Obfuscate android.support.v7.widget.GridLayout issue

孤人 提交于 2020-02-14 12:20:00

问题


I'm trying to obfuscate my android application, where I use android.support.v7.appcompat and android.support.v7.GridLayout, but the app is crashing with the following exception:

android.view.InflateException: Binary XML file line #2: Error inflating class    android.support.v7.widget.GridLayout
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.droid.fragments.c.al.onCreateView(Unknown Source)
at android.support.v4.app.Fragment.performCreateView(Unknown Source)
at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source)
at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source)
at android.support.v4.app.BackStackRecord.run(Unknown Source)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(Unknown Source)
at android.support.v4.app.FragmentManagerImpl$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: android.support.v7.widget.GridLayout
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.view.LayoutInflater.createView(LayoutInflater.java:552)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)

My proguard-project.txt:

-dontusemixedcaseclassnames  
-dontskipnonpubliclibraryclasses  
-verbose  
-dontoptimize  
-dontpreverify  
-keepclasseswithmembernames class * {  
    native <methods>;  
}  

-keepattributes *Annotation*,EnclosingMethod,Signature  

-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.app.backup.BackupAgentHelper   
-keep public class * extends android.preference.Preference  

-keepclassmembers public class * extends android.view.View {  
   void set*(***);  
   *** get*();  
}  

-keepclassmembers class * extends android.app.Activity {  
   public void *(android.view.View);  
}  

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

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

-keepclassmembers enum * {  
    public static **[] values();  
    public static ** valueOf(java.lang.String);  
}

-keep class * implements android.os.Parcelable {  
  public static final android.os.Parcelable$Creator *;  
  public void set*(***);  
  public *** get*();  
  public *** is*();  
}  

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

-keep class android.support.v7.widget.** { *; }  
-keep class android.support.v7.internal.** { *; }  
-keep interface android.support.v7.internal.** { *; }  
-keep class android.support.v4.widget.** { *; }  
-keep interface android.support.v4.widget.** { *; }  
-keep class com.viewpagerindicator.** { *; }  

-keep class android.support.v4.app.** { *; }  
-keep class android.support.v4.view.** { *; }  
-keep interface android.support.v4.app.** { *; }  
-keep interface android.support.v4.view.** { *; }  

How can I resolve this problem?


回答1:


#### -- Support Library --

# support-v4
-dontwarn android.support.v4.**
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class android.support.v4.** { *; }

# support-v7
-dontwarn android.support.v7.**
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
-keep class android.support.v7.** { *; }



回答2:


I'm using something like that (it may be too broad though):

# Preserve all fundamental application classes.
-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.view.View
-keep public class * extends android.preference.Preference
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

# Preserve Android support libraries` classes and interfaces
-keep class android.support.** { *; }
-keep interface android.support.** { *; }


来源:https://stackoverflow.com/questions/18978706/obfuscate-android-support-v7-widget-gridlayout-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!