5

我正在对我的 Android 项目进行首次 Proguard 设置并导出我的 APK 文件,但出现以下错误:(我proguard.cfg在项目根目录中也找不到任何文件)

[2013-08-01 10:54:42 - SalesmanTracker] Note: there were 2 duplicate class definitions.
[2013-08-01 10:54:42 - SalesmanTracker] Warning: com.google.common.collect.MinMaxPriorityQueue: can't find referenced field 'int UNSET_EXPECTED_SIZE' in class com.google.common.collect.MinMaxPriorityQueue$Builder
[2013-08-01 10:54:42 - SalesmanTracker] Warning: com.google.common.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator: can't find referenced class sun.misc.Unsafe
[2013-08-01 10:54:42 - SalesmanTracker] Warning: com.google.common.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator: can't find referenced class sun.misc.Unsafe
[2013-08-01 10:54:42 - SalesmanTracker] Warning: com.google.common.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator: can't find referenced class sun.misc.Unsafe
[2013-08-01 10:54:42 - SalesmanTracker] Warning: com.google.common.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator: can't find referenced class sun.misc.Unsafe
[2013-08-01 10:54:42 - SalesmanTracker] Warning: com.google.common.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator: can't find referenced class sun.misc.Unsafe
[2013-08-01 10:54:42 - SalesmanTracker] Warning: com.google.common.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator$1: can't find referenced class sun.misc.Unsafe
[2013-08-01 10:54:42 - SalesmanTracker] Warning: com.salesman.activities.PlacesMapActivity: can't find referenced class com.google.android.maps.GeoPoint
[2013-08-01 10:54:42 - SalesmanTracker] Warning: com.salesman.activities.PlacesMapActivity: can't find referenced class com.google.android.maps.MapController
[2013-08-01 10:54:42 - SalesmanTracker] Warning: com.salesman.activities.PlacesMapActivity: can't find referenced class com.google.android.maps.OverlayItem
[2013-08-01 10:54:42 - SalesmanTracker]       You should check if you need to specify additional program jars.
[2013-08-01 10:54:42 - SalesmanTracker] Warning: there were 9 unresolved references to classes or interfaces.
[2013-08-01 10:54:42 - SalesmanTracker]          You may need to specify additional library jars (using '-libraryjars').
[2013-08-01 10:54:42 - SalesmanTracker] Warning: there were 1 unresolved references to program class members.
[2013-08-01 10:54:42 - SalesmanTracker]          Your input classes appear to be inconsistent.
[2013-08-01 10:54:42 - SalesmanTracker]          You may need to recompile them and try again.
[2013-08-01 10:54:42 - SalesmanTracker]          Alternatively, you may have to specify the option 
[2013-08-01 10:54:42 - SalesmanTracker]          '-dontskipnonpubliclibraryclassmembers'.
[2013-08-01 10:54:42 - SalesmanTracker] java.io.IOException: Please correct the above warnings first.
[2013-08-01 10:54:42 - SalesmanTracker]     at proguard.Initializer.execute(Initializer.java:321)
[2013-08-01 10:54:42 - SalesmanTracker]     at proguard.ProGuard.initialize(ProGuard.java:211)
[2013-08-01 10:54:42 - SalesmanTracker]     at proguard.ProGuard.execute(ProGuard.java:86)
[2013-08-01 10:54:42 - SalesmanTracker]     at proguard.ProGuard.main(ProGuard.java:492)

**项目.属性:**

# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=proguard.cfg

# Project target.
target=android-17
android.library.reference.1=..\\librarySlideMenu
android.library.reference.2=../google-play-services_lib

请告诉我解决方案以及如何正确设置proguard。

提前致谢。

4

3 回答 3

7

终于在本教程的帮助下我得到了答案

我更改了以下内容:

project.properties: 取消注释或添加这一行:

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

现在我使用了谷歌图书馆,所以我proguard.project.txt会喜欢:

在这里添加您在项目中使用的库:

-libraryjars /libs/google-api-client-1.10.3-beta.jar
-libraryjars /libs/google-api-client-android2-1.10.3-beta.jar
-libraryjars /libs/google-http-client-1.10.3-beta.jar
-libraryjars /libs/google-http-client-android2-1.10.3-beta.jar
-libraryjars /libs/google-oauth-client-1.10.1-beta.jar
-libraryjars /libs/gson-2.1.jar
-libraryjars /libs/guava-11.0.1.jar
-libraryjars /libs/jackson-core-asl-1.9.4.jar
-libraryjars /libs/jsr305-1.3.9.jar
-libraryjars /libs/protobuf-java-2.2.0.jar
-libraryjars /libs/maps.jar

在此处添加任何项目特定的保留选项:

-keep class com.google.**
-dontwarn com.google.**

然后,您可以使用以下步骤导出 APK:

  • 右键单击项目
  • 选择导出
  • 按照步骤

如果您有任何疑问,那么您可以随意 ping 我 :)

谢谢你。

于 2013-08-01T07:54:26.037 回答
3

在我的情况下使用 Maven,作为依赖项google-api-client带来,导致类似的问题。guava-jdk5

Proguard 上的 Guava wiki 页面建议: https ://code.google.com/p/guava-libraries/wiki/UsingProGuardWithGuava

-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue
于 2014-07-27T12:51:25.910 回答
2

在您的 proguard-project.txt 中添加这些行

-keep public class com.google.common.**
-keep public class * extends android.app.Activity
于 2013-08-01T05:39:14.260 回答