生成 APK(已签名)升级 gradle 版本时出现问题

Problem when generating APK (signed) upgrading gradle version

提问人:Alejandro Casado Benito 提问时间:12/20/2021 最后编辑:Alejandro Casado Benito 更新时间:7/8/2022 访问量:2483

问:

我正在尝试将我的 gradle 版本更新到最新版本,一切正常,但是当我生成签名的 APK 时,应用程序停止工作(无法启动)。 目前我有: Android gradle 插件版本:4.1.2 Gradle 版本:6.5

我试过更新到: Android gradle 插件版本:4.2.0 Gradle 版本:7.0.2 这就是我有问题的地方,我生成了签名的APK,但应用程序无法正常工作。

我怀疑它是否与 Proguard 或 R8 有关,我不太了解这些文档,所以我尽量不运行它们以查看它是否来自那里的故障,但即使这样我也没有让它工作。

我构建类型:

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles 'proguard-android.txt'
    }
}

你知道问题可能出在哪里吗?

logcat:

12-24 11:23:10.982   504  1885 I ActivityTaskManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.spotbros.defense/com.spotbros.spotbroslib.MainActivity bnds=[842,613][1043,923]} from uid 10129
12-24 11:23:10.984   504  1885 W ActivityTaskManager: Can't find TaskDisplayArea to determine support for multi window. Task id=39 attached=false
12-24 11:23:10.986   970  1660 D EGL_emulation: app_time_stats: avg=2043.51ms min=16.19ms max=14202.23ms count=7
12-24 11:23:10.990   504  1885 D CompatibilityChangeReporter: Compat change id reported: 174042980; UID 10147; state: DISABLED
12-24 11:23:10.992   504  1885 D CompatibilityChangeReporter: Compat change id reported: 184838306; UID 10147; state: DISABLED
12-24 11:23:10.994   504  1885 D CompatibilityChangeReporter: Compat change id reported: 185004937; UID 10147; state: DISABLED
12-24 11:23:10.997   504  1885 D CompatibilityChangeReporter: Compat change id reported: 181136395; UID 10147; state: DISABLED
12-24 11:23:10.998   504  1885 D CompatibilityChangeReporter: Compat change id reported: 174042936; UID 10147; state: DISABLED
12-24 11:23:11.002   504  1885 D CompatibilityChangeReporter: Compat change id reported: 168419799; UID 10147; state: DISABLED
12-24 11:23:11.017   504   541 D CompatibilityChangeReporter: Compat change id reported: 135634846; UID 10147; state: DISABLED
12-24 11:23:11.017   504   550 D CompatibilityChangeReporter: Compat change id reported: 143937733; UID 10147; state: ENABLED
12-24 11:23:11.029   320   320 D Zygote  : Forked child process 23520
12-24 11:23:11.032   504   550 I ActivityManager: Start proc 23520:com.spotbros.defense/u0a147 for pre-top-activity {com.spotbros.defense/com.spotbros.spotbroslib.MainActivity}
12-24 11:23:11.041 23520 23520 W potbros.defens: Unexpected CPU variant for X86 using defaults: x86_64
12-24 11:23:11.047 23520 23520 E potbros.defens: Not starting debugger since process cannot load the jdwp agent.
12-24 11:23:11.057   353   353 D goldfish-address-space: claimShared: Ask to claim region [0x3f0f68000 0x3f18cd000]
12-24 11:23:11.073   353   353 D goldfish-address-space: claimShared: Ask to claim region [0x3f71ef000 0x3f7b54000]
12-24 11:23:11.073   504   532 W InputReader: Device virtio_input_multi_touch_5 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_8 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_10 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_11 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_4 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_2 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_7 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_6 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_9 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_3 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_5 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_8 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_10 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_11 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_4 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_2 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_7 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_6 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_9 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.074   504   532 W InputReader: Device virtio_input_multi_touch_3 is associated with display ADISPLAY_ID_NONE.
12-24 11:23:11.090 23520 23520 D CompatibilityChangeReporter: Compat change id reported: 171979766; UID 10147; state: DISABLED
12-24 11:23:11.104   353   353 D goldfish-address-space: claimShared: Ask to claim region [0x3f4feb000 0x3f5950000]
12-24 11:23:11.120   504   659 D CompatibilityChangeReporter: Compat change id reported: 171306433; UID 10147; state: DISABLED
12-24 11:23:11.146 23520 23520 V GraphicsEnvironment: ANGLE Developer option for 'com.spotbros.defense' set to: 'default'
12-24 11:23:11.150 23520 23520 V GraphicsEnvironment: Neither updatable production driver nor prerelease driver is supported.
12-24 11:23:11.155 23520 23520 D NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: false
12-24 11:23:11.160  2116  2116 I GsaVoiceInteractionSrv: Handling ACTION_STOP_HOTWORD
12-24 11:23:11.162  2116  2116 E HwDetectorWithState: a: 3
12-24 11:23:11.170 23520 23520 D NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: false
12-24 11:23:11.174 23520 23520 I MultiDex: VM with version 2.1.0 has multidex support
12-24 11:23:11.176 23520 23520 I MultiDex: Installing application
12-24 11:23:11.178 23520 23520 I MultiDex: VM has multidex support, MultiDex support library is disabled.
12-24 11:23:11.194   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.197   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.209 23520 23520 D FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
12-24 11:23:11.211   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.213   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.217 23520 23520 D FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
12-24 11:23:11.219 23520 23520 D FirebaseApp: com.google.android.gms.measurement.AppMeasurement is not linked. Skipping initialization.
12-24 11:23:11.221 23520 23520 I FirebaseInitProvider: FirebaseApp initialization successful
12-24 11:23:11.228   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.239   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.245   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.255 23520 23520 W System.err: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
12-24 11:23:11.255 23520 23520 W System.err: SLF4J: Defaulting to no-operation (NOP) logger implementation
12-24 11:23:11.255 23520 23520 W System.err: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
12-24 11:23:11.257   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.261   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.263   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.279   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.281   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.294   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.297   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.311   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.313   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.320 23520 23520 D ActivityThread: Loading provider com.spotbros.defense.contentproviders.multiprocesspreferencesprovider: com.imbox.defense.database.ImboxDefenseMultiprocessPreferencesProvider
12-24 11:23:11.327   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.330   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.344   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.347   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.361   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.363   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.377   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.379   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.395   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.397   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.411   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.413   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.428   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.430   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.445   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.447   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.462   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.464   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.478   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.480   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.494   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.497   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.511   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.514   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.528   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.532   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.545   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.548   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.561   355   355 W RanchuHwc: validateDisplay: layer 706 CompositionType 1, fallback
12-24 11:23:11.564   355   355 W RanchuHwc: presentDisplay display has no layers to compose, flushing client target buffer.
12-24 11:23:11.620   504  1885 W ActivityManager: Unable to start service Intent { act=android.service.smartspace.SmartspaceService cmp=com.google.android.as/com.google.android.apps.miphone.aiai.app.AiAiSmartspaceService } U=0: not found
12-24 11:23:11.620   504  1885 W RemoteSmartspaceService: could not bind to Intent { act=android.service.smartspace.SmartspaceService cmp=com.google.android.as/com.google.android.apps.miphone.aiai.app.AiAiSmartspaceService } using flags 67112961
12-24 11:23:11.622   504   504 W ActivityManager: Unbind failed: could not find connection for android.app.LoadedApk$ServiceDispatcher$InnerConnection@4d069a6
12-24 11:23:11.625   727   779 D EGL_emulation: app_time_stats: avg=1663.02ms min=13.67ms max=14835.26ms count=9
12-24 11:23:11.946 23520 23520 E ActivityThread: Failed to find provider info for com.spotbros.enterprise.contentproviders.mainprovider
12-24 11:23:11.949 23520 23520 E ActivityThread: Failed to find provider info for com.spotbros.enterprise.contentproviders.mainprovider
12-24 11:23:11.952 23520 23520 E ActivityThread: Failed to find provider info for com.spotbros.enterprise.contentproviders.mainprovider
12-24 11:23:11.955   504  1885 D CompatibilityChangeReporter: Compat change id reported: 135634846; UID 10147; state: DISABLED
12-24 11:23:11.957   504   550 D CompatibilityChangeReporter: Compat change id reported: 143937733; UID 10147; state: ENABLED
12-24 11:23:11.965   320   320 D Zygote  : Forked child process 23543
12-24 11:23:11.966   504   550 I ActivityManager: Start proc 23543:com.spotbros.defense:remote/u0a147 for service {com.spotbros.defense/com.spotbros.service.SpotBrosService}
12-24 11:23:11.970 23520 23520 E ActivityThread: Failed to find provider info for com.spotbros.enterprise.contentproviders.mainprovider
12-24 11:23:11.972 23520 23520 E ActivityThread: Failed to find provider info for com.spotbros.enterprise.contentproviders.mainprovider
12-24 11:23:11.974 23520 23520 D AndroidRuntime: Shutting down VM
12-24 11:23:11.978 23520 23520 E AndroidRuntime: FATAL EXCEPTION: main
12-24 11:23:11.978 23520 23520 E AndroidRuntime: Process: com.spotbros.defense, PID: 23520
12-24 11:23:11.978 23520 23520 E AndroidRuntime: java.lang.RuntimeException: Unable to create application com.spotbros.application.SpotbrosApplication: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.database.Cursor.moveToFirst()' on a null object reference
安卓 android-gradle-plugin proguard gradle-plugin android-r8

