4

我有一个 Android 应用程序,它使用actionbarsherlock和 libs 文件夹下的下一个 jar:

android-support-v4.jar
gson-2.2.4.jar
libGoogleAnalyticsV2.jar
volley.jar

我正在尝试使用 Android Studio Build#AI-130.692269 生成签名 APK。我选中了“运行 ProGuard”和“包含系统 proguard 文件”这两个复选框

我的 ProGuard 路径文件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 *;
#}

我编辑了 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=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
proguard.config=/Applications/adt-bundle-mac-x86_64/sdk/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
android.library=false
android.library.reference.1=../AndroidBarSherlock/actionbarsherlock

这是我得到的输出:

Information:ProGuard: [SocialPrice] ProGuard, version 4.7
Information:ProGuard: [SocialPrice] Reading input...
Information:ProGuard: [SocialPrice] Reading program jar [/Users/sdelamo/Library/Caches/AndroidStudioPreview/compile-server/_temp_/proguard_input4364141808943557175.jar]
Information:ProGuard: [SocialPrice] Reading program jar [/Users/sdelamo/Documents/Developer/android/facebook-android-sdk-3.0.1/facebook/libs/android-support-v4.jar]
Information:ProGuard: [SocialPrice] Reading program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/volley.jar]
Information:ProGuard: [SocialPrice] Reading program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/libGoogleAnalyticsV2.jar]
Information:ProGuard: [SocialPrice] Reading program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/gson-2.2.4.jar]
Information:ProGuard: [SocialPrice] Reading library jar [/Applications/Android Studio.app/sdk/platforms/android-17/android.jar]
Information:ProGuard: [SocialPrice] Initializing...
Information:ProGuard: [SocialPrice] Note: com.google.analytics.tracking.android.AdHitIdGenerator: can't find dynamically referenced class com.google.ads.AdRequest
Information:ProGuard: [SocialPrice] Note: com.google.gson.internal.UnsafeAllocator: can't find dynamically referenced class sun.misc.Unsafe
Information:ProGuard: [SocialPrice] Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
Information:ProGuard: [SocialPrice] Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
Information:ProGuard: [SocialPrice] Note: there were 2 references to unknown classes.
Information:ProGuard: [SocialPrice]       You should check your configuration for typos.
Information:ProGuard: [SocialPrice] Note: there were 2 unresolved dynamic references to classes or interfaces.
Information:ProGuard: [SocialPrice] Ignoring unused library classes...
Information:ProGuard: [SocialPrice]   Original number of library classes: 3259
Information:ProGuard: [SocialPrice]   Final number of library classes:    841
Information:ProGuard: [SocialPrice] Printing kept classes, fields, and methods...
Information:ProGuard: [SocialPrice] Shrinking...
Information:ProGuard: [SocialPrice] Printing usage to [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/proguard_logs/usage.txt]...
Information:ProGuard: [SocialPrice] Removing unused program classes and class elements...
Information:ProGuard: [SocialPrice]   Original number of program classes: 921
Information:ProGuard: [SocialPrice]   Final number of program classes:    579
Information:ProGuard: [SocialPrice] Obfuscating...
Information:ProGuard: [SocialPrice] Printing mapping to [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/proguard_logs/mapping.txt]...
Information:ProGuard: [SocialPrice] Writing output...
Information:ProGuard: [SocialPrice] Preparing output jar [/Users/sdelamo/Library/Caches/AndroidStudioPreview/compile-server/socialprice_a27782ee/android/intermediate_artifacts/SocialPrice/obfuscated_sources.jar]
Information:ProGuard: [SocialPrice]   Copying resources from program jar [/Users/sdelamo/Library/Caches/AndroidStudioPreview/compile-server/_temp_/proguard_input4364141808943557175.jar]
Information:ProGuard: [SocialPrice]   Copying resources from program jar [/Users/sdelamo/Documents/Developer/android/facebook-android-sdk-3.0.1/facebook/libs/android-support-v4.jar]
Information:ProGuard: [SocialPrice]   Copying resources from program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/volley.jar]
Information:ProGuard: [SocialPrice]   Copying resources from program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/libGoogleAnalyticsV2.jar]
Information:ProGuard: [SocialPrice]   Copying resources from program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/gson-2.2.4.jar]
Information:ProGuard: [SocialPrice] Printing classes to [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/proguard_logs/dump.txt]...
Information:Compilation completed successfully with 4 warnings in 2 min 28 sec
Information:0 errors
Information:4 warnings
Warning:ProGuard: [SocialPrice]       You should check if you need to specify additional program jars.
Warning:ProGuard: [SocialPrice] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [volley.jar:META-INF/MANIFEST.MF])
Warning:ProGuard: [SocialPrice] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [libGoogleAnalyticsV2.jar:META-INF/MANIFEST.MF])
Warning:ProGuard: [SocialPrice] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [gson-2.2.4.jar:META-INF/MANIFEST.MF])

我对 ProGuard 完全陌生,因此欢迎任何反馈。

4

4 回答 4

5

我在尝试使用 joda-time 库时遇到了类似的问题。

通过添加

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}

到build.gradle 中的android部分,错误消失了。

该解决方案在复制的 重复文件中找到(Android Studio 0.4.0)

于 2014-02-25T23:05:32.187 回答
2

此 url中报告了类似的问题。希望能帮助到你。

顺便说一句,还要确保您使用最新版本的 Android SDK。它会为您的项目创建一个空的 proguard-project.txt。

于 2013-06-17T06:56:39.700 回答
0

从 0.9.1 版本开始,可以在打包过程中出现冲突时包含文件:

android.packagingOptions {
    pickFirst 'META-INF/MANIFEST.MF'
}

有关更多信息,请参阅Gradle 发行说明

于 2014-06-14T12:00:35.423 回答
-2

将 -dontwarn 添加到 proguard.cfg 以忽略警告

于 2013-06-17T09:54:49.090 回答