ProGuard Rules
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 Android 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.
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
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
app/build.gradle
file in your Android project. - Ensure ProGuard is enabled for release builds by verifying or adding the following configuration in the
buildTypes
section:
android {
// ... other configurations
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:
./gradlew assembleRelease
- Install the APK on a device or emulator.
- Test AppTrove SDK features (e.g., event tracking, campaign data retrieval) 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.
Best Practices
- Test ProGuard Rules: Build and test the release APK with ProGuard enabled in a development environment to verify SDK functionality before deploying to production.
- Backup ProGuard Files: Commit
proguard-rules.pro
to version control to track changes and ensure consistency across builds. - Monitor Build Logs: Check Android build logs for ProGuard-related warnings or errors that may affect the SDK.
- Use Default ProGuard Files: Include the default
proguard-android-optimize.txt
file inbuild.gradle
to leverage Android's standard optimizations alongside Trackier's rules. - Validate SDK Functionality: After applying ProGuard rules, test key SDK features like event tracking and campaign data retrieval to confirm they work as expected.
- Keep Rules Updated: Check for updates to AppTrove SDK ProGuard rules in the Trackier Documentation Portal as new SDK versions are released.
Troubleshooting
Common Issues
SDK Features Not Working in Release Build:
- Confirm all required ProGuard rules are added to
proguard-rules.pro
without modifications. - Check build logs for warnings about missing classes or methods related to
com.trackier.sdk
, Google Play Services, or Install Referrer. - Temporarily set
minifyEnabled false
inbuild.gradle
to isolate ProGuard-related issues.
Build Errors with ProGuard:
- Verify the syntax of the ProGuard rules in
proguard-rules.pro
for typos or formatting errors. - Ensure the
proguardFiles
line inbuild.gradle
correctly referencesproguard-rules.pro
.
Tracking Data Not Appearing in Trackier Panel:
- Test the release APK to ensure the SDK is initialized and tracking events correctly.
- Confirm the app token and environment match the Trackier Panel configuration.
Kotlin Reflection Issues:
- Ensure all Kotlin-related ProGuard rules are included.
- Check for conflicts with other libraries that may use Kotlin reflection.
Retrofit/Moshi Issues:
- Add the Retrofit and Moshi rules if your app uses these libraries.
- Check for any custom serialization that might be affected by ProGuard.
For further assistance, refer to the Trackier Documentation Portal or contact Trackier support at support@trackier.com.