Apk 文件不适用于 xamarin 表单 Android 中启用的 proguard [英] Apk file not working with enabled proguard in xamarin forms Android

查看:39
本文介绍了Apk 文件不适用于 xamarin 表单 Android 中启用的 proguard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

未处理的异常是:

<块引用>

Java.Lang.RuntimeException:无法启动活动 ComponentInfo{com.companyname.RCBazaar/md514419014412832c50536fe1441e86d52.MainActivity}:android.view.InflateException:二进制 XML 文件行 #20:错误 inflating class.vd.android.FitWindowsFrameLayout.

堆栈跟踪:

<块引用>

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in <4f3358c3df0042d0bd6cef1efa29748d>:0在 Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod(Java.Interop.JniObjectReference 实例,Java.Interop.JniObjectReference 类型,Java.Interop.JniMethodInfo 方法,Java.Interop.JniArgumentValue* args)[0x00089] in :0在 Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (System.IntPtr jobject, System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x00015] 在 <9c44aef564514541bb6316396b56>在 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] 在 D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:164在 RCBazaar.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00018] 在 D:\manasa\RCBazaar\RCBazaar\RCBazaar\RCBazaar.Android\MainActivity.cs:38托管 Java.Lang.RuntimeException 堆栈跟踪结束android.view.InflateException:二进制 XML 文件第 20 行:错误膨胀类 android.support.v7.widget.FitWindowsFrameLayoutandroid.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)android.view.LayoutInflater.inflate(LayoutInflater.java:469) android.view.LayoutInflater.inflate(LayoutInflater.java:397)android.view.LayoutInflater.inflate(LayoutInflater.java:353)

解决方案

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

并添加以下代码

-keep class com.google.android.gms.** { *;}-不要警告 com.google.android.gms.**-保持类com.microsoft.windowsazure.messaging.** { *;}-不要警告 com.microsoft.windowsazure.messaging.**-保持类com.google.firebase.** { *;}-不要警告 com.google.firebase.**-保持类android.support.v7.widget.** { *;}-不要警告 android.support.v7.widget.**-保持类android.support.v4.widget.Space { *;}-不要警告android.support.v4.widget.Space

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

-injars bin/classes-injars 库-outjars bin/classes-processed.jar-libraryjars/usr/local/java/android-sdk/platforms/android-9/android.jar-不要预验证-repackageclasses ''-允许访问修改-优化!代码/简化/算术-keepattributes *注解*- 保持公共类 * 扩展 android.app.Activity- 保持公共类 * 扩展 android.app.Application- 保持公共类 * 扩展 android.app.Service- 保持公共类 * 扩展 android.content.BroadcastReceiver- 保持公共类 * 扩展 android.content.ContentProvider- 保持公共类 * 扩展 android.view.View {公共<init>(android.content.Context);公共 <init>(android.content.Context, android.util.AttributeSet);公共 <init>(android.content.Context, android.util.AttributeSet, int);公共无效集*(...);}-keepclasseswithmembers 类 * {公共 <init>(android.content.Context, android.util.AttributeSet);}-keepclasseswithmembers 类 * {公共 <init>(android.content.Context, android.util.AttributeSet, int);}-keepclassmembers 类 * 实现 android.os.Parcelable {静态 android.os.Parcelable$Creator CREATOR;}-keepclassmembers 类 **.R$* {公共静态<字段>;}

如果您不了解 检查这个

如果查询恢复.

I am working on xamarin forms and I wanted to reduce the APK size and improve the performance. I tried by enabling the ProGuard to reduce the APK size. But after generating (release) the APK not working. Please, any help would be appreciated.

Unhandleld exception is:

Java.Lang.RuntimeException: Unable to start activity ComponentInfo{com.companyname.RCBazaar/md514419014412832c50536fe1441e86d52.MainActivity}: android.view.InflateException: Binary XML file line #20: Error inflating class 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 method, 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] in <9c44aef564514541bb63163656b8198b>:0 at Android.Support.V7.App.AppCompatActivity.SetSupportActionBar (Android.Support.V7.Widget.Toolbar toolbar) [0x00088] in <4ab3f13aee974899a73f2f846f804630>:0 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00050] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:164 at RCBazaar.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00018] in D:\manasa\RCBazaar\RCBazaar\RCBazaar\RCBazaar.Android\MainActivity.cs:38 End of managed Java.Lang.RuntimeException stack trace android.view.InflateException: Binary XML file line #20: Error inflating class 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.inflate(LayoutInflater.java:353)

解决方案

Well first add a file to your project called proguard.cfgand set the build action to ProGuardconfiguration

And add the following code to it

-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

Also, add the following to it suggested by 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>;
}

In case you don't understand check this

In case of queries revert.

这篇关于Apk 文件不适用于 xamarin 表单 Android 中启用的 proguard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