juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.09k stars 506 forks source link

Execution failed for task ':unityLibrary:BuildIl2CppTask'. #440

Open joel-guti opened 2 years ago

joel-guti commented 2 years ago

Following all steps, when I try to compile from Flutter to a real Android device, I´m getting this error:


Total compilation time: 455873 milliseconds.
Error: Unity.IL2CPP.Building.BuilderFailedException: /Users/joel/Library/Android/sdk/ndk/23.0.7530507/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ @"/var/folders/n7/qdccy_41471d67w873834dtr0000gn/T/tmp48FuhM.tmp" -o "/Users/joel/Desktop/UNITY_FLUTTER/flutter_application_1/android/unityLibrary/build/il2cpp_armeabi-v7a_Release/il2cpp_cache/linkresult_957C279CD3368175BD29C9A69FA3072A/libil2cpp.so" -shared -Wl,-soname,libil2cpp.so -Wl,--no-undefined -Wl,-z,noexecstack -Wl,--gc-sections -Wl,--build-id -stdlib=libc++ -static-libstdc++ -target armv7-linux-androideabi19 -Wl,--wrap,sigaction "/Users/joel/Desktop/UNITY_FLUTTER/flutter_application_1/android/unityLibrary/src/main/jniStaticLibs/armeabi-v7a/baselib.a" -llog -rdynamic -fuse-ld=gold
clang-12: error: invalid linker name in argument '-fuse-ld=gold'
   at Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles(HashSet`1 objectFiles, CppToolChainContext toolChainContext) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.Building/CppProgramBuilder.cs:line 363
   at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.Building/CppProgramBuilder.cs:line 160
   at il2cpp.Compilation.CompilationDriver.Run(RuntimePlatform platform, BuildingOptions buildingOptions, ReadOnlyCollection`1 matchedAssemblyMethodSourceFiles) in /Users/bokken/build/output/unity/il2cpp/il2cpp/Compilation/CompilationDriver.cs:line 65
   at il2cpp.Program.DoRun(String[] args, RuntimePlatform platform, BuildingOptions buildingOptions, Boolean throwExceptions) in /Users/bokken/build/output/unity/il2cpp/il2cpp/Program.cs:line 74

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/joel/Desktop/UNITY_FLUTTER/flutter_application_1/android/unityLibrary/build.gradle' line: 52

* What went wrong:
Execution failed for task ':unityLibrary:BuildIl2CppTask'.
> Process 'command '/Users/joel/Desktop/UNITY_FLUTTER/flutter_application_1/android/unityLibrary/src/main/Il2CppOutputProject/IL2CPP/build/deploy/netcoreapp3.1/il2cpp'' finished with non-zero exit value 4

* 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

BUILD FAILED in 7m 56s
Exception: Gradle task assembleDebug failed with exit code 1

I´m getting the same result using Mac OS with Catalina and tested as well in Mac Os with Big Sur.

I have NDK installed, and I have disabled the mac security with: sudo spctl --master-disable

Nothing works.

Unity (please complete the following information):

Smartphone (please complete the following information):

samueltenoriosis commented 2 years ago

same error, any solution?

roberto-donext commented 2 years ago

I found a solution that works for me. Looks that you can download a ndk version, but, Unity, by default is using it own version. Check in Unity , Preferences / External Tools . Here you can find Android NDK installed with Unity. The solution for me was, download NDK 19 from https://developer.android.com/ndk/downloads/older_releases Go to the folder where Unity is using NDK, for example : /Applications/Unity/Hub/Editor/2020.3.15f2/PlaybackEngines/AndroidPlayer/NDK Delete this content and replace with the new NDK downloaded. Unity looks that only accept NDK version 19.0.5232133, so you can open the file source.properties in the new NDK folder and change the pkg.version with the accepted one: Pkg.Revision = 19.0.5232133 Rememeber that you need to have the same version of NDK in two files more: First on Android/local.properties: ndk.dir=/Applications/Unity/Hub/Editor/2020.3.15f2/PlaybackEngines/AndroidPlayer/NDK for example and on android/app/build.gradle: ndkVersion "19.0.5232133"

