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

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

Closed
jonathanantoine opened this issue Jan 10, 2020 · 11 comments · Fixed by #4178
Assignees
Labels
Area: App Runtime Issues in `libmonodroid.so`.

Comments

@jonathanantoine
Copy link

jonathanantoine commented Jan 10, 2020

Steps to Reproduce

  1. Create a Xamarin Android app
  2. Enable R8 and D8.
  3. Uses the default proguard cfg
  4. Run it on a device

Specifics (?) of my app : Android job service, FileProvider, BroadcastReceiver.

There is one MonoRuntimeProvider_1 java class generated in my obj folder.

The default proguard config is this one (found in the obj folder) :

# This is Xamarin-specific (and enhanced) configuration.

-dontobfuscate

-keep class android.support.multidex.MultiDexApplication { <init>(); }
-keep class mono.MonoRuntimeProvider { *; <init>(...); }
-keep class mono.MonoPackageManager { *; <init>(...); }
-keep class mono.MonoPackageManager_Resources { *; <init>(...); }
-keep class mono.android.** { *; <init>(...); }
-keep class mono.java.** { *; <init>(...); }
-keep class mono.javax.** { *; <init>(...); }
-keep class opentk.platform.android.AndroidGameView { *; <init>(...); }
-keep class opentk.GameViewBase { *; <init>(...); }
-keep class opentk_1_0.platform.android.AndroidGameView { *; <init>(...); }
-keep class opentk_1_0.GameViewBase { *; <init>(...); }
-keep class com.xamarin.java_interop.ManagedPeer { *; <init>(...); }

-keep class android.runtime.** { <init>(...); }
-keep class assembly_mono_android.android.runtime.** { <init>(...); }
# hash for android.runtime and assembly_mono_android.android.runtime.
-keep class md52ce486a14f4bcd95899665e9d932190b.** { *; <init>(...); }
-keepclassmembers class md52ce486a14f4bcd95899665e9d932190b.** { *; <init>(...); }

# Android's template misses fluent setters...
-keepclassmembers class * extends android.view.View {
   *** set*(...);
}

# also misses those inflated custom layout stuff from xml...
-keepclassmembers class * extends android.view.View {
   <init>(android.content.Context,android.util.AttributeSet);
   <init>(android.content.Context,android.util.AttributeSet,int);
}

Expected Behavior

No crash.

Actual Behavior

A crash report like this :

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)
... 10 more

Version Information

The app is built via App Center (Mono 6.4 and Android 10.0).

On my mac I have this tool :

=== Visual Studio Community 2019 for Mac ===

Version 8.4 (build 2657)
Installation UUID: 37cc8c40-d076-4974-8bf8-344f707f4364
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.16.1.25 (issue-7441-d16-3-vsmac / 881172e73)

Package version: 606000155

=== Mono Framework MDK ===

Runtime:
Mono 6.6.0.155 (2019-08/296a9afdb24) (64-bit)
Package version: 606000155

=== Roslyn (Language Service) ===

3.4.0-beta4-19562-05+ff930dec4565e2bc424ad3bf3e22ecb20542c87d

=== NuGet ===

Version: 5.3.0.6192

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/3.1.100/Sdks
SDK Versions:
3.1.100
3.0.101
3.0.100
2.2.401
2.2.300
2.2.106
2.2.104
2.2.101
2.1.505
2.1.302
2.1.301
2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.6.0/lib/mono/msbuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
3.1.0
3.0.1
3.0.0
2.2.6
2.2.5
2.2.4
2.2.2
2.2.0
2.1.14
2.1.13
2.1.9
2.1.2
2.1.1
2.0.5

=== Xamarin.Profiler ===

Version: 1.6.12.26
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 10.1.1.0 (Visual Studio Community)
Commit: xamarin-android/d16-4/f2c9364
Android SDK: /Users/jonathanantoine/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
4.4 (API level 19)
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 29.0.5
SDK Build Tools Version: 29.0.2

Build Information:
Mono: bef1e63
Java.Interop: xamarin/java.interop/d16-4@c4e569f
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@46204c4
Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/jonathanantoine/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.4.0.9
Hash: 3f7256f
Branch: remotes/origin/d16-4
Build date: 2019-12-19 18:59:12 UTC

=== Android Device Manager ===

Version: 16.4.0.28
Hash: 68e9956
Branch: remotes/origin/d16-4
Build date: 2019-12-19 18:59:32 UTC

=== Xamarin Designer ===

Version: 16.4.0.468
Hash: 519082ea8
Branch: remotes/origin/d16-4
Build date: 2019-12-04 16:21:00 UTC

=== Apple Developer Tools ===

