-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Include basic proguard file so starting Xamarin Forms project can release with proguard enabled #2709
Comments
The way Xamarin.Android works, it creates a rule for any class that generates a Java ACW. This is so that any C# type that extends a Java type won't need a proguard rule. Since the failure here is Maybe there is something we need to do in the support library? @Redth ? |
Having the ProGuard file included in the template is essential IMO. There's already a huge amount of knowledge required to get anything working in the mobile space and it's really important that all the features offered by the system work "out of the box". I agree that every developer that needs ProGuard will need to learn about it, but having the system help us as much as possible by providing expert-level defaults will make a big difference for those just starting out in the learning. |
Yes, I didn't see this rule in particular in the proguard configs for support, so presumably Forms may need to ship their own proguard config file in their nuget package... |
I think we need to do some more evaluation of other rules that might be needed here. I also now have an app which needs:
|
Commit 4bb4b2e introduced a crash in our `Xamarin.Forms-Performance-Integration` test, crashing in the middle of app startup, because the r8 linker is enabled. The same happens when ProGuard is enabled in Xamarin.Forms apps; see also: xamarin/Xamarin.Forms#2709 It looks like we need to preserve the `android.support.v7.view.**` classes to avoid the crash. E AndroidRuntime: FATAL EXCEPTION: main E AndroidRuntime: Process: Xamarin.Forms_Performance_Integration, PID: 8563 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity}: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.v7.view.menu.ActionMenuItemView E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913) E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) E AndroidRuntime: at android.os.Looper.loop(Looper.java:193) E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6669) E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.v7.view.menu.ActionMenuItemView E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.v7.view.menu.ActionMenuItemView E AndroidRuntime: Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet] E AndroidRuntime: at java.lang.Class.getConstructor0(Class.java:2327) E AndroidRuntime: at java.lang.Class.getConstructor(Class.java:1725) E AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:615) E AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) E AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) E AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:492) E AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:423) E AndroidRuntime: at android.support.v7.view.menu.BaseMenuPresenter.createItemView(:1) E AndroidRuntime: at android.support.v7.view.menu.BaseMenuPresenter.getItemView(:3) E AndroidRuntime: at android.support.v7.widget.ActionMenuPresenter.getItemView(:3) E AndroidRuntime: at android.support.v7.widget.ActionMenuPresenter.flagActionItems(:21) E AndroidRuntime: at android.support.v7.view.menu.MenuBuilder.flagActionItems(:6) E AndroidRuntime: at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(:3) E AndroidRuntime: at android.support.v7.widget.ActionMenuPresenter.updateMenuView(:1) E AndroidRuntime: at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(:6) E AndroidRuntime: at android.support.v7.view.menu.MenuBuilder.onItemsChanged(:4) E AndroidRuntime: at android.support.v7.view.menu.MenuBuilder.onItemActionRequestChanged(:2) E AndroidRuntime: at android.support.v7.view.menu.MenuItemImpl.setShowAsAction(:3) E AndroidRuntime: at xamarin.forms.performance.integration.MainActivity.n_onCreate(Native Method) E AndroidRuntime: at xamarin.forms.performance.integration.MainActivity.onCreate(:1) E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7136) E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7127) E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) E AndroidRuntime: at android.os.Looper.loop(Looper.java:193) E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6669) E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) W ActivityManager: Force finishing activity Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity
Hi guys. Actually I see this behavior in a blank XF app (default VS 15.9.4 template) deployed on emulator with ProGuard and Link: SDK Assemblies only. App can be deployed and it works only if Link: none (pointless) or as @Redth mentioned add a manual ProGuard file and -keep class android.support.v7.widget.FitWindowsLinearLayout { *; } @Redth you also mentioned here that 28.0.0 will fix. I've updated all NuGets but still same behavior. Or am I missing something? |
closed by #5143 |
Description
The current starter Xamarin Forms Android project will not deploy as is with proguard enabled.
The minimum configuration currently required is a proguard file with the following entry
The support libraries all include proguard.txt files as part of their nuget packages so Xamarin Forms could also include the above minimum.
It is debatable whether this is useful since as a user grows an application and uses more things they are going to have to learn how to interact with proguard and modify the file. It is just the inevitable outcome of having proguard enabled.
Though having the baseline function would probably stop people from creating issues and indicating that it's a defect of Xamarin Forms
Steps to Reproduce
Expected Behavior
App to launch successfully.
Actual Behavior
Crashes on launch.
Basic Information
.NET Framework 4.7.2
Android SDK Platform-Tools 27.0.1
Android SDK Build-Tools 27.0.3
Proguard 6.0.3
JDK 8 Update 171
Android NDK R17
Reproduction Link
App1.zip
RELATED Tickets
#2671
#2491
#2457
#2495
#5742
The text was updated successfully, but these errors were encountered: