Looks like the app crashes when AndroidManifest.xml is missing the keys below. iOS seems to pick these values up from branch.json just fine.
<!-- Branch init -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_abc" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_abc" />
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
Any ideas how to have Android pick these up from the json file?
Hello, We are working on supporting these keys in JSON file in Android. We will get back to you soon. Thanks.
Is there an update on this? The docs seem to suggest that adding branch.json inside android/app/src/main/assets/would work, however it doesn't as far as I can see
Hello, We are still working on it. We will release a fix soon.
Hi, @sequoiaat. Any estimates of when the fix will be released?
Any updates on this @sequoiaat ?
+1
Hey @sequoiaat,
This is still an issue today.
And currently it's very misleading for maintenance. You see the branch.json file which is used on iOS, but if you apply any changes there, they won't be applied on android.
Keys are not supported in branch.json for Android. In fact, they were never officially supported at all for this SDK because they cannot be supported on Android at all. They happen to work on iOS, but since they can't be supported on Android, there was never any official announcement of support afaik. We'll address this in 3.0, but it may probably require native SDK changes. Along the way we'll also support setting keys from JS instead of configuration.
This has been addressed in the master branch by #417. Basically you need to replace Branch.getAutoInstance(this) in your MainApplication.java with RNBranchModule.getAutoInstance(this). See webview_example for a working example that sets keys from branch.json. The Android and iOS apps do not have key entries in the Android manifest or Info.plist, respectively. This will go out soon in a 3.0.0-beta.2. It also lays the groundwork for setting keys from JS.
I made a proposal for docs since it was unclear to me that manual step is required when using RN > 0.60 with branch.json: https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/pull/520
This is still an issue for me using branch 5.0.0 and react native 0.63. I have a branch.json file next to my package.json that looks like this:
{
"liveKey": "key_live_mykey",
"testKey": "key_test_mykey",
"debugMode": true,
"useTestInstance": true
}
in the docs it says I can omit the keys from my AndroidManifest.xml if I have branch.json, but when I try to run the app I get: Error from Branch: Trouble initializing Branch. Branch API Error: Please enter your branch_key in your project's manifest file first.
This happens even if I manually link and ignore the warnings from react about using autolink instead.
Seeing the same issue with rn-branch 5.0 and RN 0.63. Branch on Android cannot pull keys from branch.json, only from AndroidManifest.xml. This is with RNBranchModule.getAutoInstance(this) being called in MainApplication.java as @jdee suggested.
I spent quite some time trying to understand why including this SDK on Android caused my app to crash on launch. Then I found this issue. Putting the keys in the AndroidManifest.xml fixes the problem.
Here is a stacktrace of the adb logs for when the VM was crashing due to this problem of not having the keys available.
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: FATAL EXCEPTION: main[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: Process: com.PACKAGE_NAME, PID: 24037[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: java.lang.RuntimeException: Unable to create application com.PACKAGE_NAME.MainApplication: android.content.res.Resources$NotFoundException: String resource ID #0x0[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6717)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at android.app.ActivityThread.access$1300(ActivityThread.java:237)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at android.os.Looper.loop(Looper.java:223)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7656)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at android.content.res.Resources.getText(Resources.java:444)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at android.content.res.Resources.getString(Resources.java:537)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at io.branch.referral.BranchUtil.readBranchKey(BranchUtil.java:109)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at io.branch.referral.Branch.getAutoInstance(Branch.java:454)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at io.branch.rnbranch.RNBranchModule.getAutoInstance(RNBranchModule.java:101)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at com.PACKAGE_NAME.MainApplication.onCreate(MainApplication.java:60)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712)[0m
[38;5;196m04-23 11:00:08.963 24037 24037 E AndroidRuntime: ... 8 more[0m
Could someone update the Branch.io docs, which say that you can rely on branch.json for Android (and that's clearly not the case)?
Here is what the Branch RN docs say:
<!-- Branch keys -->
<!-- (Omit if setting keys in branch.json) -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_gdzsepIaUf7wG3dEWb3aBkmcutm0PwJa"/>
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_edwDakKcMeWzJ3hC3aZs9kniyuaWGCTa"/>
If anyone runs into this issue, whether or not you're using branch.json, make sure you add the keys in the AndroidManifest.xml.
I'm using [email protected], [email protected], and [email protected].
This is still an issue on the latest sdk 5.0.3 and react native 0.64 and using RNBranchModule.getAutoInstance(this).
Please reopen.
Most helpful comment
Seeing the same issue with rn-branch 5.0 and RN 0.63. Branch on Android cannot pull keys from
branch.json, only fromAndroidManifest.xml. This is withRNBranchModule.getAutoInstance(this)being called inMainApplication.javaas @jdee suggested.