Skip to main content

SDK Unity FAQ

This FAQ addresses common issues encountered when integrating the AppTrove SDK into Unity projects for Android, focusing on compatibility with AdMob and duplicate class errors. Each issue includes detailed explanations and solutions to ensure smooth integration.


1. Why does the AppTrove SDK not work with AdMob in Unity?

Issue: The Unity package for the AppTrove SDK does not work correctly when the AdMob package is included in the project, leading to integration failures or runtime issues.

Cause: The AppTrove SDK and AdMob package may have conflicting dependencies or initialization processes, particularly related to Android libraries or plugins. This can cause issues during the build or runtime, such as failed dependency resolution or crashes.

Solution:
To resolve the conflict between the AppTrove SDK and AdMob in Unity, follow these steps:

  1. Remove the AdMob Package:
    • In the Unity Editor, go to the Package Manager (Window > Package Manager).
    • Locate and remove the AdMob package (e.g., Google Mobile Ads SDK).
  2. Add the AppTrove SDK Package:
    • Import the AppTrove SDK Unity package into your project:
      • Download the AppTrove SDK Unity package from the official Trackier documentation or repository.
      • Import it via Assets > Import Package > Custom Package in the Unity Editor.
    • Configure the AppTrove SDK as per the documentation (e.g., set up your app ID, initialize the SDK in a script).
  3. Build and Test the App:
    • Build the Android project (File > Build Settings > Android) and ensure the AppTrove SDK works correctly.
    • Test the app on a device or emulator to confirm tracking functionality (e.g., installs, events).
  4. Re-add the AdMob Package:
    • Return to the Package Manager and re-install the AdMob package.
    • Configure AdMob as needed (e.g., add your AdMob App ID, set up ad units).
  5. Resolve Android Dependencies:
    • In the Unity Editor, go to Assets > External Dependency Manager > Android Resolver > Resolve.
    • This will resolve and download the necessary Android dependencies for both Trackier and AdMob, ensuring compatibility.
  6. Test Again:
    • Rebuild the project and test the app to confirm that both Trackier and AdMob are functioning correctly.

Explanation:

  • Removing AdMob temporarily allows the AppTrove SDK to initialize and configure its dependencies without conflicts.
  • The Android Resolver ensures that the correct versions of shared dependencies (e.g., Android libraries, JARs) are included in the build, resolving potential conflicts.

Additional Tips:

  • Ensure you are using the latest versions of both the AppTrove SDK and AdMob packages, as newer releases may include fixes for compatibility issues.
  • Check the Unity Console and Android Logcat for any errors during dependency resolution or runtime.

2. Why do I encounter duplicate class errors in Unity projects with the AppTrove SDK?

Issue: The Unity project fails to build or crashes at runtime due to duplicate class errors, often related to Android libraries.

Cause: Duplicate class errors occur when multiple JAR or AAR files in the project include the same classes, typically due to conflicting dependencies between the AppTrove SDK and other plugins (e.g., AdMob, analytics SDKs). This is common when multiple plugins include overlapping versions of libraries like androidx, kotlin-stdlib, or Google Play services.