With all this, I can compile for Android. Hope this helps

TaiTrien commented 2 years ago

Hi guys, I just fixed this problem by changing the version of NDK from 23 -> 19. You can find the version in Android Studio, choose Tools. -> SDK Manager -> Android SDK -> select SKD Tools tab -> click on Show package details checkbox -> then change the version of NDK. Good luck

CodeMinion commented 2 years ago

Hello folks,

I faced the same situation using Unity version 2021.1.12f1. I downgraded to NDK 19 and did not work.

Upon further investigation it seems this is related to a mismatch of the Unity NDK version and the version installed with Android Studio, once the two version matched I was able to build fine.

Steps:

  1. Go to the location of Unity's NDK. In my case it was under /Applications/Unity/Hub/Editor/2020.3.15f2/PlaybackEngines/AndroidPlayer/NDK like in @roberto-donext case. Your location may vary based on OS.
  2. Open the source.properties file and look for the NDK version used, for example Pkg.Revision = 21.3.6528147
  3. Go to Android Studio and under the SDK manager download the same NDK version unity is using. (Don't forget to check "Show package details" to see a list of all NDK versions.
  4. Once the download is complete go to unityLibrary/build.gradle and configure that version inside the top android { }. For example ndkVersion "21.3.6528147"
  5. Build

Hope this helps,

novavision commented 2 years ago

I followed the steps @CodeMinion mentioned, and moved from that error to another :)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:stripReleaseDebugSymbols'.
> No toolchains found in the NDK toolchains folder for ABI with prefix: arm-linux-androideabi

* 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

BUILD FAILED in 1m 15s
Running Gradle task 'assembleRelease'...                           81.7s
Gradle task assembleRelease failed with exit code 1
Process finished with exit code 1

Googling that issue I found that it may relate to build tools. But.. I can't get what exactly is wrong here. image and build.gradle options seems correct

android {
    ndkVersion '19.0.5232133'
    compileSdkVersion 30
    buildToolsVersion '30.0.0'

UPDATE Hope this will help someone - in my case looks like ndkVersion '19.0.5232133' was just ignored and removing all the rest NDK I had in AndroidStudio helped to solve the problem. Also, by some reason, I couldn't compile Flutter app using min API level 30 and target API level 30. Setting min API level to 28 and target API level to 30 worked fine.

DawidPietrykowski commented 2 years ago

To anyone still facing this issue, in my case it was a flutter error. Currently the flutter snap package seems broken and installing it manually fixed the issue for me.

jugbeep commented 2 years ago

I found a solution that works for me. Looks that you can download a ndk version, but, Unity, by default is using it own version. Check in Unity , Preferences / External Tools . Here you can find Android NDK installed with Unity. The solution for me was, download NDK 19 from https://developer.android.com/ndk/downloads/older_releases Go to the folder where Unity is using NDK, for example : /Applications/Unity/Hub/Editor/2020.3.15f2/PlaybackEngines/AndroidPlayer/NDK Delete this content and replace with the new NDK downloaded. Unity looks that only accept NDK version 19.0.5232133, so you can open the file source.properties in the new NDK folder and change the pkg.version with the accepted one: Pkg.Revision = 19.0.5232133 Rememeber that you need to have the same version of NDK in two files more: First on Android/local.properties: ndk.dir=/Applications/Unity/Hub/Editor/2020.3.15f2/PlaybackEngines/AndroidPlayer/NDK for example and on android/app/build.gradle: ndkVersion "19.0.5232133"

With all this, I can compile for Android. Hope this helps

I ensured the NDK referenced in my Flutter project's 'local.properties' file was pointing to the same NDK version used in Unity, and that solved it for me.

ProEthan commented 2 years ago

I found a solution that works for me. Delete the unityLibrary folder in Android Project and re-copy-paste from Unity;

veerarama commented 2 years ago

Hi, I tries all the above mentioned methods for this issue, none of them worked. Any more ideas ?

arshad-dqot commented 1 year ago

Open your unity project go to Edit->Preferences->ExternalTool and copy NDK path, Now open your flutter project local.properties and paste that path at ndk.dir

like this - ndk.dir=C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.9f1\\Editor\\Data\\PlaybackEngines\\AndroidPlayer\\NDK

sailinhtut commented 1 year ago

Open your unity project go to Edit->Preferences->ExternalTool and copy NDK path, Now open your flutter project local.properties and paste that path at ndk.dir

like this - ndk.dir=C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.9f1\\Editor\\Data\\PlaybackEngines\\AndroidPlayer\\NDK

This work for me directly. Thank @arshad-dqot .

Velek commented 1 year ago

On March 29, 2023 2:01:28 AM PDT, Sai Lin Htut @.***> wrote:

Open your unity project go to Edit->Preferences->ExternalTool and copy NDK path, Now open your flutter project local.properties and paste that path at ndk.dir

like this - ndk.dir=C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.9f1\\Editor\\Data\\PlaybackEngines\\AndroidPlayer\\NDK

This work for me directly. Thank @arshad-dqot .

I've been wondering if there it was likely to cause problems having Android Studio's SDK and tools and Unity's. I just began changing part of a shipping app to Unity. I keep having trouble with these lines the export adds in the unityLibrary/build.gradle file: buildToolsVersion '32.0.0'

compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
}
AhmedNavaz commented 11 months ago

