使用Ant构建时未找到Adview

时间:2012-04-25 14:53:36

标签: android ant admob apk proguard

我正在使用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:\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脚本和外部罐子有关。

1 个答案:

答案 0 :(得分:0)

确保将jar放在项目的libs目录中。使用eclipse,您可以将它们放在其他文件夹中,然后只需设置您的构建环境。但是ant希望它们在你的libs文件夹中。