Ant 似乎在打包 apk 时忽略了 Proguard 生成的 jar
Posted
技术标签:
【中文标题】Ant 似乎在打包 apk 时忽略了 Proguard 生成的 jar【英文标题】:Ant seems to ignore jar generated by Proguard while packaging apk 【发布时间】:2012-06-10 13:42:43 【问题描述】:我有一个 Jenkins 构建服务器,用于使用 ant 和 android(SDK 修订版 18)构建 Android APK。发布 APK 工作正常。但是,如果我通过提供 proguard.cfg 并通过 project.properties 中的“proguard.config=proguard.cfg”指向它来启用 proguard,则似乎会发生以下情况:
Proguard 被执行(从 shell 输出和之后的 mappings.txt 和 seed.txt 可以看出) 生成一个 apk。但是,APK 生成的 Stacktraces 根本没有被混淆。
有人对此有想法吗?看来proguard生成的jar由于某些原因没有包含在apk中。
这是我的 Proguard 配置
-优化通过 5 -dontusemixedcase类名 -dontskipnonpubliclibraryclasses -dontpreverify -详细 -优化 !code/simplification/arithmetic,!field/,!class/merging/
-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 -keepclasseswithmembernames class * native <methods>; -keepclasseswithmembers class * public <init>(android.content.Context, android.util.AttributeSet); -keepclasseswithmembers class * public <init>(android.content.Context, android.util.AttributeSet, int); -keepclassmembers class * extends android.app.Activity public void *(android.view.View); -keepclassmembers enum * public static **[] values(); public static ** valueOf(java.lang.String); -keep class * implements android.os.Parcelable public static final android.os.Parcelable$Creator *; #ACRA specifics # we need line numbers in our stack traces otherwise they are pretty useless -renamesourcefileattribute SourceFile -keepattributes SourceFile,LineNumberTable # ACRA needs "annotations" so add this... -keepattributes *Annotation* # keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'. # Note: if you are removing log messages elsewhere in this file then this isn't necessary -keep class org.acra.ACRA *; # keep this around for some enums that ACRA needs -keep class org.acra.ReportingInteractionMode *; # keep this otherwise it is removed by ProGuard -keep public class org.acra.ErrorReporter public void addCustomData(java.lang.String,java.lang.String); # keep this otherwise it is removed by ProGuard -keep public class org.acra.ErrorReporter public org.acra.ErrorReporter$ReportsSenderWorker handleSilentException(java.lang.Throwable);
mappings.txt 声明我的代码被混淆了:
de.cellular.crashtest.ObfuscateThisClass -> de.cellular.crashtest.b:
但是它在报告的 Stacktrace 中没有被混淆
【问题讨论】:
【参考方案1】:看来这只是一个jenkins配置问题:apk是从bin/
目录存档的,但混淆的一个在release/
【讨论】:
以上是关于Ant 似乎在打包 apk 时忽略了 Proguard 生成的 jar的主要内容,如果未能解决你的问题,请参考以下文章