Android: Crash on cold start when opening a universal link
Our app handles links for two formats:
- our own app scheme (i.e. "myapp://")
- universal link (via Branch), via https scheme, (i.e. "https://myapp.app.link")
When opening a regular app link ("myapp://"), the app opens normally. However when opening a Branch link, we're seeing this crash:
AndroidRuntime: FATAL EXCEPTION: main
AndroidRuntime: Process: com.myapp, PID: 10892
AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
AndroidRuntime: at com.iterable.iterableapi.IterableActionRunner$IterableActionRunnerImpl.openUri(IterableActionRunner.java:76)
AndroidRuntime: at com.iterable.iterableapi.IterableActionRunner$IterableActionRunnerImpl.executeAction(IterableActionRunner.java:43)
AndroidRuntime: at com.iterable.iterableapi.IterableActionRunner.executeAction(IterableActionRunner.java:22)
AndroidRuntime: at com.iterable.iterableapi.IterableApi.handleAppLink(IterableApi.java:835)
AndroidRuntime: at com.myapp.MainActivity.handleIntentInIterable(MainActivity.java:77)
AndroidRuntime: at com.myapp.MainActivity.onStart(MainActivity.java:27)
AndroidRuntime: at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1582)
AndroidRuntime: at android.app.Activity.performStart(Activity.java:8628)
AndroidRuntime: at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3807)
AndroidRuntime: at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:225)
AndroidRuntime: at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:205)
AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:177)
AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:98)
AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:205)
AndroidRuntime: at android.os.Looper.loop(Looper.java:294)
AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8177)
AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Here's how our links are configured:
AndroidManifest.xml, under application/activity:
<!-- Deeplinks using myapp:// scheme -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" android:host="*" />
</intent-filter>
<!-- Branch links -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="myapp.app.link" />
</intent-filter>
and how are MainActivity..onStart / MainActivity.handleIntentInIterable handler look like
...
@Override
protected void onStart() {
super.onStart();
RNBranchModule.initSession(this.getIntent().getData(), this);
handleIntentInIterable(getIntent());
}
...
private void handleIntentInIterable(Intent intent) {
if (Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getData() != null) {
IterableApi.getInstance().handleAppLink(intent.getDataString());
}
}
We're temporarily wrapping the failing statement (IterableApi.getInstance().handleAppLink(intent.getDataString());) into a try/catch block, but this is likely causing issues on our tracking.
Can you advise on what the issue might be? TIA
Some additional information:
- We're implementing Iterable SDK via react-native (using Iterable's wrapper
"@iterable/react-native-sdk": "1.3.17") - The version of the Iterable SDK that this wrapper pulls in is
com.iterable:iterableapi:3.4.16
Our Java version:
% java --version
openjdk 17.0.8.1 2023-08-24
OpenJDK Runtime Environment Homebrew (build 17.0.8.1+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.8.1+0, mixed mode, sharing)
Additional params from our build.gradle:
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 23
compileSdkVersion = 33
targetSdkVersion = 33
ndkVersion = "21.4.7075529"
kotlinVersion = "1.8.21"
}
...
}
Hi we're having the exact same issue, same stack trace.
@ Iterable: Is anyone looking into this? It's the main source of crashes in our app now. Let us know if you need more info please. The initial post is pretty detailed.
Thank you!
Hi all @flochtililoch @fabiendem Thanks for sharing these details; our team is looking into this. We will add updates to this thread.
@jena-chakour Any updates on what's happening with this issue?
Hi all, our team is still reviewing this-- will update asap with findings and next steps
Bumping again for visibility. We have also
We're temporarily wrapping the failing statement (IterableApi.getInstance().handleAppLink(intent.getDataString());) into a try/catch block, but this is likely causing issues on our tracking.
same as OP. Any updates on root cause or additional context on this issue?
Any news @jena-chakour ?
Hey all, appreciate everyone's patience while we work on this! We are reviewing a PR expected to help prevent these crashes and are still in final testing-- will update here when we have results to share
@jena-chakour Could you provide a link to the PR that resolves this issue?
Hey all, @digioak sure thing, it's this one here: https://github.com/Iterable/iterable-android-sdk/pull/706 Tl;dr, it implements a check to ensure the package manager is not null, preventing potential crashes
Hi all, please see our updated Android SDK version 3.5.1, which includes the null packageManager check intended to preclude this crash issue. Let us know your results!
Thank you @jena-chakour Is there any chance you can nudge the maintainer of the react-native SDK to update the Android dependency to the one with the fix, please? We're using Iterable via this RN wrapper. https://github.com/Iterable/react-native-sdk/issues/533
Edit: @evantk91 maybe you can help with the above please?
Thank you!