androidurbanairship.com

Android release build crashes on launch


App installs and runs fine on an android phone during development when I connect it through usb. But when I deployed to production, now it gives me "Unfortunately app has stopped" every time I open the app.

So I figured it out that it's issue with Urban airship settings in proguard-rules file. And added below lines in proguard-rules file.

-keep class com.urbanairship.** { ; } -dontwarn com.urbanairship.*

But still crashes on launch with following error.

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)

Solution

  • To avoid such problems in production, it is better to enable proGuard for the debug version as well. I had a similar problem, here is my 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 *;}
    

    The text of the error makes me think that proGuard has a problem with activity or serialization. My file includes both.