使用外部 Admob jar 的 Proguard 运行时错误
Posted
技术标签:
【中文标题】使用外部 Admob jar 的 Proguard 运行时错误【英文标题】:Proguard runtime error with external Admob jar 【发布时间】:2012-10-17 01:16:06 【问题描述】:签名的应用程序出错!
我的应用使用了外部 Admob jar,但 proguard 正在触摸 jar:
jar 文件位于 /libs/GoogleAdMobAdsSdk-6.2.1.jar
谢谢
LogCat 错误:
Proguard returned with error code 1. See console
Warning: com.google.ads.m: can't find referenced class
com.google.ads.internal.state.AdState
Warning: com.google.ads.m: can't find referenced class com.google.ads.internal.state.AdState
You should check if you need to specify additional program jars.
Warning: there were 2 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:321)
at proguard.ProGuard.initialize(ProGuard.java:211)
at proguard.ProGuard.execute(ProGuard.java:86)
at proguard.ProGuard.main(ProGuard.java:492)
在 jar 文件中
配置proguard-project.txt:
-libraryjars /libs/GoogleAdMobAdsSdk-6.2.1.jar
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-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.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*(...);
-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.content.Context
public void *(android.view.View);
public void *(android.view.MenuItem);
-keepclassmembers class * implements android.os.Parcelable
static android.os.Parcelable$Creator CREATOR;
-keepclassmembers class **.R$*
public static <fields>;
添加后
-keep public class com.google.ads.**
到该文件,eclipse控制台仍然给出以下错误:
Proguard returned with error code 1. See console
Note: there were 160 duplicate class definitions.
Warning: com.google.ads.m: can't find referenced class
com.google.ads.internal.state.AdState
Warning: com.google.ads.m: can't find referenced class
com.google.ads.internal.state.AdState
You should check if you need to specify additional program jars.
Warning: there were 2 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:321)
at proguard.ProGuard.initialize(ProGuard.java:211)
at proguard.ProGuard.execute(ProGuard.java:86)
at proguard.ProGuard.main(ProGuard.java:492)
【问题讨论】:
***.com/questions/13040226/… 感谢您的评论。但这不适用于例如Dropbox Sdkor 其他外部 jars。这些将被 proguard 触摸或更改 听起来您不希望 proguard 更改库文件。您应该为 AdMob SDK jar 添加-keep public class com.google.ads.**
,并为其他 jar 添加类似的内容,这样这些类就不会被重命名。
做了但仍然出现错误,请参阅编辑
【参考方案1】:
我刚刚添加了
-dontwarn com.google.ads.**
到 proguard-project.txt 文件,签名的 apk 工作正常! 在这里推荐(就像 Eric 之前说的):Proguard can't find referenced class com.google.ads.internal.state.AdState
【讨论】:
这真的对我有用..我还按照 Eric Leichtenschlag 11 月 2 日 16:55 的评论添加了。谢谢你们俩.. 此代码签署了应用程序,但 admob 广告确实出现并给出了 classnotfoundexception 但@peterdk 代码对我有用。【参考方案2】:这对我有用,看来您需要将这两项添加到 proguard 配置中:
-dontwarn com.google.ads.**
-keep class com.google.ads.** *;
【讨论】:
【参考方案3】:-dontwarn com.google.ads.** 这里保护广告类 如果您想保护您的班级,请添加 com.pkgname.**
【讨论】:
以上是关于使用外部 Admob jar 的 Proguard 运行时错误的主要内容,如果未能解决你的问题,请参考以下文章
带有外部 jar 的 Proguard 错误 - 返回错误代码 1