How to obfuscate an apk with Proguard through Eclipse?

核能气质少年 提交于 2019-12-05 19:56:42

问题


I added proguard.config=proguard.cfgto my default.properties file and have a proguard.cfg file in my project root. If I now use Export as Android Application from within Eclipse I get the following Errors:

[2011-01-27 11:11:37 - Application] Warning: class [classes/com/package.Class.class] unexpectedly contains class [com/package.Class]
[2011-01-27 11:11:37 - Application] Warning: class [classes/com/package.Class2.class] unexpectedly contains class [com/package.Class2]
[2011-01-27 11:11:37 - Application] Note: there were 145 duplicate class definitions.
[2011-01-27 11:11:37 - Application] Warning: there were 146 classes in incorrectly named files.
[2011-01-27 11:11:37 - Application]          You should make sure all file names correspond to their class names.
[2011-01-27 11:11:37 - Application]          The directory hierarchies must correspond to the package hierarchies.
[2011-01-27 11:11:37 - Application]          If you don't mind the mentioned classes not being written out,
[2011-01-27 11:11:37 - Application]          you could try your luck using the '-ignorewarnings' option.
[2011-01-27 11:11:37 - Application] java.io.IOException: Please correct the above warnings first.
[2011-01-27 11:11:37 - Application]     at proguard.InputReader.execute(InputReader.java:133)
[2011-01-27 11:11:37 - Application]     at proguard.ProGuard.readInput(ProGuard.java:195)
[2011-01-27 11:11:37 - Application]     at proguard.ProGuard.execute(ProGuard.java:78)
[2011-01-27 11:11:37 - Application]     at proguard.ProGuard.main(ProGuard.java:499)

It seems that somehow my classes are saved in a classes subfolder but Proguard uses this classes subfolder as a package. Therefore the definition of the classes can not be understood by Proguard.

Is this a problem with my SDK Setup? Or are there errors in my Proguard Configuration causing this problem?


回答1:


I changed the proguard.cfg slightly from whatever was working for me last May and now it works:

from

-injars bin

to

-injars bin/classes

I also had to clean-up a bit--removing Junit (which wasn't used in this project) and the compatibility library (which I probably could have ignored away, but chose to ditch altogether instead).




回答2:


Now that is convenient I just updated to the the new ddms Eclipse pluging Version: Android DDMS 9.0.0.v201101191456-93220 and updated my SDK to the new Version that includes Honeycomb and the problem seems to be gone.




回答3:


Steps to get obfusticated apk:

1) Download latest proguard from "http://sourceforge.net/projects/proguard/files/". Current latest version is proguard4.7

2) Replace "bin" and "lib" folder of "C:\Program Files (x86)\Android\android-sdk\tools\proguard" with latest downloaded proguard folders.

3) Check SDK location in eclipse for blank spaces in it and for that go to window > Preferences > Android. If there is blank space then replace it with:

    c:\Progra~2\android\android-sdk (for windows 64-bit)
    c:\Progra~1\android\android-sdk (for windows 32-bit)

4) Check that proguard.cfg file is in your project's root folder and add "proguard.config=proguard.cfg" in project.properties file of android project.

5) Now export your project to get obfusticated apk.

I hope that it will help.



来源:https://stackoverflow.com/questions/4815167/how-to-obfuscate-an-apk-with-proguard-through-eclipse

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