如何使用proguard enable创建apk

时间:2013-09-27 07:04:23

标签: android proguard

我想保护我的应用程序免受反向工程。当我通过导出创建apk时,它不会创建。我在项目中添加了一些库,它们被放置在libs文件夹& google-play-sevice library。我在控制台中有以下错误。

请告诉我解决方案。

控制台错误

[2013-09-27 12:20:45 - Fishing_log] Proguard returned with error code 1. See console
[2013-09-27 12:20:45 - Fishing_log] java.io.IOException: Can't write [C:\Users\owner\AppData\Local\Temp\android_7397078648251854298.jar] (Can't read [C:\Users\owner\AppData\Local\Temp\android_7626178264196017495.jar] (Duplicate zip entry [android_7626178264196017495.jar:com/fishing/BaseActivity$1.class]))
[2013-09-27 12:20:45 - Fishing_log]     at proguard.OutputWriter.writeOutput(OutputWriter.java:264)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.OutputWriter.execute(OutputWriter.java:160)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.ProGuard.writeOutput(ProGuard.java:373)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.ProGuard.execute(ProGuard.java:154)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.ProGuard.main(ProGuard.java:484)
[2013-09-27 12:20:45 - Fishing_log] Caused by: java.io.IOException: Can't read [C:\Users\owner\AppData\Local\Temp\android_7626178264196017495.jar] (Duplicate zip entry [android_7626178264196017495.jar:com/fishing/BaseActivity$1.class])
[2013-09-27 12:20:45 - Fishing_log]     at proguard.InputReader.readInput(InputReader.java:232)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.InputReader.readInput(InputReader.java:202)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.OutputWriter.writeOutput(OutputWriter.java:253)
[2013-09-27 12:20:45 - Fishing_log]     ... 4 more
[2013-09-27 12:20:45 - Fishing_log] Caused by: java.io.IOException: Duplicate zip entry [android_7626178264196017495.jar:com/fishing/BaseActivity$1.class]
[2013-09-27 12:20:45 - Fishing_log]     at proguard.io.JarWriter.getOutputStream(JarWriter.java:139)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.io.FilteredDataEntryWriter.getOutputStream(FilteredDataEntryWriter.java:105)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.io.FilteredDataEntryWriter.getOutputStream(FilteredDataEntryWriter.java:92)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.io.ClassRewriter.read(ClassRewriter.java:68)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.io.JarReader.read(JarReader.java:65)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:65)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.io.DirectoryPump.pumpDataEntries(DirectoryPump.java:53)
[2013-09-27 12:20:45 - Fishing_log]     at proguard.InputReader.readInput(InputReader.java:228)
[2013-09-27 12:20:45 - Fishing_log]     ... 6 more

proguard的-project.txt

-injars bin/classes

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-repackageclasses ''
-dontnote
-verbose

-dontwarn **CompatHoneycomb
-dontwarn twitter4j.**
-dontwarn com.google.android.gms.**
-dontwarn  org.**

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-dontwarn sun.misc.Unsafe, java.lang.management.ManagementFactory, org.codehaus.jackson.JsonParser, org.json.JSONObject, org.codehaus.jackson.JsonGenerator, org.codehaus.jackson.JsonFactory, com.google.common.collect.MinMaxPriorityQueue

-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.preference.PreferenceActivity
-keep public class * extends android.app.Dialog
-keep class * implements android.text.*
-keep class com.fo.fishing.asyntask.*
-keep class com.fo.fishing.utils.*

-keep public interface com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {

   native <methods>;

}

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

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

#Keep the R
-keepclassmembers class **.R$* {
    public static <fields>;
}
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
  public *;
}

评论 -injars bin / classes &amp;通过这种方式添加库 -libraryjars libs / android-support-v4.jar apk已创建,但安装后不会崩溃。

崩溃报告

STACK_TRACE=java.lang.AbstractMethodError: abstract method not implemented
at org.acra.jraf.android.util.activitylifecyclecallbackscompat.a.onActivityCreated(Unknown Source)
at android.app.Application.dispatchActivityCreated(Application.java:162)
at android.app.Activity.onCreate(Activity.java:865)
at android.support.v4.app.FragmentActivity.onCreate(Unknown Source)
at com.fishing.Login.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:4470)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:2)

构建过程还会自动为您指定所有-injars-outjars-libraryjars。你不能再指定它们。

在Eclipse中,您可能需要检查是否已导出所有库,因此它们由ProGuard处理并包含在最终的apk中。