-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Is there an existing issue for this?
- I have searched the existing issues
Unity version
Unity 6000.2.0 "Supported"
Common issues
- I have checked the common issues
Flutter version
3.32.8
Description
if you try to build on Android with an export from Unity 6000.0.2 or higher, you get this error:
FAILURE: Build failed with an exception.
* Where:
Build file '<path>\flutter_embed_unity-main\flutter_embed_unity_6000_0_android\example\android\unityLibrary\build.gradle' line: 134
* What went wrong:
Execution failed for task ':unityLibrary:buildIl2Cpp'.
> Could not get unknown property 'unity.androidNdkPath' for project ':unityLibrary' of type org.gradle.api.Project.
* 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 2m 58sUnity has changed the way they use NDK and SDK directories in unityLibrary/build.gradle.
Unity 2022.3/6000.0/6000.1 use android.ndkDirectory.
Unity 6000.2.0 uses unity.androidNdkPath and unity.androidSdkPath.
- commandLineArgs.add("--tool-chain-path=${android.ndkDirectory}")
+ commandLineArgs.add("--tool-chain-path=" + getProperty("unity.androidNdkPath"))- exec {
- executable "${workingDir}/src/main/Il2CppOutputProject/IL2CPP/build/deploy/il2cpp${executableExtension}"
- args commandLineArgs
- environment "ANDROID_SDK_ROOT", getSdkDir()
- }
+ def command = "${workingDir}/src/main/Il2CppOutputProject/IL2CPP/build/deploy/il2cpp${executableExtension}";
+ execCommand(workingDir, [command, *commandLineArgs], [
+ "ANDROID_SDK_ROOT": getProperty("unity.androidSdkPath"),
+ "ANDROID_NDK_ROOT": getProperty("unity.androidNdkPath"),
+ "NDK_ROOT": getProperty("unity.androidNdkPath"),
+ "ANDROID_NDK_HOME": getProperty("unity.androidNdkPath"),
+ ])These unity. properties are defined in gradle.properties in the Unity output.
Example of gradle.properties.
org.gradle.jvmargs=-Xmx4096M
org.gradle.parallel=true
unityStreamingAssets=
unityTemplateVersion=20
unityProjectPath=<path>\flutter_embed_unity-main\example_unity_6000_0_project
unity.projectPath=<path>\flutter_embed_unity-main\example_unity_6000_0_project
unity.debugSymbolLevel=none
unity.buildToolsVersion=34.0.0
unity.minSdkVersion=24
unity.targetSdkVersion=34
unity.compileSdkVersion=34
unity.applicationId=com.example.flutterunitywidget
unity.abiFilters=armeabi-v7a,arm64-v8a
unity.versionCode=1
unity.versionName=0.1
unity.namespace=com.example.flutterunitywidget
unity.agpVersion=8.7.2
unity.androidSdkPath=C:/Program Files/Unity/Hub/Editor/6000.2.0f1/Editor/Data/PlaybackEngines/AndroidPlayer/SDK
unity.androidNdkPath=C:/Program Files/Unity/Hub/Editor/6000.2.0f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK
unity.androidNdkVersion=27.2.12479018
unity.jdkPath=C:/Program Files/Unity/Hub/Editor/6000.2.0f1/Editor/Data/PlaybackEngines/AndroidPlayer/OpenJDK
unity.javaCompatabilityVersion=VERSION_17
unity.installInBuildFolder=false
android.useAndroidX=true
android.enableJetifier=true
android.bundle.includeNativeDebugMetadata=false
org.gradle.welcome=never
Fix / Workaround
The easiest fix seems to be to avoid deleting the file android/unityLibrary/gradle.properties during the export.
ProjectExporterAndroid.cs around line 85
// ProjectExporterAndroid.cs
// The files at the root of exportPath can be deleted
DirectoryInfo exportDirectory = new DirectoryInfo(exportPath);
foreach (FileInfo file in exportDirectory.GetFiles()) {
+ if (file.Name != "gradle.properties")
+ {
file.Delete();
Debug.Log($"Deleted {file.FullName}");
+ }
}Alternatively you could define your own values in the android/gradle.properties of your Flutter project.
unity.androidSdkPath=
unity.androidNdkPath=
Minimum reproducible example (MRE)
Just try to build the example from this repo. Unity 6000.2.0 or newer.
What platforms are you seeing the problem on?
Android
Devices
No response
Anything else?
I know 6.2 is not a LTS release like 6000.0.x, but Unity has recently added "Supported" releases.
And 6.2 is listed as recommended in Unity hub.
