debug-apk 工作正常但在主要活动上签名 apk 发布崩溃

debug-apk work fine but sign apk release crash on main acitvity

调试 apk 运行 正常但发布签名的 apk 在主 activity 上崩溃。我已经检查了所有内容,但我不知道问题出在哪里。[build.gradle][1]

   android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.newtrendsdeveloper.unorthodox"
            minSdkVersion 19
            targetSdkVersion 28
            versionCode 51
            versionName "4.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            vectorDrawables.useSupportLibrary = true
        }
        buildTypes {
            release {
                minifyEnabled true
                shrinkResources true
                proguardFiles 'proguard-rules.pro'
            }
            debug {}
        }

    flavorDimensions "color"
    productFlavors {
        blue {}
        green {
            applicationIdSuffix ".test"
            versionNameSuffix "\"4.0-Microsoft Windows [Version 10.0.17134.407]\n" +
                    "      (c) 2018 Microsoft Corporation. All rights reserved.\n" +
                    "      \n" +
                    "      C:\Users\HP\Downloads\Tusky-master\Tusky-master\app>\";" + getGitSha()
        }
    }

    lintOptions {
        disable 'MissingTranslation'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    androidExtensions {
        experimental = true
    }
    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
}

ext.supportLibraryVersion = '28.0.0'
ext.daggerVersion = '2.19'

// 如果这里更改了库,那么在LicenseActivity

中也应该更改它们
dependencies {
    implementation('com.mikepenz:materialdrawer:6.0.`enter code here`9@aar') {
        transitive = true
    }

很可能是您的 gradle 文件中的 minifyEnabled 为真。

这会删除未使用的代码并混淆代码。所以你可以查看什么是崩溃日志,可能是 class 未找到或空指针异常。检查缺少的内容,然后在构建输出中您可以搜索名为 usage.txt 的文件。这包括所有已删除的内容,您可以确保它已被删除。如果是,则修改 proguard 规则以保留 class.

您可以查看文档以了解有关混淆器的更多信息: https://developer.android.com/studio/build/shrink-code

当然,检查这是否是问题所在的另一种方法是将 minifyEnabled 更改为 false,然后重试。如果可行,那么您可以将其重新打开并找出导致问题的原因。