项目上线打包时想到要给项目代码做混淆,参考网上的资料编写了proguard-project。但是在打包成功后运行却不断出错,一点点修改proguard-project最后还是报错,查看报错log发现是项目中集成的百度地图SDK中的类被混淆丢失了,以致报了
此外,项目中还使用了AndBase/,xutils等第三方library,使用了诸多jar包,shareSDK分享。
java.lang.NoClassDefFoundError: com/baidu/platform/comjni/engine/AppEngine
在工程目录中的proguard-project.txt加了以下代码解决问题,
-keep class com.baidu.**{*;}
-keep class vi.com.gdi.bgl.**{*;}
此外,项目中还使用了AndBase/,xutils等第三方library,使用了诸多jar包,shareSDK分享。
贴上proguard-project.txt代码
# 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:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-optimizationpasses 5
-dontusemixedcaseclassnames
#是否混淆第三方jar
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-ignorewarnings
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-libraryjars libs/android-support-v4.jar
-libraryjars libs/baidumapapi_v3_0_0.jar
-libraryjars libs/armeabi/libBaiduMapSDK_v3_0_0.so
-libraryjars libs/armeabi/liblocSDK4b.so
-libraryjars libs/mips/libbdpush_V2_1.so
-libraryjars libs/jackson-all-1.7.6.jar
-libraryjars libs/locSDK_4.1.jar
-libraryjars libs/mframework.jar
-libraryjars libs/pushservice-4.1.0.jar
-libraryjars libs/ShareSDK-QQ-2.5.4.jar
-libraryjars libs/ShareSDK-QZone-2.5.4.jar
-libraryjars libs/ShareSDK-ShortMessage-2.5.4.jar
-libraryjars libs/ShareSDK-SinaWeibo-2.5.4.jar
-libraryjars libs/ShareSDK-Wechat-2.5.4.jar
-libraryjars libs/ShareSDK-Wechat-Core-2.5.4.jar
-libraryjars libs/ShareSDK-Wechat-Moments-2.5.4.jar
# webview +js
#keep 使用webview的类
-keepclassmembers class com.archermind.sopaylife.WebBrowser {
public *;
}
#保持哪些类不被混淆
-keep class android.** {*; }
-keep public class * extends android.view
-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.pm
-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
#ACRA specifics
#we need line numbers in our stack traces otherwise they are pretty useless
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
#ACRA needs "annotations" so and this...
-keepattributes *Annotation*
#保持 native 方法不被混淆
-keepclasseswithmembernames class * {
native <methods>;
}
#保持自定义控件类不被混淆
-keepclasseswithmembers class * {
public <init>(android.content.Context,android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet,init);
}
-keepclasseswithmembers class * {
void onClick*(...);
}
-keepclasseswithmembers class * {
*** *Callback(...);
}
# 保持自定义控件类不被混淆
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# 保持枚举 enum 类不被混淆
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# 保持 Parcelable 不被混淆
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
#微信
-keep class cn.sharesdk.demo.wxapi.WXEntryActivity {*;}
-keep class cn.sharesdk.onekeyshare.** {*;}
-keep class com.baidu.**{*;}
-keep class vi.com.gdi.bgl.**{*;}
#keep所有的javabean
-keep class com.archermind.entity.**{*;}
#keep 泛型
-keepattributes Signature
-keep public class * implements java.io.Serializable {
public *;
}
#andbase
-dontwarn com.ab.**
-keep class com.ab.**{*;}
#xutils
-dontwarn com.lidroid.xutils.**
-keep class com.lidroid.xutils.**{*;}