react-native-poc-usabilla
v1.3.0
Published
1. Enter the `android` folder in home directory of the RN app 2. Copy the latest .aar version of the Usabilla SDK in the path app/libs/ 3. Change the Gradle wrapper to be at least `4.1-all` in `gradle-wrapper.properties` 4. Replace the original Project-le
Downloads
4
Readme
Android
- Enter the
android
folder in home directory of the RN app - Copy the latest .aar version of the Usabilla SDK in the path app/libs/
- Change the Gradle wrapper to be at least
4.1-all
ingradle-wrapper.properties
- Replace the original Project-level
build.gradle
file with thisbuildscript { ext.kotlin_version = '1.2.10' repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { mavenLocal() jcenter() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } google() } }
- Add the following to the App-level
build.gradle
fileapply plugin: 'kotlin-android' ... implementation fileTree(dir: "libs", include: ["*.aar"]) implementation "com.android.support:appcompat-v7:26.1.0" implementation 'com.mcxiaoke.volley:library:1.0.19' implementation "com.facebook.react:react-native:0.52.0" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.android.support.test.espresso:espresso-idling-resource:3.0.1'
- Create a class called
UsabillaBridge.kt
which will host all the methods bridging from React Native to Java/Kotlin, such asclass BridgeModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { override fun getName() = "UsabillaBridge" @ReactMethod fun initialize(appId: String) { currentActivity?.let { Usabilla.initialize(it.baseContext, appId) Toast.makeText(it.baseContext, "SDK initialised with AppId $appId", Toast.LENGTH_SHORT).show() } } // Other methods }
- Create a class called
BridgePackage.kt
to be able to reference the previous class from React Native, such asclass BridgePackage : ReactPackage { override fun createNativeModules(reactContext: ReactApplicationContext): MutableList<NativeModule> = mutableListOf(UsabillaBridge(reactContext)) override fun createViewManagers(reactContext: ReactApplicationContext?): MutableList<ViewManager<View, ReactShadowNode<*>>> = Collections.emptyList() }
- In
MainApplication.kt
(or its java version) add the BridgePackage to the methodgetPackages()
- Run the app either opening the project in the
android
folder with AndroidStudio, or via command line typingreact-native run-android
from within the RN folder - Add the following to
App.js
import { NativeModules } from 'react-native';
- You should be able to call a method in the
UsabillaBridge.kt
from the RN app withNativeModules.UsabillaBridge.initialize('5a37c12145380769f373d71b');