Setting up proguard-project for Android application

时间:2016-06-10 16:11:36

标签: android obfuscation android-proguard

I have just become aware of obfuscation and want to setup proguard to work with my application. I am working in eclipse and I set it up my project.properties as suggested many places, as such

# 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

# Project target.
target=android-23
android.library.reference.1=../../Resources/route_planner_app_basic

and my proguard-project.txt as

# 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:

-injars      bin/classes
-injars      libs
-outjars     bin/classes-processed.jar
-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar

-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

-keepclassmembers class * implements android.os.Parcelable {
    static ** CREATOR;
}

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

-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

# 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 *;
#}

When I exported it worked fine the first time however I noticed a mistake when I ran the application so I fixed the mistake and since then every time I try to export the application I get the following error.

[2016-06-10 17:55:33 - route_planner_TT] Proguard returned with error code 1. See console
[2016-06-10 17:55:33 - route_planner_TT] java.io.IOException: Can't read [C:\Users\Gareth Edwards\git_repos\workspace\route_planner_TT\usr\local\java\android-sdk\platforms\android-9\android.jar] (No such file or directory)
[2016-06-10 17:55:33 - route_planner_TT]    at proguard.InputReader.readInput(InputReader.java:230)
[2016-06-10 17:55:33 - route_planner_TT]    at proguard.InputReader.readInput(InputReader.java:200)
[2016-06-10 17:55:33 - route_planner_TT]    at proguard.InputReader.readInput(InputReader.java:178)
[2016-06-10 17:55:33 - route_planner_TT]    at proguard.InputReader.execute(InputReader.java:100)
[2016-06-10 17:55:33 - route_planner_TT]    at proguard.ProGuard.readInput(ProGuard.java:196)
[2016-06-10 17:55:33 - route_planner_TT]    at proguard.ProGuard.execute(ProGuard.java:78)
[2016-06-10 17:55:33 - route_planner_TT]    at proguard.ProGuard.main(ProGuard.java:492)
[2016-06-10 17:55:33 - route_planner_TT] Caused by: java.io.IOException: No such file or directory
[2016-06-10 17:55:33 - route_planner_TT]    at proguard.io.DirectoryPump.pumpDataEntries(DirectoryPump.java:50)
[2016-06-10 17:55:33 - route_planner_TT]    at proguard.InputReader.readInput(InputReader.java:226)
[2016-06-10 17:55:33 - route_planner_TT]    ... 6 more

This was five hours ago, and I've been pulling my hair out since please help.

2 个答案:

答案 0 :(得分:0)

好像你应该使用SDK Manager下载/重新下载Android SDK 9。

答案 1 :(得分:0)

在proguard-project.txt中,使用以下选项包含android.jar:

-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar

但您似乎在Windows计算机上工作。您需要将其更改为指向计算机上安装的android.jar的正确Windows路径。