Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

ProGuard enabled crashes Android app #515

Closed
JaccoDieleman opened this issue Sep 21, 2018 · 10 comments
Closed

ProGuard enabled crashes Android app #515

JaccoDieleman opened this issue Sep 21, 2018 · 10 comments

Comments

@JaccoDieleman
Copy link

Description

After consuming the Xamarin.Essentials NuGet package my Android app crashes during start up.

Steps to Reproduce

The problem can be reproduced with the Samples.Android project in this repository.
To reproduce, check "Enable ProGuard" in the Release configuration and try starting the app in release mode.

Expected Behavior

App starts

Actual Behavior

App crashes

Basic Information

  • Version with issue: 0.10.0-preview
  • IDE: Visual Studio Professional for Windows 15.7.6
  • Platform Target Frameworks:
    • Android: 8.1
@EmilAlipiev
Copy link

you should added output window with stacktrace information. I am also using proguard and full linking but no problem so far. you may include the apis you are accessing. it could be related to one of them as well.

@JaccoDieleman
Copy link
Author

@EmilAlipiev I'm trying to use GeoLocation. The app however crashes before it tries to use GeoLocation, it crashes while the splashScreen is being shown. The SampleApp from this repo uses all apis and has the same behavior.

I don't get a stacktrace in Visual Studio. However, this is what I picked from the device log:

09-24 09:19:52.634	LGE Nexus 5X	Error	23888	AndroidRuntime	Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.FitWindowsFrameLayout" on path: DexPathList[[zip file "/data/app/com.easysystems.easyexpense-XygxF7LxfTqJsFStVPWJYg==/base.apk"],nativeLibraryDirectories=[/data/app/com.easysystems.easyexpense-XygxF7LxfTqJsFStVPWJYg==/lib/arm, /data/app/com.easysystems.easyexpense-XygxF7LxfTqJsFStVPWJYg==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
	at android.view.LayoutInflater.createView(LayoutInflater.java:606)
	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
	at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:427)
	at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
	at android.support.v7.app.AppCompatDelegateImplV9.initWindowDecorActionBar(AppCompatDelegateImplV9.java:175)
	at android.support.v7.app.AppCompatDelegateImplBase.getSupportActionBar(AppCompatDelegateImplBase.java:145)
	at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:199)
	at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:129)
	at md5fc62b2e4833275b110f05a96ae4ffc8c.MainActivity.n_onCreate(Native Method)
	at md5fc62b2e4833275b110f05a96ae4ffc8c.MainActivity.onCreate(MainActivity.java:32)
	at android.app.Activity.performCreate(Activity.java:7009)
	at android.app.Activity.performCreate(Activity.java:7000)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
	at android.app.ActivityThread.-wrap11(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:164)
	at android.app.ActivityThread.main(ActivityThread.java:6494)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
  Force finishing activity com.easysystems.easyexpense/md5fc62b2e4833275b110f05a96ae4ffc8c.MainActivity
09-24 09:19:52.634	LGE Nexus 5X	Error	23888	AndroidRuntime	Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class android.support.v7.widget.FitWindowsFrameLayout
09-24 09:19:52.634	LGE Nexus 5X	Error	23888	AndroidRuntime	FATAL EXCEPTION: main
09-24 09:19:52.634	LGE Nexus 5X	Error	23888	AndroidRuntime	Process: com.easysystems.easyexpense, PID: 23888
09-24 09:19:52.634	LGE Nexus 5X	Error	23888	AndroidRuntime	Caused by: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class android.support.v7.widget.FitWindowsFrameLayout
09-24 09:19:52.634	LGE Nexus 5X	Debug	23888	AndroidRuntime	Shutting down VM
09-24 09:19:52.634	LGE Nexus 5X	Error	23888	AndroidRuntime	java.lang.RuntimeException: Unable to start activity ComponentInfo{com.easysystems.easyexpense/md5fc62b2e4833275b110f05a96ae4ffc8c.MainActivity}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class android.support.v7.widget.FitWindowsFrameLayout
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
	at android.app.ActivityThread.-wrap11(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:164)
	at android.app.ActivityThread.main(ActivityThread.java:6494)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
