Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import proguard rules from proguard-android.txt #8403

Closed
wants to merge 2 commits into from

Conversation

dellis1972
Copy link
Contributor

@dellis1972 dellis1972 commented Oct 9, 2023

Context: #8337
Fixes: #8397

The latest Android sdk no longer ships with proguard as a result the file in proguard-android.txt [1] is missing. As a result customers are reporting errors such as

Unhandled Exception from source=AndroidEnvironment

Java.Lang.Exception: android.view.View_IOnClickListenerImplementor
    at Java.Interop.JniEnvironment.Types.TryFindClass(String , Boolean )
    at Java.Interop.JniEnvironment.Types.FindClass(String )
    at Java.Interop.JniType..ctor(String )
    at Java.Interop.JniPeerMembers.JniInstanceMethods..ctor(Type )
    at Java.Interop.JniPeerMembers.JniInstanceMethods.GetConstructorsForType(Type )
    at Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance(String , Type , JniArgumentValue* )
    at Android.Views.View.IOnClickListenerImplementor..ctor()
    at Android.Views.View.__CreateIOnClickListenerImplementor()
    at Java.Interop.EventHelper.AddEventHandler[IOnClickListener,IOnClickListenerImplementor](WeakReference& , Func`1 , Action`1 , Action`1 )
    at Android.Views.View.add_Click(EventHandler )
    at com.glmsoftware.obdnowpros.Fragments.SubscriptionFragment.OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_inflater, IntPtr native_container, IntPtr native_savedInstanceState)
    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L(_JniMarshal_PPLLL_L callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1, IntPtr p2)
    --- End of managed Java.Lang.Exception stack trace ---

This is probably because certain code is removed that in the latest version of R8 that used to be left in place.
We should include the contents of this removed file in our own proguard_xamarin.cfg file.

[1] https://android.googlesource.com/platform/sdk/+/refs/heads/main/files/proguard-android.txt

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1940,7 +1940,6 @@ because xbuild doesn't support framework reference assemblies.
<_ProguardConfiguration Include="$(ProguardConfigFiles)" />
</ItemGroup>
<ItemGroup Condition=" '$(ProguardConfigFiles)' == '' ">
<_ProguardConfiguration Include="$(_AndroidSdkDirectory)tools\proguard\proguard-android.txt" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removing this really broke the LibraryProjectZipWithLint test. Is there a real issue there?

@jpobst
Copy link
Contributor

jpobst commented Oct 9, 2023

While I think this is a good change, I'm not convinced it actually fixes the reported issue.

From my testing, this case #8337 (comment) still seems to work on .NET 7 but not .NET 8. I keep investigating but I cannot find any real difference between the 2 that would cause the issue.

@jonpryor
Copy link
Member

jonpryor commented Oct 9, 2023

As per discussion on Discord, it looks like dotnet/java-interop#1149 is the actual fix for #8337.

We may still want this change anyway, but we should probably re-evaluate this. Why did Google remove proguard-android.txt from the Android SDK? Did the functionality get moved elsewhere (and we should thus be tracking the new location)? Is the previous contents "moot" because of other changes in the SDK? Something else?

I suspect that this will become a .NET 9 task.

@jpobst
Copy link
Contributor

jpobst commented Oct 9, 2023

Why did Google remove proguard-android.txt from the Android SDK?

I came across the answer to this earlier in my research:

# This file is no longer maintained and is not used by new (2.2+) versions of the
# Android plugin for Gradle. Instead, the Android plugin for Gradle generates the
# default rules at build time and stores them in the build directory.

(Source)

Agreed that this is something we will eventually need to further research to ensure we keep up with the Android ecosystem.

Context dotnet#8337
        dotnet#8397

The latest Android sdk no longer ships with `proguard` as a result the
file in proguard-android.txt [1] is missing. As a result customers are
reporting errors such as

```
Unhandled Exception from source=AndroidEnvironment

Java.Lang.Exception: android.view.View_IOnClickListenerImplementor
    at Java.Interop.JniEnvironment.Types.TryFindClass(String , Boolean )
    at Java.Interop.JniEnvironment.Types.FindClass(String )
    at Java.Interop.JniType..ctor(String )
    at Java.Interop.JniPeerMembers.JniInstanceMethods..ctor(Type )
    at Java.Interop.JniPeerMembers.JniInstanceMethods.GetConstructorsForType(Type )
    at Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance(String , Type , JniArgumentValue* )
    at Android.Views.View.IOnClickListenerImplementor..ctor()
    at Android.Views.View.__CreateIOnClickListenerImplementor()
    at Java.Interop.EventHelper.AddEventHandler[IOnClickListener,IOnClickListenerImplementor](WeakReference& , Func`1 , Action`1 , Action`1 )
    at Android.Views.View.add_Click(EventHandler )
    at com.glmsoftware.obdnowpros.Fragments.SubscriptionFragment.OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_inflater, IntPtr native_container, IntPtr native_savedInstanceState)
    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L(_JniMarshal_PPLLL_L callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1, IntPtr p2)
    --- End of managed Java.Lang.Exception stack trace ---
```

This is probably because certain code is removed that in the latest version of R8 that used to be
left in place.
We should include the contents of this removed file in our own proguard_xamarin.cfg file.

[1] https://android.googlesource.com/platform/sdk/+/refs/heads/main/files/proguard-android.txt
@dellis1972
Copy link
Contributor Author

I'm closing this PR as it was not causing the issue.

@dellis1972 dellis1972 closed this Dec 4, 2023
@dellis1972 dellis1972 deleted the Issue8397 branch December 4, 2023 16:35
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

R8 linking causes runtime crashes on new IDE installations due to missing proguard rules file
4 participants