Android 发布构建在启动时崩溃

Android release build crashes on launch

当我通过 USB 连接应用程序时,在开发过程中,应用程序可以在 android phone 上正常安装和运行。但是,当我部署到生产环境时,现在每次打开应用程序时都会显示“不幸的是应用程序已停止”。

所以我发现这是 proguard-rules 文件中 Urban 飞艇设置的问题。 并在 proguard-rules 文件中添加以下行。

-保持 class com.urbanairship.** { ; } -dontwarn com.urbanairship.*

但仍然在启动时崩溃并出现以下错误。

java.lang.NoSuchMethodError: No virtual method object()Lm/b/g; in class Lm/b/g; or its super classes (declaration of 'm.b.g' appears in /data/app/~~8aj5YP2-7MODBpBbFJ_YYw==/com.hct2.android.web.dev-dcCYVQdPn_VkfhnR9UHHfA==/base.apk!classes2.dex)
        at com.urbanairship.json.JsonMap.write(JsonMap.java:211)
        at com.urbanairship.json.JsonMap.toString(JsonMap.java:195)
        at com.urbanairship.job.WorkUtils.convertToData(WorkUtils.java:24)
        at com.urbanairship.job.WorkManagerScheduler.createWorkRequest(WorkManagerScheduler.java:35)
        at com.urbanairship.job.WorkManagerScheduler.schedule(WorkManagerScheduler.java:22)
        at com.urbanairship.job.JobDispatcher.dispatch(JobDispatcher.java:92)
        at com.urbanairship.channel.AirshipChannel.dispatchUpdateJob(AirshipChannel.java:1115)
        at com.urbanairship.channel.AirshipChannel.dispatchUpdateJob(AirshipChannel.java:1096)
        at com.urbanairship.channel.AirshipChannel.updateRegistration(AirshipChannel.java:744)
        at com.urbanairship.push.PushManager.setUserNotificationsEnabled(PushManager.java:495)
        at f.g.a.a.a.h.f.a.onCreate(BaseActivity.java:175)

为避免在生产中出现此类问题,最好也为调试版本启用 proGuard。 我有一个类似的问题,这是我的proguard-rules.pro:

-optimizationpasses 5
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging*/
-allowaccessmodification
-repackageclasses ''

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

-keepattributes InnerClasse
-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.SerializationKt
-keep,includedescriptorclasses class com.mymiscapps.example.**$$serializer { *; }

-keep class kotlin.reflect.** { *; }
-dontwarn kotlin.reflect.**
-keep class org.jetbrains.** { *; }

-keep class com.mymiscapps.example.** { *; }

-keep public class org.apache.commons.io.**
-keep public class com.google.gson.**
-keep public class com.google.gson.** {public private protected *;}

错误文本让我觉得 proGuard 在 activity 或序列化方面有问题。我的文件包括两者。