Skip to main content

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:

  1. SDK not initialized: Ensure the SDK is initialized before tracking events
  2. Network permissions: Add internet permission to android/app/src/main/AndroidManifest.xml:
    <uses-permission android:name="android.permission.INTERNET" />
  3. ProGuard rules: Add ProGuard rules for release builds (see above)
  4. 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:

  1. Missing permissions: Ensure all required permissions are in AndroidManifest.xml
  2. ProGuard issues: Add ProGuard rules for release builds
  3. Kotlin version conflicts: Ensure compatible Kotlin versions
  4. 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:

  1. Enable R8 optimization in android/app/build.gradle:

    android {
    buildTypes {
    release {
    minifyEnabled true
    shrinkResources true
    }
    }
    }
  2. Add ProGuard rules (see above) to remove unused code

  3. Use APK Analyzer in Android Studio to identify large dependencies



Troubleshooting


Q: How do I test the SDK in React Native?

A: Testing steps:

  1. Use development environment for testing
  2. Enable debug logging (see above)
  3. Test on real devices (not simulators)
  4. Check network requests in debug console
  5. Verify ProGuard rules for release builds

Q: What should I do if the SDK is not working?

A: Follow these troubleshooting steps:

  1. Check SDK initialization: Ensure SDK is initialized before use
  2. Verify permissions: Check all required permissions are added
  3. Test network connectivity: Ensure app can make network requests
  4. Check ProGuard rules: Verify rules are added for release builds
  5. Enable debug logging: Check console for error messages
  6. Test on real device: Simulators may not work properly
  7. Contact support: If issues persist, contact Trackier support

Support

For additional help: