OneSignal-Android-SDK icon indicating copy to clipboard operation
OneSignal-Android-SDK copied to clipboard

[Bug]: SDK Crashes on release/app bundle build when not all onesignal modules are included: Service interface i6.a could not be instantiated

Open CarlBarks opened this issue 2 years ago • 8 comments

What happened?

The application crashes on startup with the following error. It happens only on release/app bundle builds with proguard enabled and works as expected on debug builds.

FATAL EXCEPTION: main
                                                                                                                Process: xxxx, PID: 13210
                                                                                                                java.lang.RuntimeException: Unable to create application xxxx: java.lang.Exception: Service interface i6.a could not be instantiated
                                                                                                                	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6764)
                                                                                                                	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
                                                                                                                	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
                                                                                                                	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                                	at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                                	at android.os.Looper.loop(Looper.java:288)
                                                                                                                	at android.app.ActivityThread.main(ActivityThread.java:7872)
                                                                                                                	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                                	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                                	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
                                                                                                                Caused by: java.lang.Exception: Service interface i6.a could not be instantiated
                                                                                                                	at l5.d.getService(Unknown Source:58)
                                                                                                                	at com.onesignal.internal.a.initWithContext(Unknown Source:257)
                                                                                                                	at j5.b.e(Unknown Source:16)
                                                                                                                	at xxx.onCreate(Unknown Source:80)
                                                                                                                	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1277)
                                                                                                                	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6759)
                                                                                                                	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
                                                                                                                	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133) 
                                                                                                                	at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                                                	at android.os.Looper.loopOnce(Looper.java:201) 
                                                                                                                	at android.os.Looper.loop(Looper.java:288) 
                                                                                                                	at android.app.ActivityThread.main(ActivityThread.java:7872) 
                                                                                                                	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                                	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
                                                                                                                	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 

OneSignal SDK Version is at 5.1.1 but also happens on 5.1.0.

Similar issues that were studied are https://github.com/OneSignal/OneSignal-Android-SDK/issues/1810 and https://github.com/OneSignal/OneSignal-Android-SDK/issues/1857 but no proguard rules helped fix the issue.

OneSignal is initiated as OneSignal.initWithContext(this, one_signal_app_id)

Steps to reproduce?

Include only the partial onesignal module dependencies

dependencies {
  implementation 'com.onesignal:core:5.0.0'
  implementation 'com.onesignal:notifications:5.0.0'
}

Build a release build / app bundle with proguard enabled

  1. Application crashes with error Service interface i6.a could not be instantiated

  2. App works as expected in debug mode

  3. Error disappears when all module dependencies are included

dependencies {
  implementation 'com.onesignal:core:5.0.0'
  implementation 'com.onesignal:in-app-messages:5.0.0'
  implementation 'com.onesignal:notifications:5.0.0'
  implementation 'com.onesignal:location:5.0.0'
}

or the full sdk package

dependencies {
  implementation 'com.onesignal:OneSignal:5.0.0'
}

What did you expect to happen?

As explained in the Migration Guide and since the modules In App and Location are not used by the app, I expected that a partial declaration of dependencies would be sufficient.

The issue resolves after depending on the whole OneSIgnal SDK, so I suspect something related to proguard rules or internal dependencies of the modules causes the inability to depend on the partial sdk.

OneSignal Android SDK version

5.1.1

Android version

13

Specific Android models

No response

Relevant log output

Two warnings before the crash helped pinpoint the issue to the missing modules:


 java.lang.ClassNotFoundException: com.onesignal.inAppMessages.InAppMessagesModule
2024-01-22 13:33:40.909 13210-13210 System.err                                               W  	at java.lang.Class.classForName(Native Method)
2024-01-22 13:33:40.909 13210-13210 System.err                                               W  	at java.lang.Class.forName(Class.java:454)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at java.lang.Class.forName(Class.java:379)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at com.onesignal.internal.a.<init>(Unknown Source:94)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at j5.b$a.a(Unknown Source:2)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at j5.b$a.invoke(Unknown Source:0)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at kotlin.SynchronizedLazyImpl.getValue(Unknown Source:20)
2024-01-22 13:33:40.909 13210-13210 System.err                                               W  	at j5.b.b(Unknown Source:2)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at j5.b.e(Unknown Source:12)
2024-01-22 13:33:40.909 13210-13210 System.err                                               W  	at xxx.onCreate(Unknown Source:80)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1277)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6759)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.os.Handler.dispatchMessage(Handler.java:106)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.os.Looper.loopOnce(Looper.java:201)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.os.Looper.loop(Looper.java:288)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.app.ActivityThread.main(ActivityThread.java:7872)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at java.lang.reflect.Method.invoke(Native Method)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  Caused by: java.lang.ClassNotFoundException: com.onesignal.inAppMessages.InAppMessagesModule
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	... 21 more
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  java.lang.ClassNotFoundException: com.onesignal.location.LocationModule
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at java.lang.Class.classForName(Native Method)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at java.lang.Class.forName(Class.java:454)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at java.lang.Class.forName(Class.java:379)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at com.onesignal.internal.a.<init>(Unknown Source:94)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at j5.b$a.a(Unknown Source:2)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at j5.b$a.invoke(Unknown Source:0)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at kotlin.SynchronizedLazyImpl.getValue(Unknown Source:20)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at j5.b.b(Unknown Source:2)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at j5.b.e(Unknown Source:12)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at xxx.onCreate(Unknown Source:80)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1277)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6759)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.os.Handler.dispatchMessage(Handler.java:106)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.os.Looper.loopOnce(Looper.java:201)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.os.Looper.loop(Looper.java:288)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at android.app.ActivityThread.main(ActivityThread.java:7872)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at java.lang.reflect.Method.invoke(Native Method)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  Caused by: java.lang.ClassNotFoundException: com.onesignal.location.LocationModule
2024-01-22 13:33:40.909 13210-13210 System.err                                                W  	... 21 more
2024-01-22 13:33:40.913 13210-13210 OneSignal                                                 W  [main] Service not found: interface i6.a

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

