infobip / mobile-messaging-react-native-plugin

Mobile Messaging SDK plugin for React Native projects
24 stars 4 forks source link

App crash on mobile-messaging initialization #37

Closed vokecodes closed 2 years ago

vokecodes commented 2 years ago

After creating the widget on the dashboard and following the infobip-mobile-messaging-react-native-plugin installation guide, the Android app fails to build with this error

Execution failed for task ':app:mergeDebugResources'.
> [string/google_app_id] /android/app/src/main/res/values/strings.xml   [string/google_app_id] /android/app/build/generated/res/google-services/debug/values/values.xml: Error: Duplicate resources

If I should remove this line of code below in /android/app/src/main/res/values/strings.xml the app builds successfully. <string name="google_app_id">your google app id</string>

We have Firebase set up in the app with the google-services.json file. When I get to build the app successfully for development, after initialization configuration, the app crashes,

kostap13 commented 2 years ago

Hi @vokecodes

Seems that issue is the same like it was for our flutter plugin. Solution for flutter was here: https://github.com/infobip/mobile-messaging-flutter-plugin/issues/3#issuecomment-982514923

Main idea how to fix is here: https://github.com/infobip/mobile-messaging-flutter-plugin/issues/3#issuecomment-982518715

Hope it will helps. If no, then feel free to ask me.

Best regards

tjuric commented 2 years ago

Hi @vokecodes, As @kostap13 has mentioned, you can just apply Google services plugin with your json file and it should be enough.

So, there are two options of providing google_app_id to our project:

  1. putting it in the string resources file or
  2. applying Google services plugin bound to your push project (no additional strings setup required) - we read it automatically (from native SDK: https://github.com/infobip/mobile-messaging-sdk-android/releases/tag/1.16.0)

We'll update our docs about the default setup with Google Services Plugin when we release support for Android 12 (our native SDK lib version 6.x).

BR, Tereza

vokecodes commented 2 years ago

Hi @kostap13 @tjuric,

What we did was to add key/values from google-services.json to resource strings (strings.xml) and removed this line apply plugin: 'com.google.gms.google-services' from the build.gradle file.

It works!

Thanks

ahadtechcarrot commented 2 years ago

Hi @vokecodes if I remove apply plugin: 'com.google.gms.google-services' then I am getting a different error. Can you please elaborate on the process of setting up infobip in android?

vokecodes commented 2 years ago

Hi @ahadtechcarrot , after removing the plugin you need to define the values in google-services.json in strings.xml

<string name="default_web_client_id" translatable="false">***</string>
<string name="gcm_defaultSenderId" translatable="false">***</string>
<string name="google_api_key" translatable="false">***</string>
<string name="google_app_id" translatable="false">***</string>
<string name="google_crash_reporting_api_key" translatable="false">***</string> 
<string name="google_storage_bucket" translatable="false">***</string>
<string name="project_id" translatable="false">***</string>
ahadtechcarrot commented 2 years ago

@vokecodes Thank you for your response. Can you let me know the keys which will be used from google-services.json in these strings element in the place of *** as I am not aware of all the keys in the above answer?

riskpp commented 2 years ago

Hi @ahadtechcarrot you can find this information here - https://developers.google.com/android/guides/google-services-plugin

ahadtechcarrot commented 2 years ago

Thank you @riskpp but I am facing errors in both the scenarios now :

Scenario 1 : removing apply plugin: 'com.google.gms.google-services' and adding all the values in strings.xml I am getting the error message :

> Task :app:fabricGenerateResourcesStagingGoogleDebug FAILED
ERROR - Crashlytics Developer Tools error.
java.lang.IllegalArgumentException: Crashlytics found an invalid API key: null. 

Scenarios 2 : Using apply plugin: 'com.google.gms.google-services'

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceId" on path: DexPathList[[zip file "/data/app/~~HqJrbxlqvpKu-fCiGQ_E2Q==/com.reelCinema.Screens.stage-FIAC9pxSrE844PRXDZOPtg==/base.apk"],nativeLibraryDirectories=[/data/app/~~HqJrbxlqvpKu-fCiGQ_E2Q==/com.reelCinema.Screens.stage-FIAC9pxSrE844PRXDZOPtg==/lib/x86, /data/app/~~HqJrbxlqvpKu-fCiGQ_E2Q==/com.reelCinema.Screens.stage-FIAC9pxSrE844PRXDZOPtg==/base.apk!/lib/x86, /system/lib, /system_ext/lib]]

@riskpp @vokecodes can provide any help regarding this?

riskpp commented 2 years ago

@ahadtechcarrot could you pls check compileSdkVersion, targetSdkVersion on your build.gradle, and which version of com.google.firebase:firebase-messaging are you using? I could only guess that you probably have compileSdkVersion or targetSdkVersion = 31 or using newer version of com.google.firebase:firebase-messaging, installed by some other plugin. If it's the case: we've updated Android SDK to support Android 12, but for plugins this task isn't yet done.

ahadtechcarrot commented 2 years ago

@riskpp I am using react-native third party plugins for firebase :

    "@react-native-firebase/analytics": "^12.0.0",
    "@react-native-firebase/app": "^12.0.0",
    "@react-native-firebase/auth": "^12.0.0",
    "@react-native-firebase/crashlytics": "^12.0.0",

I have no setup done for firebase-messaging as there is no mention of that in your documentation and the above firebase libraries we are using already before this infobip setup. Also, please find my configurations in build.gradle file :

        buildToolsVersion = "29.0.3" 
        minSdkVersion = 21  
        compileSdkVersion = 30  
        targetSdkVersion = 30   
        supportLibVersion = "28.0.0"    
        playServicesVersion = "15.0.1"
        androidMapsUtilsVersion = "0.5+"    
        googlePlayServicesAuthVersion = "16.0.1"   
ahadtechcarrot commented 2 years ago

@riskpp please let me know if I am missing out on something for Android for Version 5.0.1. As per the documentation in GitHub, I have only written the key/value pairs in the strings.xml file and updated the .bash_rc file.

tjuric commented 2 years ago

Just to have a follow-up here as well, @ahadtechcarrot your issue has been moved to a new thread https://github.com/infobip/mobile-messaging-react-native-plugin/issues/39 and solved.