评论

0赞 Alex Lipov 12/21/2021
您能否在logcat中找到并在此处发布您尝试启动应用程序时正在打印的错误?(按包名过滤 logcat 日志通常会有所帮助)
0赞 Alejandro Casado Benito 12/24/2021
@AlexLipov我已经添加了logcat,但我仍然无法解决问题,任何帮助将不胜感激,谢谢。
0赞 Alex Lipov 12/25/2021
这是你的崩溃:。此行下方应该有一个完整的异常堆栈跟踪,请查看。正如你所看到的,有一个对 null 引用的方法的调用。你能在源代码中找出确切的行吗?如果是 - 请尝试添加一些日志以找出导致它的原因。12-24 11:23:11.978 23520 23520 E AndroidRuntime: java.lang.RuntimeException: Unable to create application com.spotbros.application.SpotbrosApplication: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.database.Cursor.moveToFirst()' on a null object referenceCursor.moveToFirst()
0赞 Alejandro Casado Benito 1/10/2022
我仍在寻找光标错误,但我找不到它。但是我尝试更新附加组件和 gradle 版本,并且在更新附加组件时发生错误。因为如果我把 Android Gradle 插件版本:4.1.2 Gradle 版本:7.0.0.0 它可以正常工作。知道为什么会这样吗?

答:

0赞 Rajasekaran M 12/20/2021 #1

您必须为 'minifyEnabled' 设置 false,为 'shrinkResources' 设置 release

buildTypes {
release {
    minifyEnabled false
    shrinkResources false
    proguardFiles 'proguard-android.txt'
    }
}

评论

0赞 Alejandro Casado Benito 12/20/2021
感谢您的回复,我也试过了,但它也不起作用。我一直在尝试更新插件和 gradle 版本,但当您更新插件时失败。因为如果我把 Android gradle 插件版本:4.1.2 Gradle 版本:7.0.0 它可以工作
0赞 esi 7/8/2022 #2

如果您在应用程序中使用数据库,可能是因为您在 ProGuard File for Database 中的设置,您应该在签署 APK 时检查数据库文件是否存在。