Cordova SDK FAQ
This FAQ addresses common issues encountered when integrating the AppTrove SDK into Cordova applications, focusing on Android compatibility, build errors, and Cordova-specific problems.
Android Compatibility Issues
Q: Why does my Cordova app crash on Android 7 due to GMS (Google Mobile Services)?
A: The app crashes on Android 7 devices with the following error:
Caused by java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/Duration;
at com.google.android.gms.ads.identifier.zzd.<clinit>(zzd.java)
at com.google.android.gms.ads.identifier.zzd.zza(zzd.java)
at com.google.android.gms.ads.identifier.AdvertisingIdClient.getAdvertisingIdInfo(AdvertisingIdClient.java)
at java.lang.reflect.Method.invoke(Method.java)
at com.trackier.sdk.DeviceInfo$Companion.getGAID(DeviceInfo.java)
at com.trackier.sdk.TrackierSDKInstance.initGaid(SourceFile)
at com.trackier.sdk.TrackierSDKInstance.access$initGaid(SourceFile)
at com.trackier.sdk.TrackierSDKInstance$initialize$1.invokeSuspend(TrackierSDKInstance.java)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:1)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.java:1)
at kotlinx.coroutines.scheduling.TaskImpl.run(TaskImpl.java:1)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:1)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:1)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:1)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:1)
Cause: This error occurs because Android 7 (API level 24) doesn't natively support the java.time.Duration
class, which was introduced in Android 8 (API level 26). The Google Mobile Services (GMS) library tries to use this class, causing a NoClassDefFoundError
.
Solution: Add the following dependency to your platforms/android/app/build.gradle
file:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
// Add this dependency:
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
}
}
dependencies {
// Add this dependency:
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
}
Explanation: The coreLibraryDesugaring
dependency provides backported versions of Java 8+ APIs (including java.time.Duration
) for older Android versions, allowing the GMS library to work properly on Android 7 devices.
Q: Why does my Cordova app fail to build with "Inconsistent JVM-target compatibility" error?
A: The build fails with the following error:
Execution failed for task ':trackier/cordova_sdk:compileDebugKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17).
Cause: This error occurs due to a mismatch between the Java and Kotlin JVM target versions. The compileDebugJavaWithJavac
task uses Java 1.8, while the compileDebugKotlin
task targets JVM 17.
Solution: Update the Android build.gradle
file to align the Java and Kotlin JVM targets to version 17:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
}
Q: Why do install and event features stop working in Cordova release builds?
A: When switching from debug to release builds with minifyEnabled
and shrinkResources
enabled, the SDK's install and event tracking features stop functioning.
Cause: ProGuard or R8 optimizations in release builds may strip or obfuscate classes required by the SDK, particularly those related to Kotlin reflection or metadata.
Solution: Add the following ProGuard rules to your platforms/android/app/proguard-rules.pro
file:
-keep class kotlin.Metadata { *; }
-keep class kotlin.reflect.jvm.internal.** { *; }
-keep class com.trackier.sdk.** { *; }
-dontwarn kotlin.**
-dontwarn com.trackier.sdk.**
Cordova Specific Issues
Q: How do I properly install the Trackier Cordova SDK?
A: Install the SDK using npm:
# Install the Trackier Cordova SDK
npm install trackier/cordova_sdk
For Ionic Native apps, additional steps are required:
# Install Awesome Cordova Plugins core
npm install @awesome-cordova-plugins/core --save
# Sync Capacitor dependencies
ionic cap sync
# Download and copy the Trackier plugin folder
# Copy the trackier folder to node_modules/@awesome-cordova-plugins/
Important: Make sure you have the latest version of Cordova CLI installed.
Q: How do I initialize the Trackier SDK in Cordova?
A: Initialize the SDK in your JavaScript code:
For Pure Cordova:
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
var key = "0455721b-XXXX-XXXXX-596d818d910a"; // Replace with your SDK key
var trackierConfig = new TrackierConfig(key, TrackierEnvironment.Development);
TrackierCordovaPlugin.initializeSDK(trackierConfig);
}
For Ionic Native:
import { Component } from '@angular/core';
import { TrackierCordovaPlugin, TrackierConfig, TrackierEnvironment } from '@awesome-cordova-plugins/trackier/ngx';
@Component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss']
})
export class Tab1Page {
constructor(private trackierCordovaPlugin: TrackierCordovaPlugin) {}
async ngOnInit() {
var key = "0455721b-XXXX-XXXXX-596d818d910a"; // Replace with your SDK key
var trackierConfig = new TrackierConfig(key, TrackierEnvironment.Development);
this.trackierCordovaPlugin.initializeSDK(trackierConfig);
}
}
Important: Always initialize the SDK after the deviceready
event is fired.
Q: Why are my events not being tracked in Cordova?
A: Common causes and solutions:
- SDK not initialized: Ensure the SDK is initialized after
deviceready
- Network permissions: Add internet permission to
platforms/android/app/src/main/AndroidManifest.xml
:<uses-permission android:name="android.permission.INTERNET" />
- ProGuard rules: Add ProGuard rules for release builds (see above)
- Wrong environment: Make sure you're using the correct environment setting
- Plugin not installed: Verify the SDK is properly installed
Q: How do I track custom events in Cordova?
A: Use the TrackierEvent
class:
For Pure Cordova:
// Track a custom event
var trackierEvent = new TrackierEvent("1CFfUn3xEY"); // Event ID from dashboard
trackierEvent.setParam1("Param 1");
trackierEvent.setParam2("Param 2");
trackierEvent.setCouponCode("TestCode");
TrackierCordovaPlugin.trackEvent(trackierEvent);
For Ionic Native:
// Track a custom event
var trackierEvent = new TrackierEvent("1CFfUn3xEY"); // Event ID from dashboard
trackierEvent.setParam1("Param 1");
trackierEvent.setParam2("Param 2");
trackierEvent.setCouponCode("TestCode");
this.trackierCordovaPlugin.trackEvent(trackierEvent);
Q: How do I track revenue events in Cordova?
A: Use the revenue
and currency
methods:
// Track revenue event
var trackierEvent = new TrackierEvent("1CFfUn3xEY");
trackierEvent.setParam1("Param 1");
trackierEvent.revenue(10.0); // Revenue amount
trackierEvent.currency("INR"); // Currency code
TrackierCordovaPlugin.trackEvent(trackierEvent);
Q: How do I pass user data to the SDK?
A: Use the user data methods:
// Set user data
TrackierCordovaPlugin.setUserId("TestUserId");
TrackierCordovaPlugin.setUserName("Test");
TrackierCordovaPlugin.setUserPhone("8130XXX721");
TrackierCordovaPlugin.setUserEmail("abc@gmail.com");
TrackierCordovaPlugin.setDOB("12/1/2022");
TrackierCordovaPlugin.setGender("Male");
// Then track event
var trackierEvent = new TrackierEvent("1CFfUn3xEY");
TrackierCordovaPlugin.trackEvent(trackierEvent);
Q: Why does my Cordova app crash on Android startup?
A: Common causes and solutions:
- Missing permissions: Ensure all required permissions are in
AndroidManifest.xml
- ProGuard issues: Add ProGuard rules for release builds
- SDK not installed: Verify the SDK is properly added to the project
- SDK not initialized: Make sure SDK is initialized after
deviceready
Solution: Add these permissions to platforms/android/app/src/main/AndroidManifest.xml
:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
Build and Configuration Issues
Q: How do I configure ProGuard for Cordova release builds?
A: Add the following rules to platforms/android/app/proguard-rules.pro
:
# Trackier SDK ProGuard rules
-keep class kotlin.Metadata { *; }
-keep class kotlin.reflect.jvm.internal.** { *; }
-keep class com.trackier.sdk.** { *; }
-dontwarn kotlin.**
-dontwarn com.trackier.sdk.**
# Cordova specific
-keep class org.apache.cordova.** { *; }
-keep class org.apache.cordova.engine.** { *; }
Q: Why does my app size increase significantly after adding the Trackier SDK?
A: The SDK includes dependencies that contribute to APK size. To minimize the increase:
-
Enable R8 optimization in
platforms/android/app/build.gradle
:android {
buildTypes {
release {
minifyEnabled true
shrinkResources true
}
}
} -
Add ProGuard rules (see above) to remove unused code
-
Use APK Analyzer in Android Studio to identify large dependencies
Q: How do I handle deep linking in Cordova with Trackier SDK?
A: Configure deep linking in your Cordova app:
-
Add URL scheme to
platforms/android/app/src/main/AndroidManifest.xml
:<activity>
<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="yourapp" />
</intent-filter>
</activity> -
Initialize deep link listener in your Cordova JavaScript code:
For Pure Cordova:
document.addEventListener('deviceready', function() {
// Initialize deep link listener
var observable = TrackierCordovaPlugin.setDeferredDeeplinkCallbackListener();
observable.subscribe(function(deepLinkUrl) {
console.log('User installed via deeplink:', deepLinkUrl);
// Handle navigation here
});
}, false);
For Ionic Native:
import { Component } from '@angular/core';
import { TrackierCordovaPlugin } from '@awesome-cordova-plugins/trackier/ngx';
@Component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss']
})
export class Tab1Page {
constructor(private trackierCordovaPlugin: TrackierCordovaPlugin) {}
async ngOnInit() {
// Initialize deep link listener
const observable = this.trackierCordovaPlugin.setDeferredDeeplinkCallbackListener();
observable.subscribe((deepLinkUrl: string) => {
console.log('User installed via deeplink:', deepLinkUrl);
// Handle navigation here
});
}
}
- Send immediate deep links :
// Handle immediate deep links
document.addEventListener('deviceready', function() {
window.handleOpenURL = function(url) {
TrackierCordovaPlugin.parseDeepLink(url);
};
}, false);
Ionic Native Specific Issues
Q: How do I register the TrackierCordovaPlugin provider for Ionic Native?
A: Add the provider to your app.module.ts
:
import { NgModule } from '@angular/core';
import { TrackierCordovaPlugin } from '@awesome-cordova-plugins/trackier/ngx';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [TrackierCordovaPlugin, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
bootstrap: [AppComponent]
})
export class AppModule {}
Q: Why is the TrackierCordovaPlugin not found in Ionic Native?
A: Common causes:
- Plugin not installed: Verify the trackier folder is in
node_modules/@awesome-cordova-plugins/
- Capacitor not synced: Run
ionic cap sync
after installation - Import path incorrect: Use the correct import path:
import { TrackierCordovaPlugin } from '@awesome-cordova-plugins/trackier/ngx';
Solution: Follow the complete installation steps for Ionic Native apps.
Troubleshooting
Q: How do I enable debug logging in Cordova?
A: Enable debug mode during SDK initialization:
var trackierConfig = new TrackierConfig(key, TrackierEnvironment.Development);
// Debug logging is automatically enabled in development environment
TrackierCordovaPlugin.initializeSDK(trackierConfig);
Q: How do I test the SDK in Cordova?
A: Testing steps:
- Use development environment for testing
- Enable debug logging (see above)
- Test on real devices (not simulators)
- Check network requests in debug console
- Verify ProGuard rules for release builds
- Test on both Android and iOS platforms
Q: What should I do if the SDK is not working?
A: Follow these troubleshooting steps:
- Check SDK installation: Verify the SDK is properly installed
- Check SDK initialization: Ensure SDK is initialized after
deviceready
- Verify permissions: Check all required permissions are added
- Test network connectivity: Ensure app can make network requests
- Check ProGuard rules: Verify rules are added for release builds
- Enable debug logging: Check console for error messages
- Test on real device: Simulators may not work properly
- Check platform-specific issues: Test on both Android and iOS
- Contact support: If issues persist, contact Trackier support
Q: How do I update the Cordova SDK?
A: Update the SDK using npm:
# Update to the latest version
npm update trackier/cordova_sdk
# Or install a specific version
npm install trackier/cordova_sdk@latest
For Ionic Native apps, also run:
ionic cap sync
Q: Why does the SDK not work on iOS?
A: Common iOS-specific issues:
- CocoaPods not installed: Install CocoaPods if not already installed
- Platform not added: Add iOS platform:
cordova platform add ios
- Build issues: Clean and rebuild the project
- Permissions: Ensure iOS permissions are properly configured
Solution: Run these commands:
# Add iOS platform if not added
cordova platform add ios
# Clean and rebuild
cordova clean
cordova build ios
Support
For additional help:
- Documentation: Visit the Trackier Developer Portal
- GitHub: Check the Cordova SDK repository
- Email Support: Contact support@trackier.com
- Community: Join our developer community for discussions