Skip to content

[proguard] Preserve ManagedPeer class - #1351

Merged
jonpryor merged 1 commit into
dotnet:masterfrom
radekdoulik:pr-proguard-preserve-ManagedPeer
Feb 28, 2018
Merged

jonpryor merged 1 commit into
dotnet:masterfrom
radekdoulik:pr-proguard-preserve-ManagedPeer

Conversation

@radekdoulik

Copy link
Copy Markdown
Member

After XA stopped using Java.Interop built in XAIntegration
configuration, we need com.xamarin.java_interop.ManagedPeer to be
present in the mono.android.jar file, as managed ManagedPeer type
requires it.

Thus we need to preserve that class when using proguard.

Fixes #1331

After XA stopped using Java.Interop built in XAIntegration
configuration, we need com.xamarin.java_interop.ManagedPeer to be
present in the mono.android.jar file, as managed ManagedPeer type
requires it.

Thus we need to preserve that class when using proguard.

Fixes dotnet#1331
@jonpryor
jonpryor merged commit 4707867 into dotnet:master Feb 28, 2018
jonpryor pushed a commit that referenced this pull request Feb 28, 2018
Fixes: #1331

Apps built with ProGuard enabled crash on startup:

	$ msbuild /t:Install /p:Configuration=Release /p:EnableProguard=true *.csproj
	# launch the app, and `adb logcat` contains:
	Unhandled Exception:
	System.TypeInitializationException: The type initializer for 'Java.Interop.ManagedPeer' threw an exception. ---> System.ArgumentException: Handle must be valid.
	Parameter name: type
	  at Java.Interop.JniEnvironment+Types.IsInstanceOf (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type)
	  at Android.Runtime.JNIEnv.IsInstanceOf (System.IntPtr obj, System.IntPtr clazz)
	  at Java.Interop.Runtime.IsGCUserPeer (System.IntPtr value)
	  at Java.Interop.Runtime.IsGCUserPeer (Android.Runtime.IJavaObject value)
	  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType)
	  at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type)
	  at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer)
	  at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer)
	  at Android.Runtime.AndroidRuntime.GetExceptionForThrowable (Java.Interop.JniObjectReference& value, Java.Interop.JniObjectReferenceOptions transfer)
	  at Java.Interop.JniEnvironment+Types.FindClass (System.String classname)
	  at Java.Interop.JniType..ctor (System.String classname)
	  at Java.Interop.JniType.GetCachedJniType (Java.Interop.JniType& cachedType, System.String classname)
	  at Java.Interop.JniPeerMembers.get_JniPeerType ()
	  at Java.Interop.ManagedPeer..cctor ()
	   --- End of inner exception stack trace ---
	  at Java.Interop.JniRuntime..ctor (Java.Interop.JniRuntime+CreationOptions options)
	  at Android.Runtime.AndroidRuntime..ctor (System.IntPtr jnienv, System.IntPtr vm, System.Boolean allocNewObjectSupported, System.IntPtr classLoader, System.IntPtr classLoader_loadClass)
	  at Android.Runtime.JNIEnv.Initialize (Android.Runtime.JnienvInitializeArgs* args)

After Xamarin.Android stopped using Java.Interop built against the
`XAIntegration*` configuration (7d32ef3), we need to ensure that the
type `com.xamarin.java_interop.ManagedPeer` -- found within 
`mono.android.jar` -- is preserved within the final `classes.dex`, as
`Java.Interop.ManagedPeer` requires it.

Thus we need to preserve that class when using ProGuard.
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 2, 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.

2 participants