带有 proguard 的 Android ant build.xml 未在发行版中构建

Posted

技术标签:

【中文标题】带有 proguard 的 Android ant build.xml 未在发行版中构建【英文标题】:Android ant build.xml with proguard does not build in release 【发布时间】:2012-08-17 08:11:13 【问题描述】:

我有以下项目设置: 两个库“commoncomponents”和“libs”都定义了一些活动,例如带有 webview 和对话框助手类。 然后是我的“应用程序库”,其中包含应用程序代码,它又是 由“免费”应用和“完整”应用引用。

我通过以下附加条目启用了 proguard

-keepclassmembers class **.R$* 
    public static <fields>;

但是,当使用发布目标和 proguard 启动 ant 时,构建过程会失败 抱怨缺少 R$string 类

如果我在“commoncomponents”、“libs”或“应用程序库”项目上调用“ant release”,proguard 成功, 但是当我在“应用程序免费”或“应用程序已满”上启动它时,会出现此错误消息:

         [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: ~/Workspace/Workspaces/workspace-indigo/MyApp/bin/classes
     [echo] ----------
     [echo] Resolving Dependencies for bin...
[dependency] Library dependencies:
[dependency] ------------------
[dependency] Ordered libraries:
[dependency] ------------------
[dependency] API<=15: Adding annotations.jar to the classpath.
-pre-build:
-code-gen:
[mergemanifest] No changes in the androidManifest files.
     [echo] Handling aidl files...
     [aidl] Found 2 AIDL files.
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
[renderscript] No RenderScript files to compile.
     [echo] ----------
     [echo] Handling Resources...
     [aapt] No changed resources. R.java and Manifest.java untouched.
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Build type changed: Generating new BuildConfig class.
-pre-compile:
-compile:
    [javac] Compiling 12 source files to ~/Workspace/Workspaces/workspace-indigo/MyApp/bin/classes
     [echo] Creating library output jar file...
      [jar] Building jar: ~/Workspace/Workspaces/workspace-indigo/MyApp/bin/classes.jar
-post-compile:
-obfuscate:
   [delete] Deleting: ~/Workspace/Workspaces/workspace-indigo/MyApp/bin/proguard/original.jar
      [jar] Building jar: ~/Workspace/Workspaces/workspace-indigo/MyApp/bin/proguard/original.jar
 [proguard] ProGuard, version 4.7
 [proguard] Reading input...
 [proguard] Reading program jar [~/Workspace/Workspaces/workspace-indigo/MyApp/bin/proguard/original.jar]
 [proguard] Reading program jar [~/Workspace/Workspaces/workspace-indigo/CommonComponents/bin/classes.jar]
 [proguard] Reading program jar [~/Workspace/Workspaces/workspace-indigo/exampleLib/bin/classes.jar]
 [proguard] Reading program jar [~/Workspace/Workspaces/workspace-indigo/Bfw/bin/classes.jar]
 [proguard] Reading program jar [/Developer/Java/android-sdk-macosx/tools/support/annotations.jar]
 [proguard] Reading program jar [~/Workspace/Workspaces/workspace-indigo/MyApp/libs/android-support-v4.jar]
 [proguard] Reading library jar [/Developer/Java/android-sdk-macosx/platforms/android-10/android.jar]
 [proguard] Reading library jar [/Developer/Java/android-sdk-macosx/add-ons/addon-real3d-lge-10/libs/real3d.jar]
 [proguard] Initializing...
 [proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
 [proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
 [proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
 [proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
 [proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
 [proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
 [proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R
 [proguard] Warning: com.example.common.HelpDialog: can't find referenced class com.example.common.R$string
 [proguard] Warning: com.example.common.HelpDialog: can't find referenced class com.example.common.R$string
 [proguard] Warning: com.example.common.HelpDialog: can't find referenced class com.example.common.R
 [proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$layout
 [proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$id
 [proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$string
 [proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$layout
 [proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$id
 [proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$string
 [proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R
 [proguard] Warning: com.example.common.WebDialog$1: can't find referenced class com.example.common.R$string
 [proguard] Warning: com.example.common.WebDialog$1: can't find referenced class com.example.common.R$string
 [proguard] Warning: com.example.common.WebDialog$1: can't find referenced class com.example.common.R
 [proguard] Warning: com.example.dlg.InfoDialogActivity: can't find referenced class com.example.lib.R$layout
 [proguard] Warning: com.example.dlg.InfoDialogActivity: can't find referenced class com.example.lib.R$layout
 [proguard] Warning: com.example.dlg.InfoDialogActivity: can't find referenced class com.example.lib.R
 [proguard] Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
 [proguard] Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
 [proguard] Note: there were 2 references to unknown classes.
 [proguard]       You should check your configuration for typos.
 [proguard] Warning: there were 23 unresolved references to classes or interfaces.
 [proguard]          You may need to specify additional library jars (using '-libraryjars').

BUILD FAILED
/Developer/Java/android-sdk-macosx/tools/ant/build.xml:570: The following error occurred while executing this line:
/Developer/Java/android-sdk-macosx/tools/ant/build.xml:834: Please correct the above warnings first.

项目设置对我来说似乎没问题,因为“ant debug”编译时没有错误。 包名称更改为 com.example ,我的用户目录更改为 ~/xy 在上面的列表中

我在网上搜索了这个问题,发现了很多帖子,尤其是在 *** 上,但没有一个帮助我解决这个问题,希望有人能提供帮助,尽管这是我的第一个问题。 谢谢

【问题讨论】:

【参考方案1】:

事实证明,应用程序库构建文件打开了 proguard 混淆,通过将其关闭,在构建免费和完整的应用程序存根时找到了所有符号。

【讨论】:

以上是关于带有 proguard 的 Android ant build.xml 未在发行版中构建的主要内容,如果未能解决你的问题,请参考以下文章

用于 Android Proguard 混淆的 ANT 构建

Android ant 构建:proguard 在 ViewConfigurationCompatFroyo 类中找不到引用的方法

Ant 似乎在打包 apk 时忽略了 Proguard 生成的 jar

使用 Cordova Android 4 的 Proguard?

Android Proguard - dontobfuscate 不会禁用混淆

带有 Android 的 ProGuard:java.lang.NoSuchMethodError:android.util.Xml.asAttributeSet