Android混淆规则介绍

写在前面的话

APP上线推广,免不得是需要混淆加固的,况且劳动成果不易又会有谁希望自己的APP被破解抄袭呢。鉴于此方显本片文章的通用型和重要意义。

混淆简介

Android代码混淆是一种应用源代码保护技术,用来防止别人对apk进行逆向分析;从Android2.3开始,Google就在SDK中加入了ProGuard的工具,使用它来进行代码的混淆。

ProGuard是一个压缩、优化和混淆Java字节码文件的免费工具, 其作用有以下几点:

  • 删除代码中的注释;
  • 删除代码中没有用到的类、字段、方法和属性;
  • 会把代码中的包名、类名、方法名,变量名等修改为abcd…这种没有意义的名字,使得反编译出来的代 码难以阅读,从而达到防止apk被破解和逆向分析的目的;
  • 经过ProGuard混淆后,apk安装包会变小;

在实际项目中,有些Java类不能进行混淆,需要配置混淆规则;

在实际项目中,打包apk时一般都需要进行混淆处理;

混淆后会生成mapping.txt文件,该文件需要存档以便用来还原和查看混淆后的出错日志;

1. 开启混淆并配置混淆规则的位置

在项目的build.gradle文件中打开混淆的开关,然后在proguard-rules.pro文件中添加混淆规则即可

