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

Receiving "NDK is not installed" error despite using NDK installed with Unity #832

Closed
Shaobin-Jiang opened this issue Jun 24, 2023 · 3 comments

Comments

@Shaobin-Jiang
Copy link

Unity version: 2022.2.0f1c1 on Windows 11

android/local.properties

sdk.dir=C:\\Installed\\Scoop\\apps\\android-sdk\\current
flutter.sdk=C:\\Installed\\flutter
ndk.dir=C:\\Installed\\UnityEditor\\2022.2.0f1c1\\Editor\\Data\\PlaybackEngines\\AndroidPlayer\\NDK

Where the above ndk path is what I directly copied from Unity's preference settings.

Despite having done this, after using Flutter run, I keep receiving the error below:

[CXX1100] Both android.ndkPath and ndk.dir in local.properties are set

FAILURE: Build failed with an exception.

* Where:
Build file 'F:\Files\Codes\Projects\sports-training\sports_training\android\unityLibrary\build.gradle' line: 69

* What went wrong:
Execution failed for task ':unityLibrary:BuildIl2CppTask'.
> NDK is not installed

* 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 2s
Running Gradle task 'assembleDebug'...                              3.4s
Exception: Gradle task assembleDebug failed with exit code 1

This is kind of frustrating, since I have done exactly what the instructions from the README dictates. Is there anything I can do to solve this?

@weidenbach
Copy link

I have the same issue too. You can fix it by specifying the ndkVersion within the build.gradle in the generated unity project. However, it will be overriden every time you export the project, so I wrote a command that overrides the generated version with the one that includes the ndkVersion line.

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

@Shaobin-Jiang
Copy link
Author

I have the same issue too. You can fix it by specifying the ndkVersion within the build.gradle in the generated unity project. However, it will be overriden every time you export the project, so I wrote a command that overrides the generated version with the one that includes the ndkVersion line.

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

That did not exactly work for me @weidenbach , but gave me a hint as to how the problem might be solved. As I have only limited experience with flutter and almost none with vanilla android development, or at least I have never engaged in projects that requires me to look deeper into the project structure, I never realized that there might be more than one build.gradle file in the project.

In my case, the solution is this: I manually replaced line 69 in android/unityLibrary/build.gradle, which was originally

commandLineArgs.add("--tool-chain-path=" + android.ndkDirectory)

with the line below:

commandLineArgs.add("--tool-chain-path=" + "C:/Installed/UnityEditor/2022.2.0f1c1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK")

where the path within the quotation marks is where my NDK is installed.

@timbotimbo
Copy link
Collaborator

Just ran into the same error while testing a build on Unity 2022.3.4.
This line at the top of the error hints at the solution:
[CXX1100] Both android.ndkPath and ndk.dir in local.properties are set

These newer Unity versions add a ndkPath variable to unityLibrary/build.gradle

android {
+    ndkPath "C:/Program Files/Unity/Hub/Editor/.....

This conflicts with the ndk.dir in local.properties.

Simply removing ndk.dir from local.properties solved this error for me.

auto-submit bot pushed a commit to flutter/flutter that referenced this issue Jul 31, 2023
<img width="1119" alt="image" src="https://github.com/flutter/flutter/assets/66480156/e2e8eed1-3bef-436c-b21f-3891bdbe05bb">

In most cases, a FFI plugin doesn't need its own specific Android NDK version. Just following the Flutter app project's NDK version is enough.

If a Flutter app project depends on multiple FFI plugins that use different Android NDK versions, it can be quite wasteful and use excessive disk space due to multiple NDK installations.

Using Flutter app project's NDK version is also less error-prone because upgrading the Flutter SDK would be enough when upgrading FFI plugins(If project's `ndkVersion` is `flutter.ndkVersion`), without messing with Android NDK installations.

This problem was discussed in some actual FFI plugin repositories, and they are striving to find their own solutions:
- superlistapp/super_native_extensions#143 (comment)
- cunarist/rinf#60 (comment)
- rive-app/rive-flutter#320
- juicycleff/flutter-unity-view-widget#832
LouiseHsu pushed a commit to LouiseHsu/flutter that referenced this issue Jul 31, 2023
<img width="1119" alt="image" src="https://github.com/flutter/flutter/assets/66480156/e2e8eed1-3bef-436c-b21f-3891bdbe05bb">

In most cases, a FFI plugin doesn't need its own specific Android NDK version. Just following the Flutter app project's NDK version is enough.

If a Flutter app project depends on multiple FFI plugins that use different Android NDK versions, it can be quite wasteful and use excessive disk space due to multiple NDK installations.

Using Flutter app project's NDK version is also less error-prone because upgrading the Flutter SDK would be enough when upgrading FFI plugins(If project's `ndkVersion` is `flutter.ndkVersion`), without messing with Android NDK installations.

This problem was discussed in some actual FFI plugin repositories, and they are striving to find their own solutions:
- superlistapp/super_native_extensions#143 (comment)
- cunarist/rinf#60 (comment)
- rive-app/rive-flutter#320
- juicycleff/flutter-unity-view-widget#832
vashworth pushed a commit to vashworth/flutter that referenced this issue Aug 2, 2023
<img width="1119" alt="image" src="https://github.com/flutter/flutter/assets/66480156/e2e8eed1-3bef-436c-b21f-3891bdbe05bb">

In most cases, a FFI plugin doesn't need its own specific Android NDK version. Just following the Flutter app project's NDK version is enough.

If a Flutter app project depends on multiple FFI plugins that use different Android NDK versions, it can be quite wasteful and use excessive disk space due to multiple NDK installations.

Using Flutter app project's NDK version is also less error-prone because upgrading the Flutter SDK would be enough when upgrading FFI plugins(If project's `ndkVersion` is `flutter.ndkVersion`), without messing with Android NDK installations.

This problem was discussed in some actual FFI plugin repositories, and they are striving to find their own solutions:
- superlistapp/super_native_extensions#143 (comment)
- cunarist/rinf#60 (comment)
- rive-app/rive-flutter#320
- juicycleff/flutter-unity-view-widget#832
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

3 participants