I'm working on adding Firebase Dynamic Links to my application. I've created a native module, which is available here: Titanium Firebase DynamicLinks. The core method of this module is handleDeepLink()
:
@Kroll.method
public void handleDeepLink() {
Activity currentActivity = TiApplication.getAppRootOrCurrentActivity();
Intent intent = currentActivity.getIntent();
if (intent == null) {
return;
}
Log.w(LCAT, "Links instance not null: " + (FirebaseDynamicLinks.getInstance() != null));
Log.w(LCAT, "current activity not null: " + (currentActivity != null));
FirebaseDynamicLinks.getInstance()
.getDynamicLink(intent)
.addOnSuccessListener(currentActivity, new OnSuccessListener<PendingDynamicLinkData>() {
@Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
KrollDict queryParams = new KrollDict();
Set<String> queryParamNames = deepLink.getQueryParameterNames();
for (String paramName : queryParamNames) {
queryParams.put(paramName, deepLink.getQueryParameter(paramName));
}
fireEvent("deeplink:new", queryParams);
}
}
})
.addOnFailureListener(currentActivity, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
fireEvent("deeplink:error", e.getMessage());
}
});
}
I've added it to my demo Alloy application and used it in the following way:
$.index.addEventListener('open', () => {
const Firebase = require('com.pmitkowski.firebase.dynamiclinks');
Firebase.addEventListener('deeplink:new', (params) => {
console.warn('deep link params', params);
});
Firebase.addEventListener('deeplink:error', (error) => {
console.error(error);
});
Firebase.handleDeepLink();
});
$.index.open();
My index.xml
file:
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick">Hello, World</Label>
</Window>
</Alloy>
The problem is that every time I run my app on Android emulator, I get an error:
[ERROR] V8Exception: Exception occurred at /alloy/controllers/index.js:74: Uncaught Error: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.firebase.dynamiclinks.FirebaseDynamicLinks.getDynamicLink(android.content.Intent)' on a null object reference
The FirebaseDynamicLinks.getInstance()
method in my module, in fact, returns null
, but it's not the way how it should work and I have no idea, why it happens. I'm sure that Firebase initializes itself before this method is called (I can see it in logs). Can you help me with solving this issue?
I'm not sure, how to solve this problem with SDK version 8.3.1, but when I switched to 9.0.0 and imported Firebase Dynamic Links dependency through Gradle instead of using plain .aar and .jar dependencies, it started working properly.