使用Proguard进行混淆后Android应用程序崩溃

时间:2016-01-08 04:44:45

标签: android proguard obfuscation ibm-mobilefirst

我使用Proguard来模糊我的Android源代码并尝试签署我的应用程序并成功。我在签署应用程序时未发现任何错误。但是,在我将我的应用程序安装到我的设备后,当我尝试打开应用程序时,应用程序被强制关闭。以下是我得到的错误:

     public class TotalTimerFragment extends Fragment{
    TextView totalWorkoutTimer;
    TotalTimeCounter timeCounter;
    static long total_millis;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_totaltimer, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        totalWorkoutTimer = (TextView) view.findViewById(R.id.total_timer_textview);
//Call your count down timer class///
    }

    public class TotalTimeCounter extends CountDownTimer {

        public TotalTimeCounter(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {
            total_millis = millisUntilFinished;
            String total_hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(total_millis),
                    TimeUnit.MILLISECONDS.toMinutes(total_millis) - TimeUnit.HOURS.toMinutes(TimeUnit.
                            MILLISECONDS.toHours(total_millis)), TimeUnit.MILLISECONDS.toSeconds(total_millis) -
                            TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(total_millis)));
            totalWorkoutTimer.setText(total_hms);
        }

        @Override
        public void onFinish() {

        }
    }

以下是我的proguard配置:

W/dalvikvm( 1351): VFY: unable to resolve virtual method 159: Landroid/content/C
ontext;.getNoBackupFilesDir ()Ljava/io/File;
D/dalvikvm( 1351): VFY: replacing opcode 0x6e at 0x000b
I/dalvikvm( 1351): Could not find method org.apache.http.impl.client.DefaultHttp
Client.getCookieStore, referenced from method com.worklight.wlclient.api.WLClien
t.getCookieStore
W/dalvikvm( 1351): VFY: unable to resolve virtual method 24031: Lorg/apache/http
/impl/client/DefaultHttpClient;.getCookieStore ()Lorg/apache/a/a/a;
D/dalvikvm( 1351): VFY: replacing opcode 0x6e at 0x0008
I/dalvikvm( 1351): Could not find method org.apache.http.HttpRequest.addHeader,
referenced from method com.worklight.wlclient.WLRequest.addExtraHeaders
W/dalvikvm( 1351): VFY: unable to resolve interface method 23989: Lorg/apache/ht
tp/HttpRequest;.addHeader (Lorg/apache/a/a;)V
D/dalvikvm( 1351): VFY: replacing opcode 0x72 at 0x0019
D/dalvikvm( 1351): GC_CONCURRENT freed 261K, 11% free 3042K/3384K, paused 5ms+2m
s, total 84ms
I/dalvikvm( 1351): Could not find method org.apache.http.impl.client.DefaultHttp
Client.setCookieStore, referenced from method com.worklight.wlclient.HttpClientM
anager.<init>
W/dalvikvm( 1351): VFY: unable to resolve virtual method 24033: Lorg/apache/http
/impl/client/DefaultHttpClient;.setCookieStore (Lorg/apache/a/a/a;)V
D/dalvikvm( 1351): VFY: replacing opcode 0x6e at 0x0099
D/AndroidRuntime( 1351): Shutting down VM
W/dalvikvm( 1351): threadid=1: thread exiting with uncaught exception (group=0xb
1a82ba8)
E/AndroidRuntime( 1351): FATAL EXCEPTION: main
E/AndroidRuntime( 1351): Process: com.ACCTouch, PID: 1351
E/AndroidRuntime( 1351): java.lang.NoSuchMethodError: org.apache.http.impl.clien
t.DefaultHttpClient.setCookieStore
E/AndroidRuntime( 1351):        at com.worklight.wlclient.HttpClientManager.<ini
t>(Unknown Source)
E/AndroidRuntime( 1351):        at com.worklight.wlclient.HttpClientManager.crea
teInstance(Unknown Source)
E/AndroidRuntime( 1351):        at com.worklight.wlclient.api.WLClient.createIns
tance(Unknown Source)
E/AndroidRuntime( 1351):        at com.worklight.common.Logger.setContext(Unknow
n Source)
E/AndroidRuntime( 1351):        at com.worklight.androidgap.api.WL.<init>(Unknow
n Source)
E/AndroidRuntime( 1351):        at com.worklight.androidgap.api.WL.createInstanc
e(Unknown Source)
E/AndroidRuntime( 1351):        at com.ACCTouch.ACCTouch.onCreate(Unknown Source
)
E/AndroidRuntime( 1351):        at android.app.Activity.performCreate(Activity.j
ava:5231)
E/AndroidRuntime( 1351):        at android.app.Instrumentation.callActivityOnCre
ate(Instrumentation.java:1087)
E/AndroidRuntime( 1351):        at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2159)
E/AndroidRuntime( 1351):        at android.app.ActivityThread.handleLaunchActivi
ty(ActivityThread.java:2245)
E/AndroidRuntime( 1351):        at android.app.ActivityThread.access$800(Activit
yThread.java:135)
E/AndroidRuntime( 1351):        at android.app.ActivityThread$H.handleMessage(Ac
tivityThread.java:1196)
E/AndroidRuntime( 1351):        at android.os.Handler.dispatchMessage(Handler.ja
va:102)
E/AndroidRuntime( 1351):        at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 1351):        at android.app.ActivityThread.main(ActivityThrea
d.java:5017)
E/AndroidRuntime( 1351):        at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 1351):        at java.lang.reflect.Method.invoke(Method.java:5
15)
E/AndroidRuntime( 1351):        at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 1351):        at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:595)
E/AndroidRuntime( 1351):        at dalvik.system.NativeStart.main(Native Method)

