Error while Setting of Proguard and Exporting APK

扶醉桌前 提交于 2019-12-17 19:46:25

问题


I am doing first time proguard setting on My Android Project and Exporting My APK File but I got Following errors: (I also not found any proguard.cfg file in my project root)

[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)

*project.properties : *

# 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

Please tell me about solution of that and how to do exactly setting of proguard.

Thanks in Advance.


回答1:


Finally I Got Answer with the help of this Tutorial

I have changed following things:

In project.properties: Uncomment or add this line:

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

Now I have used Google Library so my proguard.project.txt will be like:

Here add your libraries which you have used in your project:

-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

Add any project specific keep options here:

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

Then you can Export your APK using following steps:

  • Right click on project
  • select Export
  • Follow Steps

If you have any Query then you are free to ping me :)

Thank you.




回答2:


Using Maven in my case, google-api-client brought guava-jdk5 as a dependency, causing similar problems.

Guava wiki page on Proguard suggests: https://code.google.com/p/guava-libraries/wiki/UsingProGuardWithGuava

-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue



回答3:


Add these line in your proguard-project.txt

-keep public class com.google.common.**
-keep public class * extends android.app.Activity


来源:https://stackoverflow.com/questions/17985876/error-while-setting-of-proguard-and-exporting-apk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!