Skip to content

Conversation

@jonathanpeppers
Copy link
Member

Fixes: #4110

A crash was reported when using either Proguard/R8:

java.lang.RuntimeException: Unable to get provider mono.MonoRuntimeProvider_1: java.lang.ClassNotFoundException: Didn't find class "mono.MonoRuntimeProvider_1" on path: DexPathList[[zip file "/data/app/myApp-61Sw26LCrQQYfOvCs2GsDw==/base.apk"],nativeLibraryDirectories=[/data/app/myapp-61Sw26LCrQQYfOvCs2GsDw==/lib/arm64, /data/app/myapp-61Sw26LCrQQYfOvCs2GsDw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
    at android.app.ActivityThread.installProvider(ActivityThread.java:7152)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6630)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6525)
    at android.app.ActivityThread.access$1400(ActivityThread.java:220)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1883)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7520)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "mono.MonoRuntimeProvider_1" on path: DexPathList[[zip file "/data/app/myapp-61Sw26LCrQQYfOvCs2GsDw==/base.apk"],nativeLibraryDirectories=[/data/app/myapp-61Sw26LCrQQYfOvCs2GsDw==/lib/arm64, /data/app/myapp-61Sw26LCrQQYfOvCs2GsDw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:230)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147)
    at android.app.ActivityThread.installProvider(ActivityThread.java:7136)

This could be reproduced in a new project, just by enabling a Code
Shrinker and adding a BroadcastReceiver:

[BroadcastReceiver(Process = ":remote", Name = "foo.MyReceiver")]
public class MyReceiver : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent) { }
}

This generated a file in:

obj\Release\100\android\src\mono\MonoRuntimeProvider_1.java

We have no default proguard rule in proguard_xamarin.cfg that would
cover inclusion of this Java class for ProGuard or R8.

We can simply add a trailing * to the Java class name of an existing
rule:

-keep class mono.MonoRuntimeProvider* { *; <init>(...); }

I also added a test for this scenario that will verify ProGuard & R8.

…eiver

Fixes: dotnet#4110

A crash was reported when using either Proguard/R8:

    java.lang.RuntimeException: Unable to get provider mono.MonoRuntimeProvider_1: java.lang.ClassNotFoundException: Didn't find class "mono.MonoRuntimeProvider_1" on path: DexPathList[[zip file "/data/app/myApp-61Sw26LCrQQYfOvCs2GsDw==/base.apk"],nativeLibraryDirectories=[/data/app/myapp-61Sw26LCrQQYfOvCs2GsDw==/lib/arm64, /data/app/myapp-61Sw26LCrQQYfOvCs2GsDw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
        at android.app.ActivityThread.installProvider(ActivityThread.java:7152)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6630)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6525)
        at android.app.ActivityThread.access$1400(ActivityThread.java:220)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1883)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7520)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
        Caused by: java.lang.ClassNotFoundException: Didn't find class "mono.MonoRuntimeProvider_1" on path: DexPathList[[zip file "/data/app/myapp-61Sw26LCrQQYfOvCs2GsDw==/base.apk"],nativeLibraryDirectories=[/data/app/myapp-61Sw26LCrQQYfOvCs2GsDw==/lib/arm64, /data/app/myapp-61Sw26LCrQQYfOvCs2GsDw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:230)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147)
        at android.app.ActivityThread.installProvider(ActivityThread.java:7136)

This could be reproduced in a new project, just by enabling a Code
Shrinker and adding a `BroadcastReceiver`:

    [BroadcastReceiver(Process = ":remote", Name = "foo.MyReceiver")]
    public class MyReceiver : BroadcastReceiver
    {
        public override void OnReceive(Context context, Intent intent) { }
    }

This generated a file in:

    obj\Release\100\android\src\mono\MonoRuntimeProvider_1.java

We have no default proguard rule in `proguard_xamarin.cfg` that would
cover inclusion of this Java class for ProGuard or R8.

We can simply add a trailing `*` to the Java class name of an existing
rule:

    -keep class mono.MonoRuntimeProvider* { *; <init>(...); }

I also added a test for this scenario that will verify ProGuard & R8.
@jonpryor jonpryor merged commit 55fa709 into dotnet:master Jan 27, 2020
@jonathanpeppers jonathanpeppers deleted the proguardbroadcastreceiver branch January 27, 2020 19:56
@github-actions github-actions bot locked and limited conversation to collaborators Jan 28, 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.

Exceptions : java.lang.RuntimeException: Unable to get provider mono.MonoRuntimeProvider_1

4 participants