iterable-android-sdk
iterable-android-sdk copied to clipboard
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"
}
...
}