W/ActivityManager(  377):   Force finishing activity com.ACCTouch/.ACCTouch
W/InputMethodManagerService(  377): Window already focused, ignoring focus gain
of: com.android.internal.view.IInputMethodClient$Stub$Proxy@b20e15d8 attribute=n
ull, token = android.os.BinderProxy@b1fab568
W/ActivityManager(  377): Activity pause timeout for ActivityRecord{b1fd3570 u0
com.ACCTouch/.ACCTouch t5 f}
W/ActivityManager(  377): Activity destroy timeout for ActivityRecord{b1fd3570 u
0 com.ACCTouch/.ACCTouch t5 f}

我尝试将此代码# This is a configuration file for ProGuard. # http://proguard.sourceforge.net/index.html#manual/usage.html -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -verbose # Optimization is turned off by default. Dex does not like code run # through the ProGuard optimize and preverify steps (and performs some # of these optimizations on its own). -dontoptimize -dontpreverify # Note that if you want to enable optimization, you cannot just # include optimization flags in your own project configuration file; # instead you will need to point to the # "proguard-android-optimize.txt" file instead of this one from your # project.properties file. -keepattributes *Annotation* -keep public class com.google.vending.licensing.ILicensingService -keep public class com.android.vending.licensing.ILicensingService # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native -keepclasseswithmembernames class * { native <methods>; } # keep setters in Views so that animations can still work. # see http://proguard.sourceforge.net/manual/examples.html#beans -keepclassmembers public class * extends android.view.View { void set*(***); *** get*(); } # We want to keep methods in Activity that could be used in the XML attribute onClick -keepclassmembers class * extends android.app.Activity { public void *(android.view.View); } # For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } -keepclassmembers class **.R$* { public static <fields>; } # The support library contains references to newer platform versions. # Don't warn about those in case this app is linking against an older # platform version. We know about them, and they are safe. -dontwarn android.support.** # These options let obfuscated applications or libraries produce stack traces that can still be deciphered later on -renamesourcefileattribute SourceFile -keepattributes SourceFile.LineNumberTable -keepattributes InnerClasses # Enable proguard with Cordova -keep class org.apache.cordova.** { *; } -keep public class * extends org.apache.cordova.CordovaPlugin -keep class com.worklight.androidgap.push.** { *; } -keep class com.worklight.wlclient.push.** { *; } -keep class com.worklight.common.security.AppAuthenticityToken { *; } # Enable proguard with Google Libs -keep class com.google.** { *; } -dontwarn com.google.common.** -dontwarn com.google.ads.** # These classes contain references to external jars which are not included in the default MobileFirst project -dontwarn com.worklight.common.internal.WLTrusteerInternal* -dontwarn com.worklight.jsonstore.** -dontwarn org.bouncycastle.** -dontwarn org.codehaus.jackson.map.ext.** -dontwarn com.worklight.androidgap.push.GCMIntentService -dontwarn com.worklight.androidgap.plugin.WLInitializationPlugin -dontwarn com.worklight.wlclient.push.GCMIntentService -dontwarn com.worklight.wlclient.push.WLBroadcastReceiver -dontwarn com.worklight.wlclient.push.common.* -dontwarn com.worklight.wlclient.api.WLPush -dontwarn net.sqlchiper.** -dontwarn net.sqlchiper.database.** -dontwarn org.apache.commons.codec.** -dontwarn org.apache.http.** -keep class org.apache.http.** { *; } -keep class com.worklight.** { *; } -keep class net.sqlcipher.** { *; } -keep class net.sqlcipher.database.** { *; } -keep class org.apache.commons.codec.** { *; } -keep class **.R 添加到我的proguard配置中,但现在我收到此错误,说我在尝试签署该应用时有重复的类定义。

