React-native-onesignal: Unable to build in Android: unreported exception JSONException

Created on 13 Jun 2020  路  15Comments  路  Source: OneSignal/react-native-onesignal

Description:
Unable to build android app:

/Users/fabio/Documents/Progetti/iOS/country-italia-app/node_modules/react-native-onesignal/android/src/main/java/com/geektime/rnonesignalandroid/RNOneSignal.java:489: error: unreported exception JSONException; must be caught or declared to be thrown
callback.invoke(RNUtils.jsonToWritableMap(outcomeEvent.toJSONObject()));
^
/Users/fabio/Documents/Progetti/iOS/country-italia-app/node_modules/react-native-onesignal/android/src/main/java/com/geektime/rnonesignalandroid/RNOneSignal.java:502: error: unreported exception JSONException; must be caught or declared to be thrown
callback.invoke(RNUtils.jsonToWritableMap(outcomeEvent.toJSONObject()));
^
/Users/fabio/Documents/Progetti/iOS/country-italia-app/node_modules/react-native-onesignal/android/src/main/java/com/geektime/rnonesignalandroid/RNOneSignal.java:515: error: unreported exception JSONException; must be caught or declared to be thrown

Environment
React Native: 0.62.2

buildToolsVersion = "28.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29

react-native-onesignal: 3.8.0

Steps to Reproduce Issue:
Try to build

Most helpful comment

Hi, folks!

I've reverted react-native-onesignal to v 3.7.3 and it's working for me.

If you agree with that, you can do the same, meanwhile OneSignal's devs answer us.

All 15 comments

i confirm i receive the same error

The same is happening to me

Hi, folks!

I've reverted react-native-onesignal to v 3.7.3 and it's working for me.

If you agree with that, you can do the same, meanwhile OneSignal's devs answer us.

Hi, folks!

I've reverted react-native-onesignal to v 3.7.3 and it's working for me.

If you agree with that, you can do the same, meanwhile OneSignal's devs answer us.

Downgrading to v 3.7.3 didn't work to me.
Even when trying to run the example project described in the documentation I get the same error. Also tried with a fresh install of react native, following the installation steps in the documentation but no luck.
The build works fine if I uninstall react-native-onesignal.

Hi, folks!

I've reverted react-native-onesignal to v 3.7.3 and it's working for me.

If you agree with that, you can do the same, meanwhile OneSignal's devs answer us.

It Worked for me.

Downgrading to 3.7.3 worked

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal 
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.6, 0.99.99]'
    }
}

Downgrading to v 3.7.3 didn't work to me.
Even when trying to run the example project described in the documentation I get the same error. Also tried with a fresh install of react native, following the installation steps in the documentation but no luck.
The build works fine if I uninstall react-native-onesignal.

After downgrading, are you getting the same error? Did you delete node_modules folder and package-lock.json?

Downgrading to v 3.7.3 didn't work to me.
Even when trying to run the example project described in the documentation I get the same error. Also tried with a fresh install of react native, following the installation steps in the documentation but no luck.
The build works fine if I uninstall react-native-onesignal.

After downgrading, are you getting the same error? Did you delete node_modules folder and package-lock.json?

I was stupidly including the react-native-onesignal version in the package.json file as "react-native-onesignal": "^3.7.3", which was actually installing the latest version.
After I removed the caret (^) and set it just "3.7.3" the error was gone and it now builds successfully. Can't believe I lost all this time due to this stupid mistake.
So I confirm that version 3.7.3 works fine but 3.8.0 does not.
Thanks for all the replies.

downgrading to 3.7.3 worked for me

I was stupidly including the react-native-onesignal version in the package.json file as "react-native-onesignal": "^3.7.3", which was actually installing the latest version.
After I removed the caret (^) and set it just "3.7.3" the error was gone and it now builds successfully. Can't believe I lost all this time due to this stupid mistake.
So I confirm that version 3.7.3 works fine but 3.8.0 does not.
Thanks for all the replies.

I'm glad to hear it!

I hope the downgrading doesn't affect the functionality

Hi,

Attention put the written version "3.7.3"" and not "3.7.3", it worked here

The same is happening to me T.T

Thank you for all of the information working on a fix for this now. Seems we reorganized some of our outcome event tracking and ended up moving the try-catch responsibility (for error logging) into a controller rather than the class itself now.

Be on the look out for a new release 3.8.1

Hey Downgrade to 3.7.3 dont work for me ?
RN: 0.62.2,

buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
googlePlayServicesAuthVersion = "16.0.1"

@mikechoch thanks for the fix!!

Was this page helpful?
0 / 5 - 0 ratings