-
Notifications
You must be signed in to change notification settings - Fork 162
Open
Labels
Description
Describe the bug
I followed all the instructions mentioned in the documentation for the React-Native project, opened a new empty project, tried again, but when trying to create a link on the react-native side, android.content.Context.getApplicationContext() gives a non a null object reference error.
I sent a ticket to the support team, no response
Steps to reproduce
- Create new react-native Android project
- Branch.io integration according to docs
- Make branch.createBranchUniversalObject and call generateShortUrl with generated universal object
Expected behavior
The same code works fine on iOS, my expectation is that the link will be created in the same way on Android
SDK Version
5.15.1
Make and Model
Android Pixel 9 Pro Emulator or Realme 12 Pro real device or any Android real device
OS
15
Additional Information/Context
MainActivity.kt File:
override fun onStart() {
super.onStart()
Branch.sessionBuilder(this).withCallback { branchUniversalObject, linkProperties, error ->
if (error != null) {
Log.e("BranchSDK_Tester", "branch init failed. Caused by -" + error.message)
} else {
Log.i("BranchSDK_Tester", "branch init complete!")
if (branchUniversalObject != null) {
Log.i("BranchSDK_Tester", "title " + branchUniversalObject.title)
Log.i("BranchSDK_Tester", "CanonicalIdentifier " + branchUniversalObject.canonicalIdentifier)
Log.i("BranchSDK_Tester", "metadata " + branchUniversalObject.contentMetadata.convertToJson())
}
if (linkProperties != null) {
Log.i("BranchSDK_Tester", "Channel " + linkProperties.channel)
Log.i("BranchSDK_Tester", "control params " + linkProperties.controlParams)
}
}
}.withData(this.intent.data).init()
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
setIntent(intent)
if (intent != null && intent.hasExtra("branch_force_new_session") && intent.getBooleanExtra("branch_force_new_session",false)) {
Branch.sessionBuilder(this).withCallback { referringParams, error ->
if (error != null) {
Log.e("BranchSDK_Tester", error.message)
} else if (referringParams != null) {
Log.i("BranchSDK_Tester", referringParams.toString())
}
}.reInit()
}
}
MainApplication.kt File:
override fun onCreate() {
super.onCreate()
// Branch logging for debugging
Branch.enableLogging()
// I added this line to try, but it doesn't work with or without it
// Branch.expectDelayedSessionInitialization(false)
// Branch object initialization
Branch.getAutoInstance(this.applicationContext)
SoLoader.init(this, false)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
}
}
branch.json File:
{
"deferInitForPluginRuntime": true
}
Note: the result does not change whether the branch.json file is present or not