Skip to content

Known issues in .NET

Jonathan Peppers edited this page Oct 10, 2023 · 22 revisions

.NET 8 RC 2

AndroidLinkMode=r8

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=true

$(AndroidEnableMarshalMethods) is an experimental feature in .NET 8.

When using it, Release builds may fail to fully launch:

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.

Specifying both -f and -r to dotnet build fails to restore for multi-targeted projects

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.

Clone this wiki locally