I can't build Unity Android project and the error message isn't help

Hi guys, I got this error when i try to build the project. I already search in google but no luck. Please help
Thanks
This is project structure

This is build.gradle of unityLibrary

allprojects {
    buildscript {
        repositories {
            google()
        }
    }
}

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN

apply plugin: 'com.android.library'


dependencies {
    implementation 'com.google.ar:core:1.18.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation(name: 'VuforiaWrapper', ext:'aar')
}

android {
    compileSdkVersion 29
    buildToolsVersion '30.0.2'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion 28
        targetSdkVersion 29
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
        versionCode 1
        versionName '0.1'
        consumerProguardFiles 'proguard-unity.txt'
    }

    lintOptions {
        abortOnError false
    }

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

    packagingOptions {
        doNotStrip '*/armeabi-v7a/*.so'
        doNotStrip '*/arm64-v8a/*.so'
    }
}

def getSdkDir() {
    Properties local = new Properties()
    local.load(new FileInputStream("${rootDir}/local.properties"))
    return local.getProperty('sdk.dir')
}

def BuildIl2Cpp(String workingDir, String targetDirectory, String architecture, String abi, String configuration) {
    exec {
        commandLine(workingDir + "/src/main/Il2CppOutputProject/IL2CPP/build/deploy/netcoreapp3.1/il2cpp",
            "--compile-cpp",
            "--libil2cpp-static",
            "--platform=Android",
            "--architecture=" + architecture,
            "--configuration=" + configuration,
            "--outputpath=" + workingDir + targetDirectory + abi + "/libil2cpp.so",
            "--cachedirectory=" + workingDir + "/build/il2cpp_"+ abi + "_" + configuration + "/il2cpp_cache",
            "--additional-include-directories=" + workingDir + "/src/main/Il2CppOutputProject/IL2CPP/external/bdwgc/include",
            "--additional-include-directories=" + workingDir + "/src/main/Il2CppOutputProject/IL2CPP/libil2cpp/include",
            "--tool-chain-path=" + android.ndkDirectory,
            "--map-file-parser=" + workingDir + "/src/main/Il2CppOutputProject/IL2CPP/MapFileParser/MapFileParser.exe",
            "--generatedcppdir=" + workingDir + "/src/main/Il2CppOutputProject/Source/il2cppOutput",
            "--baselib-directory=" + workingDir + "/src/main/jniStaticLibs/" + abi,
            "--dotnetprofile=unityaot")
        environment "ANDROID_SDK_ROOT", getSdkDir()
    }
    delete workingDir + targetDirectory + abi + "/libil2cpp.sym.so"
    ant.move(file: workingDir + targetDirectory + abi + "/libil2cpp.dbg.so", tofile: workingDir + "/symbols/" + abi + "/libil2cpp.so")
}

android {
    task BuildIl2CppTask {
        doLast {
              BuildIl2Cpp(projectDir.toString().replaceAll('\\\\', '/'), '/src/main/jniLibs/', 'ARMv7', 'armeabi-v7a', 'Release');
              BuildIl2Cpp(projectDir.toString().replaceAll('\\\\', '/'), '/src/main/jniLibs/', 'ARM64', 'arm64-v8a', 'Release');
        }
    }
    afterEvaluate {
        if (project(':unityLibrary').tasks.findByName('mergeDebugJniLibFolders'))
            project(':unityLibrary').mergeDebugJniLibFolders.dependsOn BuildIl2CppTask
        if (project(':unityLibrary').tasks.findByName('mergeReleaseJniLibFolders'))
            project(':unityLibrary').mergeReleaseJniLibFolders.dependsOn BuildIl2CppTask
    }
    sourceSets {
        main {
            jni.srcDirs = ["src/main/Il2CppOutputProject"]
        }
    }
}

This is local.properties

This is the error

  commandLine(workingDir + "/src/main/Il2CppOutputProject/IL2CPP/build/deploy/netcoreapp3.1/il2cpp",

looks incorrect, since you’re on Windows, it should be il2cpp.exe. Did you export this project from OSX by any chance?

1 Like

@PanithanK Is there a reason you are trying to build in Android Studio vs within Unity? Does Build and Run from Unity work OK?

1 Like

Yes this project was exported from OSX. Is there any config to check on unity if i need to export for window 10?

Unity can build into device successfully and the reason I need it as Android project because I have to make it as a module to be plugin to another Android project.

No, sadly there’s not, try manually adding .exe extension

Now I have this error
"
CreateProcess error=216, This version of %1 is not compatible with the version of Windows you’re running. Check your computer’s system information and then contact the software publisher

"

Hmph

I guess, that only means, export from Mac is not supported on Windows. You need to export gradle project from Windows, if you’re opening it on Windows

Does a new/empty project work as expected?

This happens when you are trying to link unity as a library with unity’s il2cpp project.

For me it worked using 2 things, using the ndk from unity in local.properties

ndk.dir=/Applications/Unity/Hub/Editor/2020.3.0f1/PlaybackEngines/AndroidPlayer/NDK

Commenting out the jni.srcDirs in unitylibrary.gradle

 sourceSets {
        main {
//            jni.srcDirs = ["src/main/Il2CppOutputProject"]
        }
    }