Xcode 11.3 (15712)
Build 11C29

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 13.8.3.0 (Visual Studio Community)
Hash: 0d8fe219c
Branch: d16-4
Build date: 2019-12-04 13:06:41-0500

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 804002657
Git revision: 4c6723413e884e024466fc93ff10e938bca7f721
Build date: 2020-01-06 18:20:13+00
Build branch: release-8.4
Xamarin extensions: 0f572cad12fd3886cd8e21a8b93b86e29ceaf111

=== Operating System ===

Mac OS X 10.15.2
Darwin 19.2.0 Darwin Kernel Version 19.2.0
Sat Nov 9 03:47:04 PST 2019
root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

Xamarin.Forms HotReload extension 1.4.0
Open With 0.2
MFractor 3.9.7

@jonathanantoine jonathanantoine added the Area: App Runtime Issues in `libmonodroid.so`. label Jan 10, 2020
@radekdoulik radekdoulik added this to the Under Consideration milestone Jan 13, 2020
@jonathanpeppers
Copy link
Member

@jonathanantoine I get a different missing class for a new project with VS 2019 16.4 (latest stable):

Caused by: java.lang.ClassNotFoundException: android.support.v7.widget.FitWindowsLinearLayout

I think this will be improved by: f82cd9d

Using the latest xamarin-android/master, I don't get t a crash at all.

What is weird about this, is the class you get an error for is normally named MonoRuntimeProvider:

https://github.com/xamarin/xamarin-android/blob/3c2489be0a8ea1f8db30c62b2cf8e4006f754dda/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs#L263-L270

Can you share a diagnostic MSBuild log? Also your obj/Debug/android/AndroidManifest.xml file might give us a clue what's happening here. Thanks!

@jonathanpeppers jonathanpeppers added the need-info Issues that need more information from the author. label Jan 13, 2020
@jonathanantoine
Copy link
Author

@jonathanpeppers I already keeped FitWindowsLinearLayout and that's why I did not get it in my log. On my another project I have MonoRuntimeProvider_1 and MonoRuntimeProvider_2 generated also !

How can I provide you the logs in a secure way ?

@jonathanpeppers
Copy link
Member

@jonathanantoine you can email me privately at the email address listed on my Github profile, thanks!

@jonathanantoine
Copy link
Author

@jonathanpeppers thanks, I just sent them !

@jonathanantoine
Copy link
Author

Hello,

Any update :) ?

@jonathanantoine
Copy link
Author

I manage to build a repro project, it happens as soon as I use the Process = ":remote" parameter on a BroadCastReceiver : blanctest.zip.

[BroadcastReceiver(Process = ":remote", Name = "com.jonathanantoine.deded.DisplayToastBroadcastReceiver")]
public class DisplayToastBroadcastReceiver : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent)
    {
        var notificationManager = (NotificationManager)context
        .GetSystemService(Context.NotificationService);
    }
}

@jonathanpeppers
Copy link
Member

Hi @jonathanantoine I added this proguard rule, and it seems to solve the issue:

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

Does that work for you?

The default one needs to change to this:

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

I just need to write a test and can send in a fix for this.

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 27, 2020
…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 pushed a commit that referenced this issue Jan 27, 2020
…eiver (#4178)

Fixes: #4110

A crash was reported when using either Proguard or 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.
@jonathanantoine
Copy link
Author

That was a quick fix once you get the repro project ! Thanks a lot @jonathanpeppers !

@brendanzagaeski
Copy link
Contributor

Release status update

A new Preview version has now been published on Windows that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.

The fix is not yet available on macOS. I will update this item again when a Preview version with the fix is available on macOS.

Fix included in Xamarin.Android 10.2.100.7

Fix included on Windows in Visual Studio 2019 version 16.6 Preview 1. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.

Fix not yet available on macOS.

@brendanzagaeski brendanzagaeski removed the need-info Issues that need more information from the author. label Mar 17, 2020
@brendanzagaeski
Copy link
Contributor

Release status update

A new Preview version has now been published on macOS that includes the fix for this item. The fix is not yet included in a Release version. I will update this again when a Release version is available that includes the fix.

Fix included in Xamarin.Android 10.3.0.33.

Fix included on macOS in Visual Studio 2019 for Mac version 8.6 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

(Fix also included on Windows in Visual Studio 2019 version 16.6 Preview 1 and higher. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.)

@brendanzagaeski
Copy link
Contributor

Release status update

A new Release version of Xamarin.Android has now been published that includes the fix for this item.

Fix included in Xamarin.Android 10.3.1.0.

Fix included on Windows in Visual Studio 2019 version 16.6. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.

Fix included on macOS in Visual Studio 2019 for Mac version 8.6. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App Runtime Issues in `libmonodroid.so`.
Projects
None yet
4 participants