09-24 09:19:52.542	LGE Nexus 5X	Info	23888	MonoDroid	Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class android.support.v7.widget.FitWindowsFrameLayout
09-24 09:19:52.542	LGE Nexus 5X	Info	23888	MonoDroid	Java.Lang.RuntimeException: Binary XML file line #20: Binary XML file line #20: Error inflating class android.support.v7.widget.FitWindowsFrameLayout ---> Java.Lang.RuntimeException: Binary XML file line #20: Error inflating class android.support.v7.widget.FitWindowsFrameLayout ---> Java.Lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.FitWindowsFrameLayout" on path: DexPathList[[zip file "/data/app/com.easysystems.easyexpense-XygxF7LxfTqJsFStVPWJYg==/base.apk"],nativeLibraryDirectories=[/data/app/com.easysystems.easyexpense-XygxF7LxfTqJsFStVPWJYg==/lib/arm, /data/app/com.easysystems.easyexpense-XygxF7LxfTqJsFStVPWJYg==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <0f86d47be861485fa949889ca70ebae9>:0 
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <8bce811bfb4b405f86a7c1961bca2723>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <8bce811bfb4b405f86a7c1961bca2723>:0 
  at Android.Support.V7.App.AppCompatActivity.SetSupportActionBar (Android.Support.V7.Widget.Toolbar toolbar) [0x00031] in <7391f96d58fa4d36af742b6a01b30831>:0 
  at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00050] in <6b73296523894c3d8d57f5a8e3480a43>:0 
  at Rigger.Mobile.EasyExpense.Droid.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00092] in <d8190fc332b64effbf654f6784da817c>:0 
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <5e6198e7fa2140679cd48adc9971e757>:0 
  at (wrapper dynamic-method) System.Object.46bc58c1-5c50-4d5e-9bc0-28f8c6acde0f(intptr,intptr,intptr)
  --- End of managed Java.Lang.RuntimeException stack trace ---
09-24 09:19:52.542	LGE Nexus 5X	Info	23888	MonoDroid	Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.FitWindowsFrameLayout" on path: DexPathList[[zip file "/data/app/com.easysystems.easyexpense-XygxF7LxfTqJsFStVPWJYg==/base.apk"],nativeLibraryDirectories=[/data/app/com.easysystems.easyexpense-XygxF7LxfTqJsFStVPWJYg==/lib/arm, /data/app/com.easysystems.easyexpense-XygxF7LxfTqJsFStVPWJYg==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
	at android.view.LayoutInflater.createView(LayoutInflater.java:606)
	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
	at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:427)
	at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
	at android.support.v7.app.AppCompatDelegateImplV9.initWindowDecorActionBar(AppCompatDelegateImplV9.java:175)
	at android.support.v7.app.AppCompatDelegateImplBase.getSupportActionBar(AppCompatDelegateImplBase.java:145)
	at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:199)
	at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:129)
	at md5fc62b2e4833275b110f05a96ae4ffc8c.MainActivity.n_onCreate(Native Method)
	at md5fc62b2e4833275b110f05a96ae4ffc8c.MainActivity.onCreate(MainActivity.java:32)
	at android.app.Activity.performCreate(Activity.java:7009)
	at android.app.Activity.performCreate(Activity.java:7000)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
	at android.app.ActivityThread.-wrap11(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:164)
	at android.app.ActivityThread.main(ActivityThread.java:6494)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
