Apk文件无法在xamarin表单Android中启用proguard

问题描述 投票:0回答:1

我正在研究xamarin表单,我想减小APK大小并提高性能。我尝试通过启用ProGuard来减小APK大小。但在生成(发布)后,APK无法正常工作。请,任何帮助将不胜感激。

未处理的异常是:

Java.Lang.RuntimeException:无法启动活动ComponentInfo {com.companyname.RCBazaar / md514419014412832c50536fe1441e86d52.MainActivity}:android.view.InflateException:二进制XML文件行#20:错误膨胀类android.support.v7.widget.FitWindowsFrameLayout。

StackTrace:

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()[0x0000c] in <4f3358c3df0042d0bd6cef1efa29748d>:0 at Java.Interop.JniEnvironment + InstanceMethods.CallNonvirtualVoidMethod(Java.Interop.JniObjectReference instance,Java.Interop.JniObjectReference type,Java.Interop。 JniMethodInfo方法,Java.Interop.JniArgumentValue * args)[0x00089] in:0 at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod(System.IntPtr jobject,System.IntPtr jclass,System.IntPtr jmethod,Android.Runtime.JValue * parms)[ 0x00015]在<9c44aef564514541bb63163656b8198b>:0,Android.Support.V7.App.AppCompatActivity.SetSupportActionBar(Android.Support.V7.Widget.Toolbar工具栏)[0x00088],位于<4ab3f13aee974899a73f2f846f804630>:0,位于Xamarin.Forms.Platform.Android。 FormsAppCompatActivity.OnCreate(Android.OS.Bundle savedInstanceState)[0x00050]在RCBazaar.Droid.MainActivity.OnCreate的D:\ a \ 1 \ s \ Xamarin.Forms.Platform.Android \ AppCompat \ FormsAppCompatActivity.cs:164中(Android。在D:\ ma中的OS.Bundle包)[0x00018] nasa \ RCBazaar \ RCBazaar \ RCBazaar \ RCBazaar.Android \ MainActivity.cs:38托管Java.Lang.RuntimeException堆栈跟踪结束android.view.InflateException:二进制XML文件行#20:错误膨胀类android.support.v7.widget .FitWindowsFrameLayout android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)android.view.LayoutInflater.inflate(LayoutInflater.java:469)android.view.LayoutInflater.inflate(LayoutInflater.java:397)android.view.LayoutInflater。膨胀(LayoutInflater.java:353)

xamarin xamarin.forms xamarin.android
1个回答
0
投票

首先,在项目中添加一个名为proguard.cfgand的文件,将构建操作设置为ProGuardconfiguration

并添加以下代码

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class com.microsoft.windowsazure.messaging.** { *; }
-dontwarn com.microsoft.windowsazure.messaging.**
-keep class com.google.firebase.** { *; }
-dontwarn com.google.firebase.**
-keep class android.support.v7.widget.** { *; }
-dontwarn android.support.v7.widget.**
-keep class android.support.v4.widget.Space { *; }
-dontwarn android.support.v4.widget.Space

另外,添加Xamarin建议的以下内容:

-injars  bin/classes
-injars  libs
-outjars bin/classes-processed.jar
-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar

-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

-keep public class * extends android.view.View {
 public <init>(android.content.Context);
 public <init>(android.content.Context, android.util.AttributeSet);
 public <init>(android.content.Context, android.util.AttributeSet, int);
 public void set*(...);
}

-keepclasseswithmembers class * {
 public <init>(android.content.Context, android.util.AttributeSet);
 }

 -keepclasseswithmembers class * {
 public <init>(android.content.Context, android.util.AttributeSet, int);
 }

 -keepclassmembers class * implements android.os.Parcelable {
 static android.os.Parcelable$Creator CREATOR;
 }

-keepclassmembers class **.R$* {
 public static <fields>;
}

万一你不懂check this

如果查询还原。

© www.soinside.com 2019 - 2024. All rights reserved.