Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unityLibrary:BuildIl2CppTask #570

Open
RoxDevvv opened this issue May 4, 2022 · 2 comments
Open

unityLibrary:BuildIl2CppTask #570

RoxDevvv opened this issue May 4, 2022 · 2 comments
Labels
android This issue is specific to the Android Platform. Build This issue refers to the build configuration and builds failing.

Comments

@RoxDevvv
Copy link

RoxDevvv commented May 4, 2022

Describe the bug
while trying to build in flutter

FAILURE: Build failed with an exception.

  • Where:
    Build file 'E:\Project\Flutter\auto\signlanguage\android\unityLibrary\build.gradle' line: 59

  • What went wrong:
    Execution failed for task ':unityLibrary:BuildIl2CppTask'.
    Process 'command 'E:/Project/Flutter/auto/signlanguage/android/unityLibrary/src/main/Il2CppOutputProject/IL2CPP/build/deploy/netcoreapp3.1/il2cpp.exe'' finished with non-zero exit value 4

Gardle file:

this is my gardle file :
i did not edit it , it is auto generated so i don't know why it give error


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

apply plugin: 'com.android.library'


dependencies {
    implementation(name: 'unity-classes', ext:'jar')
}

android {
    compileSdkVersion 29
    buildToolsVersion '30.0.2'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 29
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
        versionCode 2
        versionName '0.11'
        consumerProguardFiles 'proguard-unity.txt'
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress = ['.ress', '.resource', '.obb']
        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.exe",
            "--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"]
        }
    }
}



@mvn-daipham2-hn
Copy link

mvn-daipham2-hn commented May 9, 2022

You replace all content on BuildIl2Cpp function by these:

    def commandLineArgs = []
    commandLineArgs.add("--compile-cpp")
    commandLineArgs.add("--platform=Android")
    commandLineArgs.add("--architecture=" + architecture)
    commandLineArgs.add("--outputpath=" + workingDir + "/src/main/jniLibs/" + abi + "/libil2cpp.so")
    commandLineArgs.add("--libil2cpp-static")
    commandLineArgs.add("--baselib-directory=" + workingDir + "/src/main/jniStaticLibs/" + abi)
    commandLineArgs.add("--incremental-g-c-time-slice=3")
    commandLineArgs.add("--configuration=" + configuration)
    //commandLineArgs.add("--dotnetprofile=unityaot-linux")
    //commandLineArgs.add("--enable-debugger")
    //commandLineArgs.add("--profiler-report")
    //commandLineArgs.add("--profiler-output-file=" + workingDir + "/build/il2cpp_"+ abi + "_" + configuration + "/il2cpp_conv.traceevents")
    commandLineArgs.add("--print-command-line")
    commandLineArgs.add("--additional-include-directories=" + workingDir + "/src/main/Il2CppOutputProject/IL2CPP/external/bdwgc/include")
    commandLineArgs.add("--additional-include-directories=" + workingDir + "/src/main/Il2CppOutputProject/IL2CPP/libil2cpp/include")
    commandLineArgs.add("--generatedcppdir=" + workingDir + "/src/main/Il2CppOutputProject/Source/il2cppOutput")
    commandLineArgs.add("--cachedirectory=" + workingDir + "/build/il2cpp_"+ abi + "_" + configuration + "/il2cpp_cache")
    commandLineArgs.add("--tool-chain-path=" + android.ndkDirectory)
    staticLibraries.eachWithIndex {fileName, i->
        commandLineArgs.add("--additional-libraries=" + workingDir + "/src/main/jniStaticLibs/" + abi + "/" + fileName)
    }
    def executableExtension = ""
    if (org.gradle.internal.os.OperatingSystem.current().isWindows())
        executableExtension = ".exe"
    exec {
        executable workingDir + "/src/main/Il2CppOutputProject/IL2CPP/build/deploy/il2cpp" + executableExtension
        args commandLineArgs
        environment "ANDROID_SDK_ROOT", getSdkDir()
    }
    delete workingDir + "/src/main/jniLibs/" + abi + "/libil2cpp.sym.so"
    ant.move(file: workingDir + "/src/main/jniLibs/" + abi + "/libil2cpp.dbg.so", tofile: workingDir + "/symbols/" + abi + "/libil2cpp.so")

and add path to unity ndk tool in android/local.properties, example:
ndk.dir=/Applications/Unity/Hub/Editor/2021.2.13f1/PlaybackEngines/AndroidPlayer/NDK

Hope this helps. Origin solution: #544

@timbotimbo timbotimbo added android This issue is specific to the Android Platform. Build This issue refers to the build configuration and builds failing. labels Jan 8, 2023
@luzac
Copy link

luzac commented Jan 4, 2024

Try to export unity to apk first. During the process you will probably fail and get some error prompts which tell you where the problems are. Then try to export to project, just make sure android and unityLibrary refer the same ndk folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android This issue is specific to the Android Platform. Build This issue refers to the build configuration and builds failing.
Projects
None yet
Development

No branches or pull requests

4 participants