09-24 09:19:52.542	LGE Nexus 5X	Info	23888	MonoDroid	android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class android.support.v7.widget.FitWindowsFrameLayout
09-24 09:19:52.542	LGE Nexus 5X	Info	23888	MonoDroid	
09-24 09:19:52.505	LGE Nexus 5X	Info	23888	MonoDroid	UNHANDLED EXCEPTION:
09-24 09:19:52.444	LGE Nexus 5X	Debug	23888	AppCenter	Network available netId: 100
09-24 09:19:52.444	LGE Nexus 5X	Debug	23888	AppCenter	Available networks netIds: [107, 100]
09-24 09:19:52.443	LGE Nexus 5X	Debug	23888	AppCenter	Available networks netIds: [107]
09-24 09:19:52.443	LGE Nexus 5X	Debug	23888	AppCenter	Network available netId: 107
09-24 09:19:51.620	LGE Nexus 5X	Warning	23888	monodroid	Calling into managed runtime init
09-24 09:19:51.613	LGE Nexus 5X	Warning	23888	monodroid-gc	GREF GC Threshold: 46080
09-24 09:19:51.418	LGE Nexus 5X	Warning	23888	monodroid	Trying to load sgen from: /data/app/com.easysystems.easyexpense-XygxF7LxfTqJsFStVPWJYg==/lib/arm/libmonosgen-2.0.so
09-24 09:19:51.088	LGE Nexus 5X	Debug	22268	ClClient	Not sending keepalive.  Current connection state=STOPPED
09-24 09:19:50.833	LGE Nexus 5X	Info	3488	ActivityManager	Start proc 23888:com.easysystems.easyexpense/u0a768 for activity com.easysystems.easyexpense/md5fc62b2e4833275b110f05a96ae4ffc8c.MainActivity
09-24 09:19:50.670	LGE Nexus 5X	Info	3488	ActivityManager	START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.easysystems.easyexpense/md5fc62b2e4833275b110f05a96ae4ffc8c.MainActivity} from uid 2000

@jamesmontemagno
Copy link
Collaborator

Does it work without progaurd option selected? Linking or link all should work just fine as we have that in our samples today.

Do you have your progaurd config? You may need to add some information there so items don't get removed.

@jamesmontemagno
Copy link
Collaborator

Looking at your error it looks like a general progaurd issue and not anything with essentials if essentials isn't even being run yet, but hard to know.

would need to see your progaurd file.

I would recommend reading: https://docs.microsoft.com/en-us/xamarin/android/deploy-test/release-prep/proguard?tabs=vswin

a sample I use for the evolve app: https://github.com/xamarinhq/app-conference/blob/master/src/Conference.Android/proguard.cfg

I am also interested into understanding why you need progaurd on for the app as it is usually an advanced scenario.

@jamesmontemagno jamesmontemagno changed the title Linking and ProGuard enabled crashes Android app ProGuard enabled crashes Android app Sep 24, 2018
@JaccoDieleman
Copy link
Author

@jamesmontemagno, to answer your questions:

  • Yes, it works without ProGuard. Besides, it also works with ProGuard while not linking.
  • I'm not using a custom ProGuard config, so I use the one bundled with the Xamarin.Android SDK (8.3.3.2). See below.
  • I wanted to use ProGuard because it is beneficial for size and performance of the app. The other consideration to use ProGuard is because of security. But now I'm not sure whether that would help because Obfuscation doesn't work for Xamarin.Android.
# This is Xamarin-specific (and enhanced) configuration.

-dontobfuscate

-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);
}

@jamesmontemagno
Copy link
Collaborator

Most likely you will have to add to your progaurd file additional items. I will try to get you a list and working config, but I would try some of what I used for evolve. I am thinking that this would be a problem with just a normal app without Essentials too. Can you try file-> new and see if you have issues without adding essentials.

@jamesmontemagno
Copy link
Collaborator

Looks like this is something with newer support libraries causing issues: xamarin/AndroidSupportComponents#96

simply add: -keep public class android.support.v7.widget.** { *; }

I will add a progaurd file in the repo for reference!

@jamesmontemagno
Copy link
Collaborator

I have the following:

-dontwarn android.support.**
-keep public class android.support.v7.widget.** { *; }

@jamesmontemagno
Copy link
Collaborator

Also, you can use dotfuscator if you want to obfuscate

@JaccoDieleman
Copy link
Author

Thanks! I can't get proguard to pick up the custom config right now, I'll try that later, after I read through to documentation.
+1 for the advice on obfuscation!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants