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 505 forks source link

Remove ndkPath from generated build.gradle #880

Closed ricardodalarme closed 8 months ago

ricardodalarme commented 9 months ago

Description

Starting Unity 2023, Unity generates build.gradle with ndkPath which contains the absolute path to the NDK. e.g:

android {
    ndkPath "/Applications/Unity/Hub/Editor/2023.1.14f1/PlaybackEngines/AndroidPlayer/NDK"
    compileSdkVersion 33
    buildToolsVersion "32.0.0"

This causes the build to fail when tested on a different machine or when the ndk version is defined in the app-level build.gradle.

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

Type of Change

timbotimbo commented 8 months ago

Looks like this not only applies to 2023 but also 2022.3. The NDK not installed error has also shown up before: https://github.com/juicycleff/flutter-unity-view-widget/issues/832

I checked exports with the latest Unity versions on Windows. (2020.3.48, 2021.3.31, 2022.3.11 and 2023.1.16) Both 2022.3 and 2023 add the absolute path like you mention. ndkPath "C:/Program Files/Unity/Hub/Editor/2022.3.11f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK"

Following the readme and having both ndk.dir in local.properties and this ndkPath set causes an error.

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

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\User\Documents\unity_widget\example\android\unityLibrary\build.gradle' line: 67

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

Removing either android.ndkPath or nkd.dir solves the error. But like you mention, removing ndkPath makes the export more portable.

The only possible issue that I see is that some setups throw a deprecation warning for ndk.dir.

WARNING: NDK was located by using ndk.dir property. This method is deprecated and will be removed in a future release. Please delete ndk.dir from local.properties and set android.ndkVersion to [XXXXXX] in all native modules in the project. https://developer.android.com/r/studio-ui/ndk-dir

But I guess this future issue is irrelevant to this specific change.