我正在使用一个Ant
脚本来生成我的 APK Proguard
。如果我使用 Eclipse 导出功能手动构建我的 APK,一切正常,但如果我使用我的 Ant 脚本,我会收到一个“找不到调用 'com.google.ads.Adview'”异常抛出到日志中强制关闭。
这是我的 proguard.cfg 文件,我告诉它保留 com.google.ads:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-libraryjars C:\Workspace\JARs\CWAC-WakefulIntentService-0.4.5.jar;C:\Workspace\JARs\GoogleAdMobAdsSdk-6.0.0.jar;C:\Workspace\JARs\android-support-v4.jar
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-dontwarn **CompatHoneycomb
-dontwarn **CompatHoneycombMR2
-dontwarn **CompatCreatorHoneycombMR2
-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.Fragment
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keep public class com.google.ads.** { *; }
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
# This will avoid all the onClick listeners referenced from XML Layouts from being removed
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-dontwarn android.support.**
这是我的 build.xml 文件,我在其中构建 APK,然后将其复制到目录中。
<?xml version="1.0" encoding="UTF-8"?>
<project name="master" default="build">
<target name="build">
<ant dir="../Project" antfile="build.xml" inheritAll="false" inheritRefs="false" target="release" />
<copy todir="../APKs">
<fileset dir="../Project/bin" includes="*release.apk" />
</copy>
</target>
</project>
更新:
在对此进行了更多修改之后,我认为这个问题与 Proguard 无关,而是与Ant
脚本和外部 jar 相关。