Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Getting crash when running release build #713

Closed
2 of 3 tasks
dchandrani opened this issue Aug 23, 2023 · 20 comments
Closed
2 of 3 tasks

[Bug]: Getting crash when running release build #713

dchandrani opened this issue Aug 23, 2023 · 20 comments

Comments

@dchandrani
Copy link

dchandrani commented Aug 23, 2023

What happened?

Implemented OneSignal version 5.0.0 in Flutter app, but when tried to run the app in release mode I got a FATAL EXCEPTION saying Unable to start receiver com.onesignal.notifications.receivers.UpgradeReceiver: java.lang.Exception: Service class e7.b could not be instantiated.

Steps to reproduce?

1. Install onesignal_flutter: ^5.0.0

2. Launch the Android app in release mode

3. Note the crash in debug console

What did you expect to happen?

I expected to receive call back of OneSignal.User.pushSubscription.addObserver to get user id.

OneSignal Flutter SDK version

5.0.0

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

E/AndroidRuntime(11216): FATAL EXCEPTION: main
E/AndroidRuntime(11216): Process: com.voliz, PID: 11216
E/AndroidRuntime(11216): java.lang.RuntimeException: Unable to start receiver com.onesignal.notifications.receivers.UpgradeReceiver: java.lang.Exception: Service class e7.b could not be instantiated
E/AndroidRuntime(11216):        at android.app.ActivityThread.handleReceiver(ActivityThread.java:4485)
E/AndroidRuntime(11216):        at android.app.ActivityThread.access$1900(ActivityThread.java:254)
E/AndroidRuntime(11216):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2195)
E/AndroidRuntime(11216):        at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(11216):        at android.os.Looper.loopOnce(Looper.java:233)
E/AndroidRuntime(11216):        at android.os.Looper.loop(Looper.java:344)
E/AndroidRuntime(11216):        at android.app.ActivityThread.main(ActivityThread.java:8212)
E/AndroidRuntime(11216):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11216):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
E/AndroidRuntime(11216):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
E/AndroidRuntime(11216): Caused by: java.lang.Exception: Service class e7.b could not be instantiated
E/AndroidRuntime(11216):        at u6.c.i(ServiceProvider.kt:59)
E/AndroidRuntime(11216):        at f8.a.l(OneSignalImp.kt:79)
E/AndroidRuntime(11216):        at o6.d.j(OneSignal.kt:13)
E/AndroidRuntime(11216):        at com.onesignal.notifications.receivers.UpgradeReceiver.onReceive(UpgradeReceiver.kt:18)
E/AndroidRuntime(11216):        at android.app.ActivityThread.handleReceiver(ActivityThread.java:4469)
E/AndroidRuntime(11216):        ... 9 more

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Wiwo99
Copy link

Wiwo99 commented Aug 23, 2023

me too

1 similar comment
@rafaelbarbosadrip
Copy link

me too

@Jakoo13
Copy link

Jakoo13 commented Aug 24, 2023

I am seeing this as well. In version 5 after all proper migration and app working in debug, in release build the OneSignal.initialize(appId) is not working.

@sur2548
Copy link

sur2548 commented Aug 24, 2023

Same for me as well, all the classes from the OneSignal are getting removed in the production build.

@Kuodster
Copy link

Same problem here, only after building the apk.

@sur2548
Copy link

sur2548 commented Aug 25, 2023

Solution: Adding ProGuard Rules for OneSignal in Release Build

To ensure that ProGuard doesn't obfuscate the necessary classes from the OneSignal library in your Android project's release build, follow these steps:

  1. Create or locate the proguard-rules.pro file in the root directory of your project.

  2. Open the proguard-rules.pro file and add the following ProGuard rule to keep all classes within the com.onesignal package:

    -keep class com.onesignal.** {*;}
    
  3. Modify your app's build.gradle file to include the ProGuard rule and enable ProGuard for the release build:

    android {
        // ... other configuration settings ...
    
        buildTypes {
            release {
                minifyEnabled true
                shrinkResources true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                signingConfig signingConfigs.release
            }
        }
    
        // ... other configuration settings ...
    }

By adding the above ProGuard rule and configuring the release build type in this manner, you're ensuring that ProGuard won't obfuscate the classes required by the OneSignal library. This helps prevent any runtime issues or unexpected behavior when using OneSignal features in the production version of your app.

@Chhay67
Copy link

Chhay67 commented Aug 28, 2023

