Proguard Rule
Proguard is a tool used in Android release builds to optimize, shrink, and obfuscate code, reducing app size and enhancing security. To ensure the AppTrove React Native SDK and its dependencies function correctly when Proguard is enabled, specific rules must be added to prevent critical classes and methods from being removed or renamed. This section outlines how to configure Proguard rules for your Android app.
Prerequisites
- AppTrove React Native SDK installed and initialized in your project
- A Trackier MMP account with access to the Trackier Panel
- React Native 0.60 or later
- Android API 21 (Android 5.0) or later
- Proguard enabled for release builds in your Android project
- Basic knowledge of Android build configurations and Proguard
Configure Proguard Rules
To maintain the functionality of the AppTrove SDK and its dependencies in optimized builds, add the required Proguard rules to your project's Proguard configuration file.
Step 1: Add Proguard Rules
- Locate or create the Proguard configuration file in your Android project, typically at
android/app/proguard-rules.pro. - Add the following rules to preserve AppTrove SDK classes and dependencies:
-keep class com.trackier.sdk.** { *; }
-keep class com.google.android.gms.common.ConnectionResult {
int SUCCESS;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {
com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
java.lang.String getId();
boolean isLimitAdTrackingEnabled();
}
-keep public class com.android.installreferrer.** { *; }
-keep class kotlin.Metadata { *; }
-keep class kotlin.reflect.jvm.internal.** { *; }
-keep class kotlin.** { *; }
-dontwarn kotlin.**
Step 2: Enable Proguard in Android Build
- Open the
android/app/build.gradlefile in your React Native project. - Ensure Proguard is enabled for release builds by verifying or adding the following configuration in the
buildTypessection:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Step 3: Test the Release Build
- Build the Android release APK using the following command in the project root directory:
cd android && ./gradlew assembleRelease
- Install the APK on a device or emulator.
- Test AppTrove SDK features (e.g., event tracking, deep linking) to ensure they function correctly in the optimized build.
Expected Outcome
The AppTrove SDK and its dependencies will remain fully functional in the optimized release build, with no critical classes or methods removed by Proguard. Tracking data will continue to be sent to the Trackier MMP without issues, verifiable in the Trackier Panel.