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 error, sudden problem #631

Closed
rmib200 opened this issue Jun 19, 2022 · 5 comments
Closed

unityLibrary:BuildIl2CppTask error, sudden problem #631

rmib200 opened this issue Jun 19, 2022 · 5 comments

Comments

@rmib200
Copy link

rmib200 commented Jun 19, 2022

Describe the bug

Until today everything was compiling, but now when I tried to build the same project I got this error message. All I did was go to Export Android insider the Flutter bar in Unity and haven't touch anything else.

Build file 'D:\Desktop2\Neurode\flutter-unity-view-widget-master\flutter-unity-view-widget-master\example\android\unityLibrary\build.gradle' line: 78

  • What went wrong:
    Execution failed for task ':unityLibrary:BuildIl2CppTask'.

Process 'command 'D:/Desktop2/Neurode/flutter-unity-view-widget-master/flutter-unity-view-widget-master/example/android/unityLibrary/src/main/Il2CppOutputProject/IL2CPP/build/deploy/il2cpp.exe'' finished with non-zero exit value 4

This is my gradle file, that seems to be autogenerated:

// 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 30
    buildToolsVersion '30.0.2'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion 22
        targetSdkVersion 30
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
        }
        versionCode 1
        versionName '0.1'
        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'
        doNotStrip '*/x86/*.so'
        doNotStrip '*/x86_64/*.so'
    }
}

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

def BuildIl2Cpp(String workingDir, String configuration, String architecture, String abi, String[] staticLibraries) {
    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("--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")
}

android {
    task BuildIl2CppTask {
        doLast {
              BuildIl2Cpp(projectDir.toString().replaceAll('\\\\', '/'), 'Release', 'armv7', 'armeabi-v7a', [  ] as String[]);
              BuildIl2Cpp(projectDir.toString().replaceAll('\\\\', '/'), 'Release', 'arm64', 'arm64-v8a', [  ] as String[]);
              BuildIl2Cpp(projectDir.toString().replaceAll('\\\\', '/'), 'Release', 'x86', 'x86', [  ] as String[]);
              BuildIl2Cpp(projectDir.toString().replaceAll('\\\\', '/'), 'Release', 'x64', 'x86_64', [  ] as String[]);
        }
    }
    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"]
        }
    }
}

Please, I would appreciate any help in this matter. Maybe I'm doing something wrong inside Unity? I got this warning in the Unity console:

File C:\Users\MSI.android\repositories.cfg could not be loaded.
UnityEditor.BuildPipeline:BuildPlayer (UnityEditor.BuildPlayerOptions)
FlutterUnityIntegration.Editor.Build:DoBuildAndroid (string,bool) (at Assets/FlutterUnityIntegration/Editor/Build.cs:156)
FlutterUnityIntegration.Editor.Build:DoBuildAndroidLibrary () (at Assets/FlutterUnityIntegration/Editor/Build.cs:33)

Expected behavior
Compile apk without the error, like it just to do.

Screenshots
If applicable, add screenshots to help explain your problem.

Unity (please complete the following information):

  • OS: Windows
  • Version 2022.1.0f1

Smartphone (please complete the following information):

  • Device: Techno Spark
  • OS: Android
  • Version 10

Additional context
Add any other context about the problem here.

@jamesncl
Copy link

Is this a duplicate of your other issue 629 or is this a separate issue?

@timbotimbo
Copy link
Collaborator

I just noticed a build error ending with the same lines you mentioned:

FAILURE: Build failed with an exception.

* Where:
Build file 'E:\Projects\################\android\unityLibrary\build.gradle' line: 78
* What went wrong:
Execution failed for task ':unityLibrary:BuildIl2CppTask'.
> Process 'command 'E:/Projects/####################/android/unityLibrary/src/main/Il2CppOutputProject/IL2CPP/build/deploy/il2cpp.exe'' finished with non-zero exit value 4

In my case I forgot adding the Unity ndk to android/local.properties.
ndk.dir=C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.5f1\\Editor\\Data\\PlaybackEngines\\AndroidPlayer\\NDK

It's possible that different Il2Cpp build issues result in the same exit code, but its worth a try.

@rmib200
Copy link
Author

rmib200 commented Jul 3, 2022

Removing these lines inside Location: android/unityLibrary/build.gradle solved the issue

Remove these lines

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")

@rmib200 rmib200 closed this as completed Jul 3, 2022
@satyatechno
Copy link

@rmib200
my build.gradle file is that what I do for same issue with my app
`// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN

apply plugin: 'com.android.library'

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}

android {
compileSdkVersion 30
buildToolsVersion '30.0.2'

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
    minSdkVersion 19
    targetSdkVersion 30
    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.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"]
}
}
}

`

@UnityExpert
Copy link

Removing these lines inside Location: android/unityLibrary/build.gradle solved the issue

Remove these lines

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")

I tried same thing removed these in unityLibrary/build.gradle but still face same error

Execution failed for task ':unityLibrary:BuildIl2CppTask'.

Process 'command 'D:/games/flutter-unity-view-widget-master/example/android/unityLibrary/src/main/Il2CppOutputProject/IL2CPP/build/deploy/il2cpp.exe'' finished with non-zero exit value 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants