unityLibrary:mergeReleaseJavaResource Task failure when making an Android with LevelPlay dependencies

Hi, I am trying to integrate LevelPlay in my project (I followed this video for the setup: https://www.youtube.com/watch?v=sU5njx1jn8w&t=495s). I went through all the necessary steps and setup IronSource with 2 networks: UnityAds and Google AdMob. I am not 100% sure of this, but I believe the build worked before adding GooleAdMob, but now I get this error:

image

Java seems to spit out a lot of unnecessary garbage, but I think the more relevant errors are the following:

> Task :launcher:mergeReleaseJavaResource FAILED
82 actionable tasks: 8 executed, 74 up-to-date
------------------------------------------------------------------
> CommandInvokationFailure: Gradle build failed. 
> C:\Program Files\Unity\Hub\Editor\2022.3.7f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2022.3.7f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-7.2.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
------------------------------------------------------------------
> stderr[
> Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
> 
> FAILURE: Build completed with 2 failures.
> 
> 1: Task failed with an exception.
> -----------
> * What went wrong:
> Execution failed for task ':unityLibrary:mergeReleaseJavaResource'.
> > A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
>    > 2 files found with path 'META-INF/kotlinx_coroutines_core.version' from inputs:
>       - D:\DEV\Unity\Unity_ADS_Template\UnityADS_Template\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\libs\org.jetbrains.kotlinx.kotlinx-coroutines-core-1.7.1.jar
>       - D:\DEV\Unity\Unity_ADS_Template\UnityADS_Template\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\libs\org.jetbrains.kotlinx.kotlinx-coroutines-core-jvm-1.7.1.jar
>      Adding a packagingOptions block may help, please refer to
>      https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html
>      for more information
> 
> * 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.
> ==============================================================================
> 
> 2: Task failed with an exception.
> -----------
> * What went wrong:
> Execution failed for task ':launcher:mergeReleaseJavaResource'.
> > A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
>    > 2 files found with path 'META-INF/kotlinx_coroutines_core.version' from inputs:
>       - D:\DEV\Unity\Unity_ADS_Template\UnityADS_Template\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\libs\org.jetbrains.kotlinx.kotlinx-coroutines-core-1.7.1.jar
>       - D:\DEV\Unity\Unity_ADS_Template\UnityADS_Template\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\libs\org.jetbrains.kotlinx.kotlinx-coroutines-core-jvm-1.7.1.jar
>      Adding a packagingOptions block may help, please refer to
>      https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html
>      for more information
> 
> * 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.
> 

What I have tried:

  • Setting the target API Level to 32, 33, 34, and 35
  • Setting custom main gradle template (This seems to automatically delete all Android dependencies that the dependency resolver installs, which seems wrong, but the error is still there)
  • Running a “force resolve” with the Android dependency resolver tool
  • Adding “android.useAndroidX=true” and “android.enableJetifier=true” to the gradleTemplate
  • Setting a more up-to-date gradle installation in the Preferences->External Tools (particularly “gradle-7.6.3” and “gradle-8.9”

I am on Unity 2022.3.7f1.
If anyone came across this, Please do let me know how to fix it🙏

Hi,

What worked for me was to add:

packagingOptions {
               resources.pickFirsts.add('META-INF/kotlinx_coroutines_core.version')
        **PACKAGING_OPTIONS**}

to :
-the Main Gradle Template ( just after aaptOptions {…} )
-the Launcher Gradle Template ( just after buildTypes {…})

So here’s what my Main Gradle Tempate looks like:

// Android Resolver Repos Start
([rootProject] + (rootProject.subprojects as List)).each {
    ext {
        it.setProperty("android.useAndroidX", true)
        it.setProperty("android.enableJetifier", true)
    }
}
([rootProject] + (rootProject.subprojects as List)).each { project ->
    project.repositories {
        def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
        maven {
            url "https://maven.google.com"
        }
        maven {
            url "https://android-sdk.is.com/" // Assets/LevelPlay/Editor/IronSourceSDKDependencies.xml:9, Assets/LevelPlay/Editor/ISAdMobAdapterDependencies.xml:16, Assets/LevelPlay/Editor/ISUnityAdsAdapterDependencies.xml:8
        }
        maven {
            url "https://maven.google.com/" // Assets/LevelPlay/Editor/IronSourceSDKDependencies.xml:17, Assets/LevelPlay/Editor/IronSourceSDKDependencies.xml:25, Assets/LevelPlay/Editor/ISAdMobAdapterDependencies.xml:8, Assets/LevelPlay/Editor/ISUnityAdsAdapterDependencies.xml:15
        }
        mavenLocal()
        jcenter()
        mavenCentral()
    }
}
// Android Resolver Repos End
apply plugin: 'com.android.library'
**APPLY_PLUGINS**

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
    implementation 'com.google.android.gms:play-services-ads:23.0.0' // Assets/LevelPlay/Editor/ISAdMobAdapterDependencies.xml:8
    implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1' // Assets/LevelPlay/Editor/IronSourceSDKDependencies.xml:17
    implementation 'com.google.android.gms:play-services-basement:18.1.0' // Assets/LevelPlay/Editor/IronSourceSDKDependencies.xml:25
    implementation 'com.ironsource.adapters:admobadapter:4.3.43' // Assets/LevelPlay/Editor/ISAdMobAdapterDependencies.xml:16
    implementation 'com.ironsource.adapters:unityadsadapter:4.3.41' // Assets/LevelPlay/Editor/ISUnityAdsAdapterDependencies.xml:8
    implementation 'com.ironsource.sdk:mediationsdk:8.2.0' // Assets/LevelPlay/Editor/IronSourceSDKDependencies.xml:9
    implementation 'com.unity3d.ads:unity-ads:4.12.1' // Assets/LevelPlay/Editor/ISUnityAdsAdapterDependencies.xml:15
// Android Resolver Dependencies End
**DEPS**}

// Android Resolver Exclusions Start
android {
  packagingOptions {
      exclude ('/lib/armeabi/*' + '*')
      exclude ('/lib/mips/*' + '*')
      exclude ('/lib/mips64/*' + '*')
      exclude ('/lib/x86/*' + '*')
      exclude ('/lib/x86_64/*' + '*')
  }
}
// Android Resolver Exclusions End
android {
    namespace "com.unity3d.player"
    ndkPath "**NDKPATH**"
    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    defaultConfig {
        minSdkVersion **MINSDKVERSION**
        targetSdkVersion **TARGETSDKVERSION**
        ndk {
            abiFilters **ABIFILTERS**
        }
        versionCode **VERSIONCODE**
        versionName '**VERSIONNAME**'
        consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ')
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~"
    }
    
    packagingOptions {
               resources.pickFirsts.add('META-INF/kotlinx_coroutines_core.version')
        **PACKAGING_OPTIONS**}
}
**IL_CPP_BUILD_SETUP**
**SOURCE_BUILD_SETUP**
**EXTERNAL_SOURCES**

And here’s what my Launcher Gradle Tempate looks like:

apply plugin: 'com.android.application'

dependencies {
    implementation project(':unityLibrary')
    }

android {
    namespace "**NAMESPACE**"
    ndkPath "**NDKPATH**"

    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'

    packagingOptions {
               resources.pickFirsts.add('META-INF/kotlinx_coroutines_core.version')
        **PACKAGING_OPTIONS**}

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

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

    aaptOptions {
        noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ')
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~"
    }**SIGN**

    lintOptions {
        abortOnError false
    }

    buildTypes {
        debug {
            minifyEnabled **MINIFY_DEBUG**
            proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**
            jniDebuggable true
        }
        release {
            minifyEnabled **MINIFY_RELEASE**
            proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**
        }
    }
    
    packagingOptions {
               resources.pickFirsts.add('META-INF/kotlinx_coroutines_core.version')
        **PACKAGING_OPTIONS**}

    **PACKAGING_OPTIONS****PLAY_ASSET_PACKS****SPLITS**
**BUILT_APK_LOCATION**
    
    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = false
        }
        abi {
            enableSplit = true
        }
    }

}**SPLITS_VERSION_CODE****LAUNCHER_SOURCE_BUILD_SETUP**

I hope that helps!

2 Likes

That worked for some reason . I just don’t understand how the whole “dependencies” thing works. If I add a custom Main gradle template, all the Android dependencies installed by the Android resolver are deleted (and once they are deleted, the build keeps failing again). Does it mean that I need to manually add them to the template?

Do you mean something like in that topic (which I made yesterday when I had the same problem) happens?

I posted the solution in it