当我使用proguard obfuscation(Android Jack编译器)

时间:2016-10-04 18:44:30

标签: java android android-studio proguard obfuscation

我已经在我的Android应用程序中使用JACK和android studio 2.0以及最新的gradle可用,当我想使用proguard混淆代码我结束了崩溃,但是如果我把-dontobfuscate放在我的proguard文件中该应用程序运行正常,如何在使用JACK时对我的代码进行模糊处理?

build.gradle(app module)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.my.personal.project"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    jackOptions {
        enabled true
    }
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles 'proguard-jack-test.txt'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
testCompile 'junit:junit:4.12'
}

Proguard文件:

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

-keepclassmembers class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator 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.**

# Understand the @Keep support annotation.
-keep class android.support.annotation.Keep

-keep @android.support.annotation.Keep class * {*;}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <methods>;
}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <fields>;
}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <init>(...);
}

请注意,如果我使用-dontobfuscate,我的应用程序可以正常运行

LogCat:

E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: com.my.personal.project, PID: 19382
                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.personal.project/com.my.personal.project.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:221)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                   at android.os.Looper.loop(Looper.java:158)
                                                   at android.app.ActivityThread.main(ActivityThread.java:7225)
                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
                                                   at android.support.v7.c.af.o(Unknown Source)
                                                   at android.support.v7.c.a.setContentView(Unknown Source)
                                                   at com.my.personal.project.MainActivity.onCreate(Unknown Source)
                                                   at android.app.Activity.performCreate(Activity.java:6876)
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:158) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:7225) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:657)
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
                                                   at android.support.v7.c.af.o(Unknown Source) 
                                                   at android.support.v7.c.a.setContentView(Unknown Source) 
                                                   at com.my.personal.project.MainActivity.onCreate(Unknown Source) 
                                                   at android.app.Activity.performCreate(Activity.java:6876) 
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:158) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:7225) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                Caused by: java.lang.reflect.InvocationTargetException
                                                   at java.lang.reflect.Constructor.newInstance(Native Method)
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:631)
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
                                                   at android.support.v7.c.af.o(Unknown Source) 
                                                   at android.support.v7.c.a.setContentView(Unknown Source) 
                                                   at com.my.personal.project.MainActivity.onCreate(Unknown Source) 
                                                   at android.app.Activity.performCreate(Activity.java:6876) 
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:158) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:7225) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                Caused by: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuView
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                   at android.support.design.internal.c.b(Unknown Source)
                                                   at android.support.design.widget.NavigationView.<init>(Unknown Source)
                                                   at android.support.design.widget.NavigationView.<init>(Unknown Source)
                                                   at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:631) 
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
                                                   at android.support.v7.c.af.o(Unknown Source) 
                                                   at android.support.v7.c.a.setContentView(Unknown Source) 
                                                   at com.my.personal.project.MainActivity.onCreate(Unknown Source) 
                                                   at android.app.Activity.performCreate(Activity.java:6876) 
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:158) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:7225) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuView
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:657)
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                   at android.support.design.internal.c.b(Unknown Source) 
                                                   at android.support.design.widget.NavigationView.<init>(Unknown Source) 
                                                   at android.support.design.widget.NavigationView.<init>(Unknown Source) 
                                                   at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:631) 
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
                                                   at android.support.v7.c.af.o(Unknown Source) 
                                                   at android.support.v7.c.a.setContentView(Unknown Source) 
                                                   at com.my.personal.project.MainActivity.onCreate(Unknown Source) 
                                                   at android.app.Activity.performCreate(Activity.java:6876) 
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:158) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:7225) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                Caused by: java.lang.reflect.InvocationTargetException
                                                   at java.lang.reflect.Constructor.newInstance(Native Method)
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:631)
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                   at android.support.design.internal.c.b(Unknown Source) 
                                                   at android.support.design.widget.NavigationView.<init>(Unknown Source) 
                                                   at android.support.design.widget.NavigationView.<init>(Unknown Source) 
                                                   at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:631) 
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
                                                   at android.support.v7.c.af.o(Unknown Source) 
                                                   at android.support.v7.c.a.setContentView(Unknown Source) 
                                                   at com.my.personal.project.MainActivity.onCreate(Unknown Source) 
                                                   at android.app.Activity.performCreate(Activity.java:6876) 
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:158) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:7225) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                Caused by: java.lang.VerifyError: Rejecting class android.support.v7.widget.r because it failed compile-time verification (declaration of 'android.support.v7.widget.r' appears in /data/app/com.my.personal.project-2/base.apk)
                                                   at android.support.v7.widget.bw.<init>(Unknown Source)
                                                   at android.support.design.internal.NavigationMenuView.<init>(Unknown Source)
                                                at and

1 个答案:

答案 0 :(得分:2)

我修复了在我的proguard文件中添加此行的问题

-keep public class android.support.v7.widget.** { *; }