-keep class org.apache.http.** { *; }

仅供参考:我目前正在使用Mobile First ver。 7.1。

  

更新:现在我可以通过将此代码添加到我的proguard配置来解决它:[2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] Proguard returned with error code 1. See console [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] Note: there were 27 duplicate class definitions. [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] You should check if you need to specify additional program jars. [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.obfuscate.MemberObfuscator.newMemberName(MemberObfuscator.java:198) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.obfuscate.MemberNameCollector.visitAnyMember(MemberNameCollector.java:74) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.util.SimplifiedVisitor.visitProgramMember(SimplifiedVisitor.java:79) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.util.SimplifiedVisitor.visitProgramMethod(SimplifiedVisitor.java:91) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.visitor.MemberAccessFilter.visitProgramMethod(MemberAccessFilter.java:90) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:504) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.visitor.AllMemberVisitor.visitProgramClass(AllMemberVisitor.java:48) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.ProgramClass.accept(ProgramClass.java:346) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.ProgramClass.hierarchyAccept(ProgramClass.java:359) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.LibraryClass.hierarchyAccept(LibraryClass.java:371) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.ProgramClass.hierarchyAccept(ProgramClass.java:416) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.visitor.ClassHierarchyTraveler.visitProgramClass(ClassHierarchyTraveler.java:75) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.visitor.MultiClassVisitor.visitProgramClass(MultiClassVisitor.java:85) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.ProgramClass.accept(ProgramClass.java:346) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.classfile.ClassPool.classesAccept(ClassPool.java:116) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.obfuscate.Obfuscator.execute(Obfuscator.java:217) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.ProGuard.obfuscate(ProGuard.java:333) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.ProGuard.execute(ProGuard.java:135) [2016-01-08 11:39:54 - ACCTouchACCTouchAndroid] at proguard.ProGuard.main(ProGuard.java:492) ,但现在我的应用程序仍在内部崩溃,我收到此错误:

-keep class org.apache.http.client.** { *; }

1 个答案:

答案 0 :(得分:1)

  

更新:谢谢大家的建议。我现在可以通过将以下代码添加到我的proguard配置中来解决它:

-keep class org.apache.http.* { *; }
-keep class org.apache.http.client.** { *; }
-keep class org.apache.http.cookie.** { *; }
-keep class org.apache.http.impl.cookie.** { *; }
-keep class org.apache.http.message.** { *; }
-keep class org.apache.http.util.** { *; }

我仍然不知道为什么我只能将-keep class org.apache.http.** { *; }添加到我的proguard配置中。