AppsFlyerSDK / appsflyer-oaid

AppsFlyer OAID collection
https://support.appsflyer.com/hc/en-us/articles/360006278797-Implementing-OAID-in-the-Android-SDK
MIT License
27 stars 3 forks source link

Implementation within Unity Project #17

Open martingoldschmid opened 3 years ago

martingoldschmid commented 3 years ago

Hey guys,

I'm trying to integrate the OAID collection to my Unity game project "Mirages of Winter" appsflyer account: martingoldschmid@mirarigames.com

Issue: The build process get stuck at the end during or right after "unity build failure android task transform Classes DexBuilder Release UP-TO-DATE"

Here's my setup:

  1. I can build an .apk in Unity just fine without the oaid_sdk_1.0.23.aar (last version downloaded today 12/18/2020) that I integrated in the unity project folder: assets>plugins>android

  2. The min android api level is 21, Unity version 2018.3.11f1

  3. The added dependencies in the .gradle may be the problem since I'm not experienced with it, I tried every combinaison that I could think of relating the 3 depedencies that were suggested in the tutorial:

    implementation 'com.appsflyer:af-android-sdk:5.4.3@aar'
    implementation 'com.appsflyer:oaid:6.1.1'
    implementation files('libs/oaid_sdk_1.0.23.aar')
  4. Here's the .gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
**BUILD_SCRIPT_DEPS**}
}

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

// Android Resolver Repos Start
([rootProject] + (rootProject.subprojects as List)).each { project ->
    project.repositories {
        def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
        maven {
            url "https://maven.google.com"
        }
        mavenLocal()
        jcenter()
        mavenCentral()
    }
}
// Android Resolver Repos End
apply plugin: 'com.android.application'
**APPLY_PLUGINS**

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
    implementation 'com.android.installreferrer:installreferrer:2.1' // Assets/AppsFlyer/Editor/AppsFlyerDependencies.xml:10
    implementation 'com.appsflyer:af-android-sdk:6.1.0' // Assets/AppsFlyer/Editor/AppsFlyerDependencies.xml:6
    implementation 'com.appsflyer:unity-wrapper:6.1.1' // Assets/AppsFlyer/Editor/AppsFlyerDependencies.xml:8
    implementation files('libs/oaid_sdk_1.0.23.aar')
    implementation 'com.appsflyer:af-android-sdk:6.1.0@aar'
    implementation 'com.appsflyer:oaid:6.1.2'
// Android Resolver Dependencies End
**DEPS**}

// Android Resolver Exclusions Start
android {
  packagingOptions {
      exclude ('/lib/armeabi/*' + '*')
      exclude ('/lib/armeabi-v7a/*' + '*')
      exclude ('/lib/mips/*' + '*')
      exclude ('/lib/mips64/*' + '*')
      exclude ('/lib/x86/*' + '*')
      exclude ('/lib/x86_64/*' + '*')
  }
}
// Android Resolver Exclusions End
android {
    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion **MINSDKVERSION**
        targetSdkVersion **TARGETSDKVERSION**
        applicationId '**APPLICATIONID**'
        ndk {
            abiFilters **ABIFILTERS**
        }
        versionCode **VERSIONCODE**
        versionName '**VERSIONNAME**'
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress = ['.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**]
    }**SIGN**

    buildTypes {
        debug {
            minifyEnabled **MINIFY_DEBUG**
            useProguard **PROGUARD_DEBUG**
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
            jniDebuggable true
        }
        release {
            minifyEnabled **MINIFY_RELEASE**
            useProguard **PROGUARD_RELEASE**
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD****SIGNCONFIG**
        }
    }**PACKAGING_OPTIONS****SPLITS**
**BUILT_APK_LOCATION**
    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = false
        }
        abi {
            enableSplit = true
        }
    }
}**SPLITS_VERSION_CODE****REPOSITORIES****SOURCE_BUILD_SETUP**

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
}
  1. Here's the ERROR in UNITY CONSOLE:

CommandInvokationFailure: Gradle build failed. C:\Program Files\Unity2018.3\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath "C:\Program Files\Unity2018.3\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

