Android minifyEnabled = truerinkResources = true保持崩溃的应用程序

时间:2019-09-03 10:00:37

标签: java android android-studio android-gradle-plugin

在Google Play发布网站中获得以下例外。如果我minifyEnabled为false,那么rinkleResources = false。应用程序运行正常。

    FATAL EXCEPTION: ControllerMessenger
Process: MyApp, PID: 27778
java.lang.RuntimeException: Unable to start activity ComponentInfo{MyApp/MyApp.GridLayoutActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2955)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at androidx.test.espresso.base.Interrogator.a(Interrogator.java:19)
    at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:166)
    at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:158)
    at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:34)
    at androidx.test.espresso.action.MotionEvents.a(MotionEvents.java:77)
    at androidx.test.espresso.action.MotionEvents.a(MotionEvents.java:52)
    at androidx.test.espresso.action.Tap.c(Tap.java:8)
    at androidx.test.espresso.action.Tap.b(Tap.java:18)
    at androidx.test.espresso.action.Tap$1.a(Tap.java:3)
    at androidx.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:20)
    at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:9)
    at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:79)
    at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:96)
    at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:3)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6938)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

proguard-rules.pro-我添加了一些保持功能,但仍然无法正常工作

-keepclassmembers class android.support.design.internal.BottomNavigationMenuView {
    boolean mShiftingMode;
}
-keep class com.shockwave.**
-keep class android.support.v7.widget.SearchView { *; }
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
-keep class vn.hunghd.flutterdownloader.**  { *; }
-keep class com.baseflow.permissionhandler.**  { *; }   

build.gradle-我试过使用minifyEnabled false和rinkeResources false,然后正常工作。

    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId 'MyApp'
        minSdkVersion 24
        targetSdkVersion 26
        versionCode 36
        versionName "0.81"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {

        release {
            minifyEnabled true
            useProguard true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.BethakjiAppSign
            android.applicationVariants.all { variant ->
                variant.outputs.all {
                    outputFileName = "${applicationId}.apk"
                }
            }


        }
    }

2 个答案:

答案 0 :(得分:0)

尝试在proguard中为java.lang添加规则。像这样:

-keep class java.lang.** { *; }

它在调试模式下工作,因为应用程序未使用发布证书签名。如果您从Android Studio运行发布版本,则可以在发布之前测试发布版本。这样,应用程序将被签名,您可以在设备上运行它并通过应用程序。可能需要根据使用的库向proguard添加更多规则。

答案 1 :(得分:0)

您需要将/proguard-rules.pro更改为此。

#Flutter Wrapper
 -keep class com.shockwave.**
 -keep class io.flutter.app.** { *; }
 -keep class io.flutter.plugin.**  { *; }
 -keep class io.flutter.util.**  { *; }
 -keep class io.flutter.view.**  { *; }
 -keep class io.flutter.**  { *; }
 -keep class io.flutter.plugins.**  { *; }

,然后在/android/app/build.gradle中添加它。

buildTypes {
    release {
        signingConfig signingConfigs.debug
        minifyEnabled true
        shrinkResources false
        useProguard true 
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}