infobip / mobile-messaging-react-native-plugin

Mobile Messaging SDK plugin for React Native projects
29 stars 6 forks source link

Example app does not work on Android #82

Open SomniumDigital opened 8 hours ago

SomniumDigital commented 8 hours ago

I could not get the Example app to work on Android without making the following changes:

diff --git a/Example/android/build.gradle b/Example/android/build.gradle
index 90b9803..4a457d5 100644
--- a/Example/android/build.gradle
+++ b/Example/android/build.gradle
@@ -23,14 +23,14 @@ buildscript {
         mavenCentral()
     }
     dependencies {
-        classpath("com.android.tools.build:gradle:7.2.2")
+        classpath("com.android.tools.build:gradle:7.3.1")
         classpath("com.facebook.react:react-native-gradle-plugin")
         classpath("de.undercouch:gradle-download-task:4.1.2")
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files

         //GMS Gradle plugin
-        classpath 'com.google.gms:google-services:4.3.10'
+        classpath 'com.google.gms:google-services:4.3.14'
     }
 }

diff --git a/Example/android/gradle/wrapper/gradle-wrapper.properties b/Example/android/gradle/wrapper/gradle-wrapper.properties
index 669386b..8fad3f5 100644
--- a/Example/android/gradle/wrapper/gradle-wrapper.properties
+++ b/Example/android/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
diff --git a/Example/package.json b/Example/package.json
index 9d9c539..843befb 100644
--- a/Example/package.json
+++ b/Example/package.json
@@ -19,7 +19,7 @@
     "react-native-gesture-handler": "^1.10.3",
     "react-native-reanimated": "^2.10.0",
     "react-native-safe-area-context": "^3.2.0",
-    "react-native-screens": "^3.19.0",
+    "react-native-screens": "3.29.0",
     "react-native-url-polyfill": "^1.3.0",
     "require-dependency-map": "^3.1.1"
   },
@@ -29,12 +29,15 @@
     "@react-native-community/eslint-config": "^2.0.0",
     "@react-navigation/native": "6.0.13",
     "@react-navigation/native-stack": "6.4.0",
+    "add": "^2.0.6",
     "babel-jest": "^26.6.3",
     "eslint": "^7.32.0",
     "jest": "^26.6.3",
     "metro-react-native-babel-preset": "0.72.3",
+    "react-native-gradle-plugin": "^0.71.19",
     "react-native-screens": "3.14.0",
-    "react-test-renderer": "18.1.0"
+    "react-test-renderer": "18.1.0",
+    "yarn": "^1.22.22"
   },
   "jest": {
     "preset": "react-native"

It required me to update the Android Gradle build tools, Gradle Google Services and the Gradle version. Once I did this I was able to build the app, however the app seems to be unable to connect to Metro, the only way I've been able to run the app properly is by pre-compiling the JS bundle like so:

yarn react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

This then resulted in me being able to actually use the app in the Android emulator.

Unfortunately when trying to test the Deep Links however, they do not seem to work, the following adb command only opened the app up on the Home Screen:

adb shell am start -a android.intent.action.VIEW -d "com.infobip.mobilemessaging://deeplink/TestDeeplinkingScreen/TestDeeplinkingScreen2" com.example

Notes: Machine: Apple MacBook M2 Pro OS: Sonoma 14.4.1 NodeJS: v20.15.0

SomniumDigital commented 4 hours ago

I've now managed to get this up-and-running by doing the following:

I ensured the Android SDK Command-Line Tools were installed, then restarted my machine. For more info see here: https://stackoverflow.com/a/71544202/3568695

This enabled me to get the Example app working and connecting properly to Metro.

Secondly the command in the docs to test the deep link setup in the example app is incorrect, it should be the following:

adb shell am start -a android.intent.action.VIEW -d "com.infobip.mobilemessaging://deeplink/TestDeeplinkingScreen/TestDeeplinking2" com.example

N.B. TestDeeplinking2 instead of TestDeeplinkingScreen2