CarlBarks avatar Jan 22 '24 13:01 CarlBarks

@CarlBarks thank you for the detailed reproduction steps! We're looking into this more and will get back to you as soon as possible.

jennantilla avatar Jan 24 '24 02:01 jennantilla

Also experiencing this when building a release build with R8 enabled.

sebastinto avatar Apr 23 '24 21:04 sebastinto

@CarlBarks I noticed you said you are using 5.1.1 but the gradle files you shared all show 5.0.0. Can you confirm which version of OneSignal you are using?

@sebastinto are you still seeing crashes due to missing classes only when R8 is enabled?

These missing class issues due to minification should have been fixed in 5.0.1 in this PR: https://github.com/OneSignal/OneSignal-Android-SDK/pull/1828

jkasten2 avatar Jun 24 '24 19:06 jkasten2

@sebastinto are you still seeing crashes due to missing classes only when R8 is enabled?

@jkasten2 I am unfortunately. Using Release 5.1.15.

The error I'm getting:

FATAL EXCEPTION: main
Process: com.domain.domain, PID: 23427
   java.lang.RuntimeException: Unable to create application com.domain.domain.DomainApplication: java.lang.Exception: Service interface qa.a could not be instantiated
    	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7624)
    	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2400)
    	at android.os.Handler.dispatchMessage(Handler.java:106)
    	at android.os.Looper.loopOnce(Looper.java:226)
    	at android.os.Looper.loop(Looper.java:313)
    	at android.app.ActivityThread.main(ActivityThread.java:8762)
    	at java.lang.reflect.Method.invoke(Native Method)
    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
 Caused by: java.lang.Exception: Service interface qa.a could not be instantiated
    	at T9.e.getService(Unknown Source:52)
    	at com.onesignal.internal.OneSignalImp.initWithContext(Unknown Source:261)
    	at com.domain.domain.DomainApplication.onCreate(Unknown Source:119)
    	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1266)
    	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7619)
    	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2400) 
    	at android.os.Handler.dispatchMessage(Handler.java:106) 
    	at android.os.Looper.loopOnce(Looper.java:226) 
    	at android.os.Looper.loop(Looper.java:313) 
    	at android.app.ActivityThread.main(ActivityThread.java:8762) 
    	at java.lang.reflect.Method.invoke(Native Method) 
    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) 
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) 

qa.a maps to com.onesignal.location.ILocationManager

Using these rules fixes the issue (which isn't surprising since this preserves every OneSignal class):

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

sebastinto avatar Jun 24 '24 20:06 sebastinto

@sebastinto Thanks for the details, I was able to reproduce as well now, but only if android.enableR8.fullMode=true is set in the gradle.properties. (defaults to true in AGP [Android Gradle plugin] 8.0.0 and later)

jkasten2 avatar Jun 24 '24 23:06 jkasten2

@sebastinto Thanks for the details, I was able to reproduce as well now, but only if android.enableR8.fullMode=true is set in the gradle.properties. (defaults to true in AGP [Android Gradle plugin] 8.0.0 and later)

@jkasten2 Interesting! The project I tested on is using AGP 8.5.0 (it also explicitly declares android.enableR8.fullMode=true in the gradle.properties file but TIL this is not necessary anymore) so that tracks.

sebastinto avatar Jun 24 '24 23:06 sebastinto

Hey @jkasten2 , as @sebastinto mentioned, we also experienced this in higher versions of OneSignal, despite my log being from an earlier one. As it is a long time since then, we have not revisited this as we basically include the whole SDK until this issue is resolved and we can try to separate modules again.

CarlBarks avatar Jun 25 '24 09:06 CarlBarks

Quick update, PR #2136 has been merged into main to address this issue. It will be included in the next release. I'll reply again once released and close this issue then.

jkasten2 avatar Jun 27 '24 19:06 jkasten2

Fix is now available in release 5.1.16.

jkasten2 avatar Jul 02 '24 22:07 jkasten2