Solution:
To resolve duplicate class errors, identify and remove duplicate JAR or AAR files in the Unity project:

  1. Check for Duplicate JAR/AAR Files:
    • Navigate to the Assets/Plugins/Android folder in your Unity project.
    • Look for multiple JAR or AAR files that might contain overlapping classes (e.g., kotlin-stdlib, androidx, or Google Play services libraries).
    • Common culprits include:
      • kotlin-stdlib-<version>.jar
      • androidx.core-<version>.aar
      • play-services-<module>-<version>.aar
  2. Verify Dependency Versions:
    • Open the Assets/Plugins/Android/mainTemplate.gradle file (or create one if it doesn't exist by enabling Custom Gradle Template in Player Settings > Android > Publishing Settings).
    • Ensure that the AppTrove SDK and other plugins use compatible dependency versions. For example:
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.0' // Use the version required by AppTrove SDK
implementation 'com.google.android.gms:play-services-ads:23.0.0' // Example for AdMob
implementation 'androidx.core:core:1.12.0' // Ensure consistent androidx versions
}

  1. Delete Duplicated Files:
    • Remove older or conflicting JAR/AAR files from Assets/Plugins/Android. For example, if you find multiple versions of kotlin-stdlib (e.g., kotlin-stdlib-1.8.0.jar and kotlin-stdlib-1.9.0.jar), keep only the latest version required by the AppTrove SDK.
    • Be cautious not to delete files critical to other plugins.
  2. Force Dependency Resolution:
    • Go to Assets > External Dependency Manager > Android Resolver > Force Resolve to ensure Unity downloads the correct versions of dependencies specified in mainTemplate.gradle.
  3. Clean and Rebuild:
    • Delete the Library and Temp folders in your Unity project to clear cached build artifacts.
    • Rebuild the project (File > Build Settings > Android > Build).
  4. Enable ProGuard (Optional):
    • If duplicate classes persist in release builds, enable ProGuard to strip unused classes. Add a proguard-rules.pro file to Assets/Plugins/Android with the following rules to preserve AppTrove SDK classes:
-keep class com.trackier.sdk.** { *; }
-keep class kotlin.Metadata { *; }
-keep class kotlin.reflect.jvm.internal.** { *; }
-dontwarn kotlin.**
-dontwarn com.trackier.sdk.**

  • Enable ProGuard in Player Settings > Android > Publishing Settings > Minify > Release > ProGuard.

Explanation:

  • Duplicate classes arise when multiple plugins include their own copies of the same library, leading to conflicts during the Android build process.
  • By consolidating dependencies in mainTemplate.gradle and removing redundant JAR/AAR files, you ensure that only one version of each library is included.
  • The Android Resolver and ProGuard help manage dependencies and remove unused code, reducing the likelihood of conflicts.

Additional Tips:

  • Use the Gradle Build Tool window (File > Build Settings > Android > Open Gradle Build Tool) to inspect dependency conflicts during the build process.
  • Check the Android Logcat output for specific class names causing the duplicate class error, which can help identify the conflicting libraries.

3. How do I troubleshoot other AppTrove SDK integration issues in Unity?

General Troubleshooting Steps:

  1. Check SDK Version: Ensure you are using the latest version of the AppTrove SDK Unity package. Download it from the official Trackier documentation or repository.
  2. Verify Plugin Configuration:
    • Confirm that the AppTrove SDK is correctly configured in Unity (e.g., app ID, initialization script).
    • Check that Android-specific settings (e.g., AndroidManifest.xml) are updated as per the SDK documentation.
  3. Enable Logging: Enable debug logging in the AppTrove SDK to identify issues. Refer to the SDK's documentation for enabling verbose logs.
  4. Test in Staging:
    • Build and test the Android APK in a staging environment to replicate production conditions.
    • Use File > Build Settings > Android > Build to generate a debug or release APK.
  5. Check Android Manifest:
    • Ensure the Assets/Plugins/Android/AndroidManifest.xml file includes necessary permissions (e.g., INTERNET):
<uses-permission android:name="android.permission.INTERNET" />

  1. Resolve Dependencies:
    • Run Assets > External Dependency Manager > Android Resolver > Resolve after adding or updating plugins to ensure all dependencies are correctly included.
  2. Contact Support: If issues persist, contact AppTrove SDK support with the following details:
    • AppTrove SDK version
    • Unity version
    • AdMob or other plugin versions
    • Build error logs or stack traces
    • Contents of mainTemplate.gradle and proguard-rules.pro

Additional Resources

For further assistance, reach out to AppTrove SDK support or consult the Unity developer community.

For complete documentation, visit the Trackier Developer Portal.