android - 使用我的 APK 实现 Proguard 安全

标签 android proguard

我想用我的应用程序配置混淆器。但是在这样做的同时,我遇到了以下问题:

[2013-09-24 12:27:46 - DemoProguard] Proguard returned with error code 1. See console
[2013-09-24 12:27:46 - DemoProguard] Warning: com.google.android.gms.internal.bn$b: can't find referenced method 'android.view.Display getDisplay()' in class android.view.View
[2013-09-24 12:27:46 - DemoProguard] Warning: com.google.android.gms.internal.bn$b: can't find referenced method 'void removeOnGlobalLayoutListener(android.view.ViewTreeObserver$OnGlobalLayoutListener)' in class android.view.ViewTreeObserver
[2013-09-24 12:27:46 - DemoProguard]       You should check if you need to specify additional program jars.
[2013-09-24 12:27:46 - DemoProguard] Warning: there were 2 unresolved references to program class members.
[2013-09-24 12:27:46 - DemoProguard]          Your input classes appear to be inconsistent.
[2013-09-24 12:27:46 - DemoProguard]          You may need to recompile them and try again.
[2013-09-24 12:27:46 - DemoProguard]          Alternatively, you may have to specify the option 
[2013-09-24 12:27:46 - DemoProguard]          '-dontskipnonpubliclibraryclassmembers'.
[2013-09-24 12:27:46 - DemoProguard] java.io.IOException: Please correct the above warnings first.
[2013-09-24 12:27:46 - DemoProguard]    at proguard.Initializer.execute(Initializer.java:321)
[2013-09-24 12:27:46 - DemoProguard]    at proguard.ProGuard.initialize(ProGuard.java:211)
[2013-09-24 12:27:46 - DemoProguard]    at proguard.ProGuard.execute(ProGuard.java:86)
[2013-09-24 12:27:46 - DemoProguard]    at proguard.ProGuard.main(ProGuard.java:492)
[2013-09-24 12:40:50 - DemoProguard] Proguard returned with error code 1. See console
[2013-09-24 12:40:50 - DemoProguard] Warning: com.google.android.gms.internal.bn$b: can't find referenced method 'android.view.Display getDisplay()' in class android.view.View
[2013-09-24 12:40:50 - DemoProguard] Warning: com.google.android.gms.internal.bn$b: can't find referenced method 'void removeOnGlobalLayoutListener(android.view.ViewTreeObserver$OnGlobalLayoutListener)' in class android.view.ViewTreeObserver
[2013-09-24 12:40:50 - DemoProguard]       You should check if you need to specify additional program jars.
[2013-09-24 12:40:50 - DemoProguard] Warning: there were 2 unresolved references to program class members.
[2013-09-24 12:40:50 - DemoProguard]          Your input classes appear to be inconsistent.
[2013-09-24 12:40:50 - DemoProguard]          You may need to recompile them and try again.
[2013-09-24 12:40:50 - DemoProguard]          Alternatively, you may have to specify the option 
[2013-09-24 12:40:50 - DemoProguard]          '-dontskipnonpubliclibraryclassmembers'.
[2013-09-24 12:40:50 - DemoProguard] java.io.IOException: Please correct the above warnings first.
[2013-09-24 12:40:50 - DemoProguard]    at proguard.Initializer.execute(Initializer.java:321)
[2013-09-24 12:40:50 - DemoProguard]    at proguard.ProGuard.initialize(ProGuard.java:211)
[2013-09-24 12:40:50 - DemoProguard]    at proguard.ProGuard.execute(ProGuard.java:86)
[2013-09-24 12:40:50 - DemoProguard]    at proguard.ProGuard.main(ProGuard.java:492)

这是我的 proguard-text 文件

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:
-dontskipnonpubliclibraryclassmembers

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

最佳答案

尝试首先在您项目的 proguard.cfg 文件中添加这些行,如下所示:

-ignorewarnings 

如果您的项目中有任何注释,请添加下一行,如下所示

-keepattributes *Annotation*

并确保您的 gradle 文件将 minifyEnabled 设置为 false

关于android - 使用我的 APK 实现 Proguard 安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18975514/

相关文章:

java - 尝试 Google 登录时 HandleSignInResult = false

Android Google Drive - 文件夹更改监听器

android - 为什么在Android Relative layout中每次都要提供@+id/?

android-maven-插件 : deploy method that does not delete SharedPreferences

kotlin - Proguard 删除 lambda 调用

java - 混淆时遇到麻烦

android - 如何从 Soap 对象获取对 android 中字符串的响应?

java - XPathExpression 没有在适当的上下文中评估?

android - '-keep class a.b.**' 和 '-keep class a.b.** {}' 之间的区别

android - 如何在 build.gradle 中引用系统 ProGuard 二进制文件?