我正在使用Ant
脚本生成带有Proguard
的APK。 如果我使用 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:WorkspaceJARsCWAC-WakefulIntentService-0.4.5.jar;C:WorkspaceJARsGoogleAdMobAdsSdk-6.0.0.jar;C:WorkspaceJARsandroid-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.**
这是我构建.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放在项目的libs目录中。使用 eclipse,您可以将它们放在其他文件夹中,然后只需设置构建环境即可。但是,蚂蚁希望它们在您的库文件夹中。