-
Notifications
You must be signed in to change notification settings - Fork 551
Known issues in .NET
Android applications built with -c Release -p:AndroidLinkMode=r8
can crash at runtime with:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.companyname.New_folder/crc64abe8cc9139195b67.MainActivity}: java.lang.ClassNotFoundException: android.view.View_IOnClickListenerImplementor
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3644)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3781)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2306)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7918)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.ClassNotFoundException: android.view.View_IOnClickListenerImplementor
at crc64abe8cc9139195b67.MainActivity.n_onCreate(Native Method)
at crc64abe8cc9139195b67.MainActivity.onCreate(MainActivity.java:30)
at android.app.Activity.performCreate(Activity.java:8342)
at android.app.Activity.performCreate(Activity.java:8321)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3625)
... 12 more
You can workaround this issue with a custom proguard.cfg
file with rules such as:
-keep class android.content.IDialogInterfaceOnShowListenerImplementor { *; } # new MaterialAlertDialogBuilder(ctx).Create().ShowEvent += (s, e) => { };
-keep class android.widget.AdapterView_IOnItemClickListenerImplementor { *; } # FindPreference("xy").PreferenceClick += (s, e) => { };
-keep class android.view.View_IOnClickListenerImplementor { *; }
-keep class android.view.View_IOnLongClickListenerImplementor { *; }
This issue will be resolved in .NET 8 GA via xamarin/java.interop#1149
$(AndroidEnableMarshalMethods)
is an experimental feature in .NET 8.
When using it, Release
builds may fail to fully launch:
- https://github.com/xamarin/xamarin-android/issues/7893
- https://github.com/xamarin/xamarin-android/issues/8253
- https://github.com/xamarin/xamarin-android/pull/7927
A workaround is to remove <AndroidEnableMarshalMethods>true</AndroidEnableMarshalMethods>
in your .csproj
file. Or if your application can target a single architecture: <RuntimeIdentifier>android-arm64</RuntimeIdentifier>
.
We hope to address this in a future .NET 9 release.
This will manifest as a build error like this:
error : The RuntimeIdentifier 'android-arm64' is invalid.
The cause is that by passing -r <runtime identifier>
to 'dotnet build' that runtime identifier is used for all target frameworks in the project file when the project is restored, while it's only a valid runtime identifier for one of the target frameworks.
Potential workaround is to restore manually, and build without restoring:
$ dotnet restore
$ dotnet build --no-restore -f net6.0-android -r android-arm64
This happens with dotnet publish
as well.
This will be fixed in a future version of NuGet.
Ref: https://github.com/dotnet/sdk/issues/21877.
Ref: https://github.com/NuGet/Home/issues/11653.
- APK Tests on the Hyper V Emulator
- Design Time Build System
- Profile MSBuild Tasks
- Diagnose Fast Deployment Issues
- Preview layout XML files with Android Studio
- Documentation