【问题标题】:Getting error while generating the .apk file if proguard is ON如果 proguard 为 ON,则在生成 .apk 文件时出错
【发布时间】:2012-07-24 09:32:01
【问题描述】:

我正在使用 proguard 来混淆代码。 我在控制台中收到以下错误

Proguard returned with error code 1. See console
Warning: org.apache.cordova.CameraLauncher: can't find referenced class org.apache.commons.codec.binary.Base64
Warning: org.apache.cordova.CameraLauncher: can't find referenced class org.apache.commons.codec.binary.Base64
Warning: org.apache.cordova.CordovaWebView: can't find referenced method 'WebView(android.content.Context,android.util.AttributeSet,int,boolean)' in class android.webkit.WebView
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced method 'android.webkit.WebResourceResponse shouldInterceptRequest(android.webkit.WebView,java.lang.String)' in class android.webkit.WebViewClient
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced class android.webkit.WebResourceResponse
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced class android.webkit.WebResourceResponse
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced class android.webkit.WebResourceResponse
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced class android.webkit.WebResourceResponse
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced class android.webkit.WebResourceResponse
Warning: org.apache.cordova.FileUtils: can't find referenced class org.apache.commons.codec.binary.Base64
Warning: org.apache.cordova.FileUtils: can't find referenced class org.apache.commons.codec.binary.Base64
Warning: there were 9 unresolved references to classes or interfaces.
          You may need to specify additional library jars (using '-libraryjars').
Warning: there were 2 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'.
 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)

我的 project.properties 文件在这里

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=~/Desktop/Android/android-sdk-macosx/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-10

我的 proguard-project.txt 在这里

# 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:

# 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 *;
#}

如何解决?

【问题讨论】:

    标签: android cordova proguard cordova-plugin-proguard


    【解决方案1】:

    我通过在我的 proguard-project.txt

    中添加它来修复它
    -keep public class * extends com.phonegap.api.Plugin 
    -keep public class org.apache.cordova.DroidGap 
    -keep public class org.apache.cordova.** 
    -libraryjars /Users/Nasir/Desktop/libs/commons-codec.jar
    -dontwarn android.webkit.*
    

    【讨论】:

      【解决方案2】:

      您可以将以下内容添加到您的 proguard-project.txt 中。它在 Cordova (PhoneGap) 2.1 上对我有用:

      -keep public class * extends com.phonegap.api.Plugin 
      -keep public class * extends org.apache.cordova.api.Plugin 
      -keep public class org.apache.cordova.DroidGap 
      -keep public class org.apache.cordova.** 
      -libraryjars libs/commons-codec-1.7.jar
      -dontwarn android.webkit.*
      -dontwarn org.apache.**
      

      【讨论】:

      • 以上对我有用。我在签署运行 Cordova 2.3 的 Android PhoenGap 项目时遇到此错误。我不得不用-libraryjars libs/cordova-2.3.0.jar替换-libraryjars libs/commons-codec-1.7.jar
      猜你喜欢
      • 2018-06-12
      • 2019-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2018-04-16
      • 2019-07-01
      相关资源
      最近更新 更多