Android代码混淆报错
来源:互联网 发布:中国铁塔 网络强国 编辑:程序博客网 时间:2024/04/26 15:04
代码混淆方法:
1.添加proguard-project.txt文件至app下目录
2.在该文件中添加要不混淆的代码,Gson、butterknife和eventbus等第三方包,除了将jar包中的包下类不混淆外,还有一些特殊的方法,也要保证不混淆,如下:
# To enable ProGuard in your project, edit project.properties# to define the proguard.config property as described in that file.## Add project specific ProGuard rules here.# By default, the flags in this file are appended to flags specified# in ${sdk.dir}/tools/proguard/proguard-android.txt# You can edit the include path and order by changing the ProGuard# include property in project.properties.## For more details, see# http://developer.android.com/guide/developing/tools/proguard.html# Add any project specific keep options here:#先不混淆一些继承自带控件的view-keep public class * extends android.app.Fragment -keep public class * extends android.app.backup.BackupAgentHelper-keep public class * extends android.preference.Preference-keep public class * extends android.support.v4.**-keep public class com.android.vending.licensing.ILicensingService-keep class com.kingnew.tian.model.** { *; }-keep class com.kingnew.tian.Cropcategorys.Model.** { *; }#-optimizationpasses 5 # 指定代码的压缩级别#-dontusemixedcaseclassnames # 是否使用大小写混合#-keepattributes *Annotation*#-ignorewarnings # 抑制警告#-dontskipnonpubliclibraryclasses # 是否混淆第三方jar#不混淆Gson##---------------Begin: proguard configuration for Gson ----------# Gson uses generic type information stored in a class file when working with fields. Proguard# removes such information by default, so configure it to keep all of it.-keepattributes Signature# Gson specific classes-keep class sun.misc.Unsafe { *; }#-keep class com.google.gson.stream.** { *; }# Application classes that will be serialized/deserialized over Gson-keep class com.google.gson.examples.android.model.** { *; }##---------------End: proguard configuration for Gson ----------#不混淆butterknife##---------------Begin: proguard configuration for butterknife -----------keep class butterknife.** { *; }-dontwarn butterknife.internal.**-keep class **$$ViewBinder { *; }-dontwarn butterknife.**-keepclasseswithmembernames class * { @butterknife.* <fields>;}-keepclasseswithmembernames class * { @butterknife.* <methods>;}##---------------End: proguard configuration for butterknife ----------#不混淆eventbus##---------------Begin: proguard configuration for eventbus -----------keep class org.greenrobot.eventbus.** { *; }-dontwarn org.greenrobot.eventbus.**-keepclassmembers class ** { public void onEvent*(**); void onEvent*(**);}##---------------Begin: proguard configuration for eventbus ----------
3.在app的build文件中,将minifyEnabled 置为true
buildTypes { release { minifyEnabled true/*minifyEnabled主要用来控制是否运行混淆的。*/ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt' } }
4.然后在签名打包之后,保证app能够正常运行
ps:可参考该文:https://segmentfault.com/a/1190000002910305
5. 需要做混淆保护的内容
一般四大组件都会默认不被混淆
-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 -keep public class com.android.vending.licensing.ILicensingService
自定义组件的类也要设置为不被混淆,否则找不到控件
方案一、直接保护view的子类,因为自定义控件都是继承view
-keep public class * extends android.app.Dialog-keep public class * extends android.view
方案二、具体保护某个自定义控件
-keep public class com.viewpagerindicator.TitlePageIndicator
被调用的第三方jar包的类等
如果你使用了第三方的包,你需要使用一下配置,让ProGuard知道库中的一些类并不是在所有的API中可用:
-libraryjars libs/roboguice-2.0.jar -dontwarn roboguice.**
7.需要特别处理的第三方包
GSON butterknife eventbus
0 0
- Android代码混淆报错
- android代码混淆报错总结:java.io.IOException: Please correct the above
- android 打包混淆报错问题
- android混淆的一种报错
- android studio 混淆后,打包报错!!!
- Android 混淆报错app:transformClassesAndResourcesWithProguardForRelease
- # Android Studio 混淆报错 libhyphenate_av.so
- Android 代码混淆,混淆打包
- Android 代码混淆 webview混淆
- [Android]混淆Android代码
- [Android]混淆Android代码
- Android代码混淆------apk文件代码混淆
- 多渠道+混淆 报错
- android 代码混淆proguard
- Android项目代码混淆
- android 代码混淆总结
- android 代码混淆
- android代码混淆
- 1009. Product of Polynomials (25)
- JavaScript面向对象之Prototypes和继承
- How To Install Apache Tomcat 7 on CentOS 7 via Yum
- "Java:comp/env/"讲解与JNDI
- mysql → INSERT ... ON DUPLICATE KEY UPDATE
- Android代码混淆报错
- Error:(2, 0) Plugin with id 'com.github.dcendents.android-maven' not found
- 使用数组实现队列(C语言)
- Article - Physically Based Rendering
- 已安装了存在签名冲突的同名数据包
- 渗透测试:nc端口转发或反向转发
- leetcode 2:Add Two Numbers
- 多行文本垂直居中
- 弹出遮罩层后禁止滚动效果【实现代码】