any solution ???

@dchandrani
Copy link
Author

dchandrani commented Aug 28, 2023

@Chhay67 You can try the above solution by @sur2548

@PhamChiNang151020
Copy link

@Chhay67 You can try the above solution by @sur2548

I tried to try, but now my Apk file is still not registered for OneSignal control version

image
image

@sur2548
Copy link

sur2548 commented Aug 28, 2023

@Chhay67 You can try the above solution by @sur2548

I tried to try, but now my Apk file is still not registered for OneSignal control version

image image

@PhamChiNang151020 Do not initialize directly in the main function.

https://documentation.onesignal.com/docs/flutter-sdk-setup#step-5-set-up-onesignal-for-android

@PhamChiNang151020
Copy link

PhamChiNang151020 commented Aug 28, 2023

@sur2548>

Sorry, But I initialize by main.dart

And, buildTypes in the path android/app/build.gradle

If I'm doing something wrong, please help. Thank you!

@sur2548
Copy link

sur2548 commented Aug 28, 2023

@PhamChiNang151020 You can follow the official doc or Could you move the initialization to the app level?

Anyway there is a PR for this, you can check that as well

#716

@Mohamed-Nagdy
Copy link

Solution: Adding ProGuard Rules for OneSignal in Release Build

To ensure that ProGuard doesn't obfuscate the necessary classes from the OneSignal library in your Android project's release build, follow these steps:

  1. Create or locate the proguard-rules.pro file in the root directory of your project.
  2. Open the proguard-rules.pro file and add the following ProGuard rule to keep all classes within the com.onesignal package:
    -keep class com.onesignal.** {*;}
    
  3. Modify your app's build.gradle file to include the ProGuard rule and enable ProGuard for the release build:
    android {
        // ... other configuration settings ...
    
        buildTypes {
            release {
                minifyEnabled true
                shrinkResources true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                signingConfig signingConfigs.release
            }
        }
    
        // ... other configuration settings ...
    }
    

By adding the above ProGuard rule and configuring the release build type in this manner, you're ensuring that ProGuard won't obfuscate the classes required by the OneSignal library. This helps prevent any runtime issues or unexpected behavior when using OneSignal features in the production version of your app.

Thanks it resolve my problem

@emawby
Copy link
Contributor

emawby commented Sep 15, 2023

The latest release 5.0.1 adds the proguard rules to Android release builds that should resolve this issue. If that is not the case please tag me here!

@edisonlsm
Copy link

@emawby I keep getting errors related to the flutter plugin android code on Crashlytics. Maybe those should also not be minified?

(Those crashes happened on version 5.0.4)
Captura de Tela 2024-02-01 às 13 17 44

Checking on mapping.txt after a release build, it seems that the plugin code are getting minified
Captura de Tela 2024-02-01 às 13 19 06

@sur2548
Copy link

sur2548 commented Feb 2, 2024

@emawby I keep getting errors related to the flutter plugin android code on Crashlytics. Maybe those should also not be minified?

(Those crashes happened on version 5.0.4) Captura de Tela 2024-02-01 às 13 17 44

Checking on mapping.txt after a release build, it seems that the plugin code are getting minified Captura de Tela 2024-02-01 às 13 19 06

Same for me as well, for some devices it is crashing

@rickgrotavi
Copy link

@emawby I keep getting errors related to the flutter plugin android code on Crashlytics. Maybe those should also not be minified?

(Those crashes happened on version 5.0.4) Captura de Tela 2024-02-01 às 13 17 44

Checking on mapping.txt after a release build, it seems that the plugin code are getting minified Captura de Tela 2024-02-01 às 13 19 06

Got the same on Huawei device. On other devices with google - is ok.

@jkasten2
Copy link
Member

@edisonlsm @sur2548 @rickgrotavi can you share the version of OneSignal you are using and the proguard / minification rules you are using in your app?

@rickgrotavi
Copy link

rickgrotavi commented Apr 15, 2024

@edisonlsm @sur2548 @rickgrotavi can you share the version of OneSignal you are using and the proguard / minification rules you are using in your app?

onesignal_flutter: 5.1.4

-keep class com.onesignal.** {*;} in proguard-rules.pro

app/build.gradle
buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } }

upd: if i set minifyEnabled false and shrinkResources false it looks error-free

@alikamal1
Copy link

include in proguard-rules.pro

-keepattributes Signature
-keep class com.onesignal.** { *; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests