Mobclix and Proguard

不打扰是莪最后的温柔 提交于 2019-12-11 17:42:41

问题


I'm trying to use Proguard to obfuscate my code. I use Mobclix for advertisements, and when I build my APK it's spitting out an error:

org.eclipse.core.runtime.CoreException: Proguard returned with error code 1. See console
    at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(ExportHelper.java:228)
    at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.doExport(ExportWizard.java:290)
    at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.access$0(ExportWizard.java:229)
    at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard$1.run(ExportWizard.java:214)
    at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: Proguard Error 1 
Output: 
Warning: com.mobclix.android.sdk.MobclixContactsCursorEntityIterator: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsCursorEntityIterator: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5$EntityIteratorImpl: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5$EntityIteratorImpl: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5$EntityIteratorImpl: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5$EntityIteratorImpl: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5$EntityIteratorImpl: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsEntityIterator: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity$NamedContentValues 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity$NamedContentValues 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity$NamedContentValues 
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity 
      You should check if you need to specify additional program jars. 
Warning: there were 17 unresolved references to classes or interfaces. 
         You may need to specify additional library jars (using '-libraryjars'), 
         or perhaps the '-dontskipnonpubliclibraryclasses' option. 
java.io.IOException: Please correct the above warnings first. 
    at proguard.Initializer.execute(Initializer.java:308) 
    at proguard.ProGuard.initialize(ProGuard.java:210) 
    at proguard.ProGuard.execute(ProGuard.java:85) 
    at proguard.ProGuard.main(ProGuard.java:499)
    at com.android.ide.eclipse.adt.internal.build.BuildHelper.runProguard(BuildHelper.java:527)
    at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(ExportHelper.java:187)
    ... 4 more

Now, I have put the Mobclix recommended bits from their documentation into my proguard.cfg:

-keep public class com.mobclix.android.sdk.*
-keep class com.mobclix.android.sdk.MobclixJavascriptInterface

-keepclassmembers class com.mobclix.android.sdk.MobclixJavascriptInterface
{
    public void *(...);
    <methods>;
}

-keepclassmembernames class
com.mobclix.android.sdk.MobclixJavascriptInterface {
    public void *(...);
    <methods>;
}

Anything else I should be doing? Thanks a million


回答1:


The messages explain that some Mobclix classes (like com.mobclix.android.sdk.MobclixContactsCursorEntityIterator) depend on Android runtime classes (like android.content.Entity) that are not present in your input jars or library jars. In general, that could be a sign of serious problems: if that part of the code is ever executed, it will fail with NoClassDefFoundError (even without obfuscation).

It looks like the Entity class has been introduced in Android SDK 7, so I presume that you are building against an older SDK. Again assuming that your code runs fine in spite of this missing class, you can let ProGuard accept the somewhat inconsistent input with

-dontwarn android.content.Entity*

Note that -keep options don't come into play here. ProGuard performs the consistency checks before considering any -keep options.

Also see ProGuard manual > Troubleshooting > Warning: can't find referenced class




回答2:


Maybe change

-keep public class com.mobclix.android.sdk.*

to

-keep public class com.mobclix.android.sdk.**


来源:https://stackoverflow.com/questions/7003785/mobclix-and-proguard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!