我在我的安卓工作室里使用了pro卫兵。我已经在我的 proguard-rules.pro 文件中实现了Proguard。但是在发布apk之后,代码并没有被混淆。
这是 proguard-rules.pro 文件
# Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in /home/chitra/Android/Sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # 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 -dontskipnonpubliclibraryclasses -dontskipnonpubliclibraryclassmembers -dontpreverify -verbose -dump class_files.txt -printseeds seeds.txt -printusage unused.txt -printmapping mapping.txt -printmapping out.map -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -allowaccessmodification -keepattributes *Annotation*,Signature,InnerClasses -renamesourcefileattribute SourceFile -keepattributes SourceFile,LineNumberTable -keepattributes InnerClasses -keepattributes Exceptions -dontoptimize -repackageclasses '' -dontwarn android.support.** -dontwarn org.apache.harmony.awt.** -dontwarn com.sun.mail.imap.protocol.** -dontwarn javax.activation.CommandInfo -dontwarn com.google.zxing.** -dontwarn com.actionsmicro.androidkit.ezcast.imp.googlecast.** -dontwarn org.apache.http.entity.mime.** -dontwarn com.thetransactioncompany.jsonrpc2.server.MessageContext -dontwarn com.actionsmicro.d.a.a -dontwarn okio.Okio.** -dontwarn okio.DeflaterSink.** -dontwarn java.nio.file.** -dontwarn retrofit2.** -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement -dontwarn android.support.design.** # The official support library. -keep class android.support.v4.app.** { *; } -keep interface android.support.v4.app.** { *; } -keep class android.support.v7.app.** { *; } -keep interface android.support.v7.app.** { *; } -keep class android.support.v7.widget.** { *; } -keep interface android.support.v7.widget.** { *; } # The official design library. -keep class android.support.design.** { *; } -keep interface android.support.design.** { *; } -keep public class android.support.design.R$* { *; } # Keep fragments -keep public class * extends android.support.v4.app.Fragment -keep public class * extends android.app.Fragment -keep public class * extends android.app.Activity -keep public class * extends android.support.v7.app.ActionBarActivity -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 # EventBus 3.0 -keep class de.greenrobot.event.** { *; } -keep interface de.greenrobot.event.** { *; } -keep class com.** { *; } -keep interface com.** { *; } # crashlytics android -keep class com.crashlytics.android.** { *; } -keep interface com.crashlytics.android.** { *; } # digits sdk android -keep class com.digits.sdk.** { *; } -keep interface com.digits.sdk.** { *; } # firebase, google services and gson -keep class com.google.** { *; } -keep interface com.google.** { *; } # square picasso -keep class com.square.picasso.google.** { *; } -keep interface com.square.picasso.** { *; } -keepnames class * implements java.io.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(); # Native Methods -keepclasseswithmembernames class * { native <methods>; # Android Support Library -keep class android.** {*;} # Button methods -keepclassmembers class * { public void *ButtonClicked(android.view.View); # Reflection -keepclassmembers class com.elsinga.sample.proguard.SensorDescriptionFragment { public void updateFields(com.elsinga.sample.proguard.SensorData); -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); # Remove Logging -assumenosideeffects class android.util.Log { public static *** e(...); public static *** w(...); public static *** wtf(...); public static *** d(...); public static *** v(...); }
这会有什么问题呢?请让我知道。
上云精选
2核2G云服务器 每月9.33元起,个人开发者专属3年机 低至2.3折
原因很可能是,您在规则中排除了自己的代码。
所以混淆不会在您的代码上运行。
我不知道您的命名空间,从您的问题,但以下的行将影响任何与 com. 在一开始。
com.
因此,如果您的名称空间是 com.my.namespace ,它将被排除在混淆之外。
com.my.namespace
您应该考虑删除以下行,或者完全量化它应该隐藏的名称空间,以避免与您自己的名称空间发生冲突。
-keep class com.** { *; } -keep interface com.** { *; }
更新:
您还保留了所有扩展活动、片段等的类,这很可能是您编写的每一页代码。
# Keep fragments