buildTypes {debug {//是否进行混淆minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}release {//开启混淆只需要设置为true即可minifyEnabled true          //添加混淆规则的位置proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}
}

2. 找到上衣步骤配置的混淆文件,在里面添加混淆规则

首先介绍一下添加混淆规则中常用到的一些命令的含义,方便我们理解并能够自行添加属于我们项目中的一些混淆规则,然后再介绍一下项目中一些通用的混淆规则。

2.1 混淆规则常用到的命令含义

  • 保留该包下的类名不会被混淆,但是该包的子包的类名还是会被混淆

      -keep class pageName.*
    
  • 保留该包及其子包的类名不会被混淆

      -keep class pageName.**
    
  • 保留类名及其该类的内容不会被混淆(包括变量名,方法名等)

      -keep class pageName.* {*;}
    
  • 不保留类名只保留该类的方法名、变量名等不会被混淆

      -keepclassmembers class pageName.*{*;}
    
  • 保留所有继承某类的子类不会被混淆(implement同理)

      -keep public class * extends android.app.Activity
    
  • 保留该内部类中所有的public方法名、变量名不会被混淆

      -keepclassmembers class pageName$内部类名 {         //"$"的含义是保留某类的内部类不会被混淆public *;                                        }
    
  • <init>、<fields>、<methods>的含义和使用

      <init>;                //匹配所有的构造器<fields>;              //匹配所有的域<methods>;             //匹配所有的方法//可以在以上的命令前加上public、private、native等来进一步指定不被混淆的内容//也可以在以上的命令后面加上参数,来指定含有特定的参数构造方法或者方法名不会被混淆-keep class pageName {public <init>;                                  //保留所有的public的构造方法不会被混淆}-keep class pageName {public <init>(java.lang.String);              //保留所有的public的构造方法并且参数是String对象,不会被混淆}-keep class pageName {                              //保留所有的private的方法名不会被混淆private <methods>;}
    
  • 含有Keep关键字的含义(移除是指在压缩时(Shrinking)是否会被删除,需要开启压缩)

保留 防止被移除或者被重命名 防止被重命名
类和类成员 -keep -keepnames
仅类成员 -keepclassmembers -keepclassmembernames
如果拥有某成员,保留类和类成员 -keepclasseswithmembers -keepclasseswithmembernames

2.2 通用的一些混淆规则

注:四大组件、Fragment、自定义控件不需要添加混淆规则,因为这些默认是不会被混淆的,所以网上很多四大组件的混淆规则是没必要添加的。

注解

 -keepattributes *Annotation*
  • R文件下面的资源

     -keep class **.R$* {*;}
    
  • 本地的native方法(JNI)

      -keepclasseswithmembernames class * {native <methods>;}
    
  • 反射(该pageName是被反射类的包名)

    -keep class pageName{*;}
    
  • JavaBean中的泛型

      -keepattributes Signature
    
  • JavaBean(如果使用了Gson进行解析Json字符串,就需要添加JavaBean的混淆规则,因为Gson使用了反射的原理)

    -keep class pageName**
    -keep class pageName**{*;}
    
  • 枚举

      # 保留枚举类不被混淆-keepclassmembers enum * {public static **[] values();public static ** valueOf(java.lang.String);}
    
  • Parcelable序列化和Creator静态成员变量

      -keep class * implements android.os.Parcelable {public static final android.os.Parcelable$Creator *;}
    
  • Serializable序列化

    -keepclassmembers class * implements java.io.Serializable {static final long serialVersionUID;private static final java.io.ObjectStreamField[] serialPersistentFields;!static !transient <fields>;!private <fields>;!private <methods>;private void writeObject(java.io.ObjectOutputStream);private void readObject(java.io.ObjectInputStream);java.lang.Object writeReplace();java.lang.Object readResolve();
    }
    
  • WebView

      -keepclassmembers class fqcn.of.javascript.interface.for.webview {public *;}-keepclassmembers class * extends android.webkit.webViewClient {public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap);public boolean *(android.webkit.WebView, java.lang.String);}-keepclassmembers class * extends android.webkit.webViewClient {public void *(android.webkit.webView, jav.lang.String);}
    
  • 与JS交互

      #Android4.2以上需要添加以下的两个混淆配置-keepattributes *Annotation*-keepattributes *JavascriptInterface*-keepclassmembers class pageName$内部类名 {public *;}
    
  • 第三方的Jar包、依赖、SDK等

这个就需要查看项目中添加了那些第三方的Jar包、依赖、SDK了,然后在其官网上或者Github找相应的混淆规则,一般都会有的,如果没有可以自己写混淆规则。根据上面介绍的一些常用的命令含义,一般都能满足自己写混淆规则了。

3. ProGuard作用

  • 压缩(Shrinking):默认开启,用以减小应用体积,移除未被使用的类和成员,并且会在优化动作执行之后再次执行(因为优化后可能会再次暴露一些未被使用的类和成员)。

    -dontshrink 关闭压缩

  • 优化(Optimization):默认开启,在字节码级别执行优化,让应用运行的更快。

    -dontoptimize 关闭优化
    -optimizationpasses n 表示proguard对代码进行迭代优化的次数,Android一般为5

  • 混淆(Obfuscation):默认开启,增大反编译难度,类和类成员会被随机命名,除非用keep保护。

    -dontobfuscate 关闭混淆

混淆后默认会在工程目录app/build/outputs/mapping/release下生成一个mapping.txt文件,这就是混淆规则,我们可以根据这个文件把混淆后的代码反推回源本的代码,所以这个文件很重要,注意保护好。原则上,代码混淆后越乱越无规律越好,但有些地方我们是要避免混淆的,否则程序运行就会出错 。

4. 常见问题

  • 报错 Note: the configuration explicitly specifies '**' to keep library class ***.

      ote: the configuration keeps the entry point 'retrofit.OkHttpCall$ExceptionCatchingRequestBody$1 { long read(okio.Buffer,long); }', but not the descriptor class 'okio.Buffer'Note: the configuration keeps the entry point 'retrofit.RequestBuilder { void canonicalize(okio.Buffer,java.lang.String,int,int,boolean); }', but not the descriptor class 'okio.Buffer'Note: the configuration keeps the entry point 'retrofit.RequestBuilder$ContentTypeOverridingRequestBody { void writeTo(okio.BufferedSink); }', but not the descriptor class 'okio.BufferedSink'Note: the configuration keeps the entry point 'retrofit.RxJavaCallAdapterFactory$CallOnSubscribe { void call(rx.Subscriber); }', but not the descriptor class 'rx.Subscriber'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.Buffer'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.BufferOverflowException'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.BufferUnderflowException'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.ByteBuffer'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.ByteOrder'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.CharBuffer'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.DoubleBuffer'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.FloatBuffer'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.IntBuffer'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.LongBuffer'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.MappedByteBuffer'Note: the configuration explicitly specifies 'java.nio.*' to keep library class 'java.nio.ShortBuffer'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.ConnectionReuseStrategy'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.Header'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HeaderElement'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HeaderIterator'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpClientConnection'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpConnection'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpEntity'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpEntityEnclosingRequest'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpException'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpHost'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpInetConnection'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpMessage'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpRequest'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpRequestInterceptor'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpResponse'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpResponseInterceptor'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.HttpVersion'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.NameValuePair'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.NoHttpResponseException'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.ProtocolException'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.ProtocolVersion'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.RequestLine'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.StatusLine'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.auth.AuthScheme'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.auth.AuthSchemeRegistry'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.auth.AuthScope'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.auth.AuthState'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.auth.Credentials'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.auth.UsernamePasswordCredentials'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.AuthenticationHandler'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.CircularRedirectException'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.ClientProtocolException'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.CookieStore'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.CredentialsProvider'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.HttpClient'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.HttpRequestRetryHandler'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.HttpResponseException'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.RedirectException'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.RedirectHandler'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.RequestDirector'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.ResponseHandler'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.UserTokenHandler'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.entity.UrlEncodedFormEntity'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.methods.AbortableHttpRequest'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.methods.HttpDelete'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.methods.HttpEntityEnclosingRequestBase'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.methods.HttpGet'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.methods.HttpHead'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.methods.HttpPost'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.methods.HttpPut'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.methods.HttpRequestBase'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.methods.HttpUriRequest'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.utils.URIUtils'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.client.utils.URLEncodedUtils'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.ClientConnectionManager'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.ClientConnectionOperator'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.ClientConnectionRequest'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.ConnectionKeepAliveStrategy'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.ConnectionReleaseTrigger'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.ManagedClientConnection'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.params.ConnManagerPNames'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.params.ConnManagerParams'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.params.ConnPerRoute'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.params.ConnPerRouteBean'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.routing.HttpRoute'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.routing.HttpRoutePlanner'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.routing.RouteInfo'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.scheme.HostNameResolver'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.scheme.LayeredSocketFactory'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.scheme.PlainSocketFactory'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.scheme.Scheme'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.scheme.SchemeRegistry'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.scheme.SocketFactory'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.ssl.AbstractVerifier'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.ssl.BrowserCompatHostnameVerifier'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.ssl.SSLSocketFactory'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.conn.ssl.X509HostnameVerifier'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.cookie.ClientCookie'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.cookie.Cookie'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.cookie.CookieSpecRegistry'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.cookie.SetCookie'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.entity.AbstractHttpEntity'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.entity.HttpEntityWrapper'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.entity.StringEntity'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.impl.auth.AuthSchemeBase'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.impl.auth.BasicScheme'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.impl.auth.RFC2617Scheme'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.impl.client.AbstractHttpClient'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.impl.client.DefaultHttpClient'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.impl.client.DefaultRedirectHandler'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.impl.client.RedirectLocations'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.impl.conn.tsccm.AbstractConnPool'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.impl.conn.tsccm.RefQueueHandler'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.impl.cookie.BasicClientCookie'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.message.AbstractHttpMessage'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.message.BasicHeader'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.message.BasicNameValuePair'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.message.HeaderGroup'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.params.AbstractHttpParams'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.params.BasicHttpParams'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.params.CoreConnectionPNames'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.params.CoreProtocolPNames'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.params.HttpConnectionParams'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.params.HttpParams'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.params.HttpProtocolParams'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.BasicHttpContext'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.BasicHttpProcessor'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.HttpContext'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.HttpProcessor'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.HttpRequestExecutor'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.HttpRequestInterceptorList'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.HttpResponseInterceptorList'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.SyncBasicHttpContext'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.util.ByteArrayBuffer'Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.util.CharArrayBuffer'Note: there were 21 references to unknown classes.You should check your configuration for typos.(http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)Note: there were 1 references to unknown class members.You should check your configuration for typos.Note: there were 1027 unkept descriptor classes in kept class members.You should consider explicitly keeping the mentioned classes(using '-keep').(http://proguard.sourceforge.net/manual/troubleshooting.html#descriptorclass)Note: there were 128 library classes explicitly being kept.You don't need to keep library classes; they are already left unchanged.(http://proguard.sourceforge.net/manual/troubleshooting.html#libraryclass)Note: there were 65 unresolved dynamic references to classes or interfaces.You should check if you need to specify additional program jars.(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)Warning: there were 412 unresolved references to classes or interfaces.You may need to add missing library jars or update their versions.If your code works fine without the missing classes, you can suppressthe warnings with '-dontwarn' options.(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)Warning: there were 6 unresolved references to program class members.Your input classes appear to be inconsistent.You may need to recompile the code.(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)Warning: there were 2 unresolved references to library class members.You probably need to update the library versions.Alternatively, you may have to specify the option '-dontskipnonpubliclibraryclassmembers'.(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.:app:transformClassesAndResourcesWithProguardForRelease FAILEDFAILURE: Build failed with an exception.
    

运行打包后控制台提示报错日志,大抵就是项目中引用了未知的类,建议添加’org.apache.http.**'和’java.nio.*'到混淆文件中,keep.完美解决

请在忽略文件中添加如下信息,内容要使用日志报错提示相应替换包名

很有可能报错依旧,请在确认已经按照日志提示的内容完全配置忽略文件规则了,可以使用下面的这句代码压制报错

代码如下

-ignorewarnings -keep class * { public private *; }

Android混淆规则介绍相关推荐

  1. android 混淆规则作用,Android混淆规则

    简介 Java代码是非常容易反编译的.为了很好的保护Java源代码,我们往往会对编译好的class文件进行混淆处理. ProGuard是一个混淆代码的开源项目.它的主要作用就是混淆,当然它还能对字节码 ...

  2. android 混淆规则作用,Android代码混淆详解

    一.混淆的意义 混淆代码并不是让代码无法被反编译,而是将代码中的类.方法.变量等信息进行重命名,把它们改成一些毫无意义的名字,同时也可以移除未被使用的类.方法.变量等. 所以直观的看,通过混淆可以提高 ...

  3. Android 代码混淆规则

    1. Proguard介绍 Android SDK自带了混淆工具Proguard.它位于SDK根目录\tools\proguard下面. ProGuard是一个免费的Java类文件收缩,优化,混淆和预 ...

  4. Android中jsoup的混淆规则

    Android中jsoup的混淆规则 版权声明:转载必须注明本文转自严振杰的博客:http://blog.yanzhenjie.com 说实话这篇文章的标题和内容我觉得很水,所以读者们要是也觉得这篇文 ...

  5. Android自定义注解不被混淆,Android 混淆压缩开启以及自定义混淆规则

    1. app module下build文件开启代码混淆和资源压缩 通过minifyEnabled=true开启混淆,shrinkResources=true开启资源压缩,混淆会增加编译时间,一般rel ...

  6. Android代码混淆之混淆规则

    请尊重他人的劳动成果,转载请注明出处:<Android代码混淆技巧> 因为Android是使用Java开发的,所以开发者可以使用ProGuard对代码进行混淆.SDK已经集成了ProGua ...

  7. Android混淆详解

    综述 毫无疑问,混淆是打包过程中最重要的流程之一,在没有特殊原因的情况下,所有 app 都应该开启混淆. 首先,这里说的的混淆其实是包括了代码压缩.代码混淆以及资源压缩等的优化过程.依靠 ProGua ...

  8. Android混淆心得

    最近在做Android应用的混淆,踩了一些坑,这里记录分享下个人的心得. 混淆介绍 首先先简单说一下什么是混淆和混淆的作用,其实这个搜索下可以找到一堆官方的说法等等,这里简单口语叙述一下,混淆就是把代 ...

  9. Android混淆大法

    Android混淆大法 本文涉及内容: 1.混淆的基本介绍,混淆的基本配置及示例 2.如何进行多模块的混淆 3.实际项目中混淆时会遇到的问题 4.混淆后如何进行debug和日志查看 文章目录 Andr ...

最新文章

  1. Memcached安装以及PHP的调用
  2. DOS文件转换成UNIX文件格式详解
  3. 深度学习(十九)基于空间金字塔池化的卷积神经网络物体检测-ECCV 2014
  4. Windows下使用Caffe-Resnet
  5. Replace Nested Conditional with Guard Clauses(以卫语句取代嵌套条件表达式)
  6. LTE物理传输资源(2)-频带、信道带宽和频点号EARFCN
  7. 怎么解决tomcat端口占用问题?
  8. php mysqli result,PHP mysqli_free_result()与mysqli_fetch_array()函数详解
  9. c语言递归汉诺塔次数,c语言递归解决汉诺塔参数变化的疑惑
  10. Java 语言结构【转】
  11. 2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest
  12. c语言5的阶乘流程图_求n流程图(求n的阶乘的算法框图)
  13. 基于c51的节日彩灯控制器的设计
  14. C语言变量相关试题,C语言模拟试题
  15. 电信网关改造无线打印服务器,电信天翼网关路由改桥接流程
  16. iOS之推荐六款不错的 iOS 15 Safari 浏览器扩展
  17. web安全:QQ号快速登录漏洞及被盗原理
  18. 用html制作课程表
  19. 新蓝海之门,或将由数据信托来打开!
  20. 6个简历模板免费下载网站,资源超多,质量超高!

热门文章

  1. 戴尔U盘重装系统Win10步骤和详细教程
  2. mysql load 指定字段_mysql load data部分字段的正确写法
  3. 快速点击,多次请求同一接口,怎样让结果渲染为最后一次请求的结果
  4. Python学习—— 用python来买彩票
  5. “我见犹怜”的【水晶相框】请悉心呵护
  6. 什么是finally
  7. 爬取好友QQ空间的说说(增强版及使用过程中的困难总结)
  8. Redis常用架构模式
  9. 算法基础课第八章动态规划和贪心算法
  10. php一句话木马中的@有什么用