stderr[ D8: Program type already present: com.android.billingclient.BuildConfig

FAILURE: Build failed with an exception.

What went wrong:

Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForRelease'. > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\0.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\1.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\2.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\3.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\4.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\5.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\6.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\7.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\8.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\9.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\10.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\11.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\12.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\13.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\14.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\15.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\16.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\17.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\18.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\19.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\20.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\21.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\22.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\23.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\24.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\25.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\26.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\27.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\28.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\29.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\32.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\40.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\42.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\43.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\44.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\45.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\46.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\47.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\48.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\49.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\50.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\51.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\52.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\53.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\54.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\55.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\56.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\57.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\58.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\59.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\60.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\61.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\62.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\63.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\64.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\65.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\66.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\67.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\68.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\69.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\70.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\71.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\72.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\73.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\74.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\75.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\76.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\77.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\78.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\79.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\80.jar, C:\Users\marti_000\Documents\GitHub\Mirages-Tactile\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\81.jar Program type already present: com.android.billingclient.BuildConfig Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 21s ] stdout[ Observed package id 'tools' in inconsistent location 'C:\Users\marti_000\AppData\Local\Android\Sdk\tools_new' (Expected 'C:\Users\marti_000\AppData\Local\Android\Sdk\tools') Already observed package id 'tools' in 'C:\Users\marti_000\AppData\Local\Android\Sdk\tools'. Skipping duplicate at 'C:\Users\marti_000\AppData\Local\Android\Sdk\tools_new' :checkReleaseClasspath :preBuild UP-TO-DATE :preReleaseBuild UP-TO-DATE :compileReleaseAidl NO-SOURCE :compileReleaseRenderscript :checkReleaseManifest UP-TO-DATE :generateReleaseBuildConfig UP-TO-DATE :prepareLintJar UP-TO-DATE :mainApkListPersistenceRelease UP-TO-DATE :generateReleaseResValues UP-TO-DATE :generateReleaseResources :mergeReleaseResources UP-TO-DATE :createReleaseCompatibleScreenManifests UP-TO-DATE :processReleaseManifest :splitsDiscoveryTaskRelease UP-TO-DATE :processReleaseResources :generateReleaseSources :javaPreCompileRelease :compileReleaseJavaWithJavac :compileReleaseNdk NO-SOURCE :compileReleaseSources :lintVitalRelease :mergeReleaseShaders UP-TO-DATE :compileReleaseShaders UP-TO-DATE :generateReleaseAssets UP-TO-DATE :mergeReleaseAssets :transformClassesWithDexBuilderForRelease UP-TO-DATE :transformDexArchiveWithExternalLibsDexMergerForRelease FAILED 21 actionable tasks: 9 executed, 12 up-to-date ] exit code: 1 UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0) UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0) UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0) UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at :0) UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at :0) Rethrow as GradleInvokationException: Gradle build failed UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at :0) UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0) UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

af-fess commented 3 years ago

We will try to reproduce this problem on our end.

afdima commented 3 years ago

It looks like the error is Program type already present: com.android.billingclient.BuildConfig

afdima commented 3 years ago

This library could be included twice, does not look like the AppsFlyer problem.

wesfieldj commented 3 years ago

@martingoldschmid we tried to reproduce the issue and we were not able to. Try to remove the extra dependencies. There is no need to add the dependencies in build.gradle. They are added automatically.

The only action required is to add oaid_sdk_1.9.23.aar to assets > plugins > android

martingoldschmid commented 3 years ago

Thank you guys for your help,

I got confused because the tutorial and the documentation seemed to recommend to add these depedencies,

If this is done automatically in the build I won't worry about it and it should compile.

Link of the tutorial: https://support.appsflyer.com/hc/en-us/articles/360006278797-Android-OAID-implementation-in-the-SDK#supported-devices

Add OAID dependencies; they must support the manufacturer's standalone JAR file in the app-level build.gradle file:

implementation 'com.appsflyer:af-android-sdk:5.4.3@aar'
implementation 'com.appsflyer:oaid:6.1.1'
implementation files('libs/oaid_sdk_1.0.23.aar')