Android 灰熟和前进

Android 灰熟和前进,android,netbeans,proguard,Android,Netbeans,Proguard,因此,我们已经到了Android游戏开发的最后阶段,是时候对Proguard进行一些模糊处理了 我们的游戏使用Greystripe广告,在编译针对API7的调试版本时,一切正常 但在编译发布版本(过程中添加了Proguard)时,会出现大量警告: Warning: com.greystripe.sdk.DeviceInfo: can't find referenced class android.webkit.JavascriptInterface Warning: com.greystripe

因此,我们已经到了Android游戏开发的最后阶段,是时候对Proguard进行一些模糊处理了

我们的游戏使用Greystripe广告,在编译针对API7的调试版本时,一切正常

但在编译发布版本(过程中添加了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,发现
android.webkit.JavascriptInterface
在API 17之前没有引入,这当然是有道理的。因为我的目标是API7,所以自然没有可用的
android.webkit.JavascriptInterface

但我不想仅仅因为广告就把API17作为目标,我很确定我也不应该这样做

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

我当然要确保我把
-libraryjars/path/to/libs/greystripe-android-sdk-2.3.0.jar
/path/to/android.jar


有人对此有任何线索吗?我如何在不使用greystripe sdk jar的情况下混淆我的应用程序?

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


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

虽然我现在没有时间测试它(我还有很多其他的事情要做),但我想在我记忆犹新的时候在这里编写它。然后我们再看看这是否是解决方案

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

在本例中,对于Greystripe类,它们显然是在测试某些Android类是否存在,这些Android类仅在API 17之后可用,您应该将构建目标设置为API 17。这意味着您将使用API 17中可用的类进行编译。因此,Proguard不应发出警告

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

所以,现在的最佳设置(理论上,需要稍后测试)是

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

那么一切都会好起来的

更多(半)相关阅读:
将以下内容添加到您的ProGuard文件中:

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

这将删除警告并允许Greystripe SDK按预期运行

如果由于某种原因,该行无法修复它,请尝试以下操作:

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


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

我应该补充一点,当使用
-dontwarn
时发生的崩溃确实是greystripe类中的一个空指针异常。哇,这个人自己的回答。谢谢另一个人也推荐我把API 17作为目标,不过还有其他原因。所以这可能就是我最后要做的。不过现在,我实际上设法让它使用
-dontwarn
参数。它编译和运行时没有错误。不过,运行时日志确实显示了一个警告,当/如果以API17为目标时,这一警告是否会消失,这将是一件有趣的事情。