Greystripe和proguard

时间:2013-07-19 14:00:29

标签: android netbeans proguard

所以我们已经进入了Android游戏开发的最后阶段,现在是时候对Proguard进行一些混淆了。

我们的游戏正在使用Greystripe广告,在编译调试版本时,一切正常,目标是API 7。

但是在编译发布版本时(在此过程中添加了Proguard),会有大量的警告:

Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.GSFullscreenActivity: can't find referenced class android.hardware.Camera$CameraInfo
Warning: com.greystripe.sdk.GSFullscreenActivity: can't find referenced class android.hardware.Camera$CameraInfo
Warning: com.greystripe.sdk.GSFullscreenActivity: can't find referenced method 'void getCameraInfo(int,android.hardware.Camera$CameraInfo)' in class android.hardware.Camera
Warning: com.greystripe.sdk.GSFullscreenActivity: can't find referenced method 'int getNumberOfCameras()' in class android.hardware.Camera
Warning: com.greystripe.sdk.GSFullscreenActivity: can't find referenced method 'android.hardware.Camera open(int)' in class android.hardware.Camera
Warning: com.greystripe.sdk.GSFullscreenActivity: can't find referenced method 'void setDisplayOrientation(int)' in class android.hardware.Camera
Warning: com.greystripe.sdk.GSFullscreenActivity: can't find referenced class android.hardware.Camera$CameraInfo
Warning: com.greystripe.sdk.GSFullscreenActivity: can't find referenced method 'void setLayerType(int,android.graphics.Paint)' in class com.greystripe.sdk.aa
Warning: com.greystripe.sdk.a: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.a: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.ah: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.aj: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.aj: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.aj: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.as: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.as: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.as: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.as: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.as: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.at: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.at: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.bd: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.be: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.be: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.be: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.be: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.be: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.be: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.bh: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.bh: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.bl: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.bl: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.bl: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.bl: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.bl: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.m: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.m: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.m: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.m: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.m: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.m: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.m: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.m: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.m: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.s: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.s: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.w: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.w: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.w: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.w: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.w: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.w: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.w: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.w: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.w: can't find referenced class android.webkit.JavascriptInterface
Warning: com.greystripe.sdk.w: can't find referenced class android.webkit.JavascriptInterface
Warning: there were 64 unresolved references to classes or interfaces.
     You may need to specify additional library jars (using '-libraryjars').
Warning: there were 5 unresolved references to program class members.
     Your input classes appear to be inconsistent.
     You may need to recompile them and try again.
     Alternatively, you may have to specify the option 
     '-dontskipnonpubliclibraryclassmembers'.

所以显然我开始尝试-keep class-keep public class等许多不同的变体,没有任何影响。然后我开始谷歌搜索,并发现了大量的论坛帖子,人们有同样的问题,我尝试了人们回复的所有建议。仍然没有变化。

然后我看了android.jar,发现在API 17之前没有引入android.webkit.JavascriptInterface,然后它当然有道理。因为我的目标是API 7,所以自然没有android.webkit.JavascriptInterface可用。

但我不想仅仅因为广告而针对API 17,而且我很确定我不应该这样做。

逻辑上我认为我应该只能-dontwarn,但这样做会导致应用程序在加载时崩溃。

我确定我放了-libraryjars /path/to/libs/greystripe-android-sdk-2.3.0.jar/path/to/android.jar

有没有人对此有任何疑问?如何单独使用greystripe-sdk jar来混淆我的应用程序?

3 个答案:

答案 0 :(得分:1)

ProGuard在阅读输入后立即打印这些警告,因此-keep选项无效。您应该针对API 17构建,因此ProGuard可以找到分析和处理应用程序所需的所有类。您仍然可以在AndroidManifest.xml中指定不同的目标。

如果您使用的是标准的Ant / Eclipse / Gradle构建,则不应指定-libraryjars,因为这些构建已经为您完成了。

答案 1 :(得分:1)

将以下内容添加到ProGuard文件中:

-keep class com.greystripe.** { *; }

这应该删除警告并允许Greystripe SDK按预期运行。

如果由于某种原因该行无法解决问题,请尝试以下操作:

-keep class com.greystripe.** { *; }

-keepclassmembers class com.greystripe.** { public *; }

答案 2 :(得分:0)

虽然我现在没有时间对此进行测试(还有其他一些我必须要做的事情),但是我想在这里写一下,而它仍然在我心中。然后我们会看看以后是否会成为解决方案。

要记住的重要事项:targetSdkVersion与构建版本不同。

在这种情况下,使用Greystripe类,它们显然测试了自API 17以来只能使用的某些Android类的存在,您应该将构建目标设置为API 17.这意味着您将使用可用的类进行编译在API 17. Proguard因此不应该发出警告。

但是,在AndroidManifest.xml文件中,您不必放置targetSdkVersion =“17”。您可以将其设置为您希望的任何目标。 (虽然自ICS和菜单按钮问题以来,建议始终以API 14或更高版本为目标)。

因此,最佳设置(理论上,以后必须测试)是设置

build target = API 17 - 避免Proguard警告,因为Greystripe API引用了API 17中的类 sdkTargetVersion> = 14 - 由于兼容性问题。将其设置为您可以测试的API版本 minTargetVersion = 7(如果你的应用程序将在API 7上运行) - 因为Greystripe API应该根据文档在API 7上运行

然后一切都应该有效。

更多(半)相关阅读: http://simonvt.net/2012/02/07/what-api-level-should-i-target/ http://developer.android.com/guide/topics/manifest/uses-sdk-element.html https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#ICE_CREAM_SANDWICH