React Native SDK FAQ
This FAQ addresses common issues encountered when integrating the AppTrove SDK into React Native applications, focusing on Android compatibility, build errors, and React Native-specific problems.
Android Compatibility Issues
Q: Why does my React Native 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 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 React Native app fail to build with "Inconsistent JVM-target compatibility" error?
A: The build fails with the following error:
Execution failed for task ':react-native-trackier: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 React Native 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 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.**
React Native Specific Issues
Q: How do I properly initialize the Trackier SDK in React Native?
A: Initialize the SDK in your main App component or index.js:
import TrackierSDK from 'react-native-trackier';
// Initialize the SDK
TrackierSDK.initialize({
sdkKey: 'YOUR_SDK_KEY',
environment: 'development', // or 'production'
appSecret: {
secretId: 'YOUR_SECRET_ID',
secretKey: 'YOUR_SECRET_KEY'
}
});
Important: Make sure to initialize the SDK before calling any tracking methods.
Q: Why are my events not being tracked in React Native?
A: Common causes and solutions:
- SDK not initialized: Ensure the SDK is initialized before tracking events
- Network permissions: Add internet permission to
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
Q: How do I get campaign data in React Native?
A: Use the available getter methods:
import TrackierSDK from 'react-native-trackier';
// Get campaign data
const campaignData = await TrackierSDK.getCampaignData();
console.log('Campaign:', campaignData.campaign);
console.log('Ad:', campaignData.ad);
console.log('Channel:', campaignData.channel);
Note: Campaign data is only available if the user came through a Trackier tracking link.
Q: Why does my React Native 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
- Kotlin version conflicts: Ensure compatible Kotlin versions
- Native module linking: Run
npx react-native link
if needed
Solution: Add these permissions to 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 React Native release builds?
A: Add the following rules to 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.**
# React Native specific
-keep class com.facebook.react.** { *; }
-keep class com.facebook.hermes.** { *; }
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
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
Troubleshooting
Q: How do I test the SDK in React Native?
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
Q: What should I do if the SDK is not working?
A: Follow these troubleshooting steps:
- Check SDK initialization: Ensure SDK is initialized before use
- 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
- Contact support: If issues persist, contact Trackier support
Support
For additional help:
- Documentation: Visit the Trackier Developer Portal
- GitHub: Check the React Native SDK repository
- Email Support: Contact support@trackier.com
- Community: Join our developer community for discussions