Build Gradle failed in Unity 6

I’m getting this error:

FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring project ‘:unityLibrary:eos_dependencies.androidlib’. > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl. > Namespace not specified. Specify a namespace in the module’s build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace. If you’ve specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant. * 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.

What I need to do in order to solve it?

Hi! We already have the steps to adapt the project to Unity 6. I’m sharing them here, and I’ll keep an eye out in case you run into any errors or issues.

Regarding the specific error you’re encountering, the solution is:

Unity 6 migrated to a new Gradle project generation system based on Android Gradle Plugin (AGP) 8.x, which introduces mandatory changes to how Android modules are defined.

Projects must now explicitly define a namespace, use JavaVersion.VERSION_17, and enable core library desugaring to maintain compatibility with Java 8+ APIs.

You must use custom Gradle templates to ensure the correct Android toolchain versions are applied.

launcherTemplate.gradle

    apply plugin: 'com.android.application'
    apply from: 'setupSymbols.gradle'
    apply from: '../shared/keepUnitySymbols.gradle'

    dependencies {
    implementation project(':unityLibrary')
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
    }

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

    compileSdk **APIVERSION**
    buildToolsVersion = "**BUILDTOOLS**"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
        coreLibraryDesugaringEnabled true
    }

    defaultConfig {
        minSdk **MINSDK**
        targetSdk **TARGETSDK**
        applicationId '**APPLICATIONID**'
        ndk {
            abiFilters **ABIFILTERS**
            debugSymbolLevel **DEBUGSYMBOLLEVEL**
        }
        versionCode **VERSIONCODE**
        versionName '**VERSIONNAME**'
    }

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

    lint {
        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**
        }
    }**PACKAGING****PLAY_ASSET_PACKS****SPLITS**
    **BUILT_APK_LOCATION**
    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = false
        }
        abi {
            enableSplit = true
        }
        texture {
            enableSplit = true
        }
    }

	**GOOGLE_PLAY_DEPENDENCIES**
    }**SPLITS_VERSION_CODE****LAUNCHER_SOURCE_BUILD_SETUP**

mainTemplate.gradle

    apply plugin: 'com.android.library'
    apply from: '../shared/keepUnitySymbols.gradle'
    **APPLY_PLUGINS**

    android {
    namespace "com.unity3d.player"
    ndkPath "**NDKPATH**"
    ndkVersion "**NDKVERSION**"

    compileSdk **APIVERSION**
    buildToolsVersion = "**BUILDTOOLS**"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
        coreLibraryDesugaringEnabled true
    }

    defaultConfig {
        minSdk **MINSDK**
        targetSdk **TARGETSDK**
        ndk {
            abiFilters **ABIFILTERS**
            debugSymbolLevel **DEBUGSYMBOLLEVEL**
        }
        versionCode **VERSIONCODE**
        versionName '**VERSIONNAME**'
        consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
    **DEFAULT_CONFIG_SETUP**
    }

    lint {
        abortOnError false
    }

    androidResources {
        noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ')
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~"
    }**PACKAGING**
    }
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        **DEPS**
        coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
    }
    **IL_CPP_BUILD_SETUP**
    **SOURCE_BUILD_SETUP**
    **EXTERNAL_SOURCES**

gradleTemplate.properties

    org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
    org.gradle.parallel=true
    unityStreamingAssets=**STREAMING_ASSETS**
    **ADDITIONAL_PROPERTIES**
    android.useAndroidX=true

For Unity 6, you must modify the build.gradle file located at:

<project>\Library\PackageCache\com.playeveryware.eos@b4c7aa785817\PlatformSpecificAssets~\EOS\Android\eos_dependencies.androidlib\build.gradle

This folder is automatically generated when importing the EOS package into Unity. The default Gradle configuration inside it must be replaced with the following content to ensure proper compilation and namespace compatibility in Unity 6.

build.gradle

    buildscript {
    repositories {
        google()
        mavenCentral()
        flatDir(dirs: 'libs')
    }

    dependencies {
        classpath "com.android.tools.build:gradle:7.4.2"
    }
    }

    apply plugin: 'com.android.library'
    repositories {
    google()
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
    }
    android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }
    }
    namespace 'com.pew.eos_dependencies'
    compileSdkVersion 34
    buildToolsVersion '34.0.0'
    defaultConfig {
        targetSdkVersion 34
    }
    }
    dependencies {
        implementation 'androidx.appcompat:appcompat:1.5.1'
        implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
        implementation 'androidx.security:security-crypto:1.0.0'
        implementation 'androidx.browser:browser:1.4.0'
    //api fileTree(dir: 'libs', include: ['*.aar'])
    }

If you do not define a namespace, Android Gradle Plugin 8.0+ will fail with the error: Namespace not specified. Specify a namespace in the module’s build file.

Additionally, you must edit the AndroidManifest.xml file located at:

<project>\Library\PackageCache\com.playeveryware.eos@b4c7aa785817\PlatformSpecificAssets~\EOS\Android\eos_dependencies.androidlib\AndroidManifest.xml

The manifest file contains the line , which is no longer accepted in Unity 6 due to updated Android Gradle Plugin validation rules.

You must replace its contents with the following version to ensure proper compatibility:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application
        android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    </manifest>

Let me know if this works or if you have any questions. I’m here to help!

If you encounter the following error during build:

A failure occurred while executing MergeNativeLibsTask:
2 files found with path 'lib/arm64-v8a/libc++_shared.so'

Remove the conflicting UnityHelpers_Android-debug.aar file or any duplicated .so libraries located in:

<project>\Library\PackageCache\com.playeveryware.eos@b4c7aa785817\Runtime\Android

Unity 6 now merges all native libraries automatically, so duplicated entries will cause a build failure.

This solved my problems! thank you so much!

Still working for Unity 6.3! and EOS plugin version 6.02