I found a solution that works for me. Delete the unityLibrary folder in Android Project and re-copy-paste from Unity;

This worked for me thanks.

monkeyK1n9 commented 10 months ago

This other solution worked for me: 1- In Unity, go to Edit->Preferences->ExternalTool and copy NDK path, 2- Open from terminal cd <NDK path> 3- open the source.properties file vi source.properties 4- note the ndk version 5- add android { ndkVersion '<version>' to your build.gradle in your unity/android/UnityLibrary 6- Create a file in your [Project root]/android/ and name it local.properties 7- Copy the SDK and NDK path from Unity Edit->Preferences->ExternalTool. You should have something like this :

sdk.dir = <the path to sdk>
ndk.dir = <the path to ndk>

8- Now you can run the build again

huzaifahazelGit commented 4 months ago

I found a solution that works for me. Looks that you can download a ndk version, but, Unity, by default is using it own version. Check in Unity , Preferences / External Tools . Here you can find Android NDK installed with Unity. The solution for me was, download NDK 19 from https://developer.android.com/ndk/downloads/older_releases Go to the folder where Unity is using NDK, for example : /Applications/Unity/Hub/Editor/2020.3.15f2/PlaybackEngines/AndroidPlayer/NDK Delete this content and replace with the new NDK downloaded. Unity looks that only accept NDK version 19.0.5232133, so you can open the file source.properties in the new NDK folder and change the pkg.version with the accepted one: Pkg.Revision = 19.0.5232133 Rememeber that you need to have the same version of NDK in two files more: First on Android/local.properties: ndk.dir=/Applications/Unity/Hub/Editor/2020.3.15f2/PlaybackEngines/AndroidPlayer/NDK for example and on android/app/build.gradle: ndkVersion "19.0.5232133"

With all this, I can compile for Android. Hope this helps

I have tried many ways to run simple unity android code but at last I am able to run the build properly good with ndkVersion 19.2.5345600 Nice Answering , Properly good working with sdk.dir=C\:\Users\huzai\AppData\Local\Android\Sdk ndk.dir=C\:\Users\huzai\AppData\Local\Android\Sdk\ndk\19.2.5345600