生成APK(签名)升级gradle版本时出现问题
Posted
技术标签:
【中文标题】生成APK(签名)升级gradle版本时出现问题【英文标题】:Problem when generating APK (signed) upgrading gradle version 【发布时间】:2022-01-21 22:01:00 【问题描述】:我正在尝试将我的 gradle 版本更新到最新版本并且一切正常,但是当我生成签名的 APK 时,应用程序停止工作(无法启动)。 目前我有: android gradle 插件版本:4.1.2 Gradle 版本:6.5
我已尝试更新为: Android gradle 插件版本:4.2.0 摇篮版本:7.0.2 这就是我遇到问题的地方,我生成了签名的 APK,但应用程序无法运行。
我怀疑它是否与 Proguard 或 R8 相关,我不太了解这些文件,所以我尽量不运行它们以查看它是否来自那里的失败,但即使我得到它也没有工作。
我的构建类型:
buildTypes
release
minifyEnabled true
shrinkResources true
proguardFiles 'proguard-android.txt'
你知道问题出在哪里吗?
日志猫:
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
【问题讨论】:
您能在 logcat 中找到并在此处发布您尝试启动应用程序时正在打印的错误吗? (通常有助于按包名过滤 logcat 日志) @AlexLipov 我已经添加了logcat,我仍然无法解决问题,非常感谢您的帮助,谢谢。 这是您的崩溃: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
。在这一行下面应该有一个完整的异常堆栈跟踪,检查一下。如您所见,在空引用上调用了Cursor.moveToFirst()
方法。你能在源代码中找到确切的行吗?如果是 - 请尝试添加一些日志以找出原因。
【参考方案1】:
你必须为 'minifyEnabled' 和 'shrinkResources' 设置 false 来释放
buildTypes
release
minifyEnabled false
shrinkResources false
proguardFiles 'proguard-android.txt'
【讨论】:
感谢回复,我也试过了,还是不行。我一直在尝试更新插件和 gradle 版本,当您更新插件时失败。因为如果我把 Android gradle plugin version: 4.1.2 Gradle version: 7.0.0 它工作以上是关于生成APK(签名)升级gradle版本时出现问题的主要内容,如果未能解决你的问题,请参考以下文章
如何解决Android Studio版本升级4.2.2 打包Apk签名时出现状态窗口中文乱码
Android - 签名的 APK - Gradle 执行失败
生成签名的 apk 时出现 TaskExecutionException
构建签名 Apk 时出现 ClassCastException