Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Android] [Unity 6.2] Could not get unknown property 'unity.androidNdkPath' for project ':unityLibrary' #1039

Open
@timbotimbo

Description

Describe the bug
When using Unity 600020 with Android, you will get the following error:

FAILURE: Build failed with an exception.
* Where:
Build file 'C:\<path>\example\android\unityLibrary\build.gradle' line: 130
* 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 2s
Running Gradle task 'assembleRelease'... 3.6s
Gradle task assembleRelease failed with exit code 1

To Reproduce

  1. Use the Unity 6000 branch or flutter_unity_widget_2 to handle Unity 6 support.
  2. Export Android using Unity 600020 or newer.
  3. Attempt to run or build Flutter

More Context
Unity 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 600020 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-unity-view-widget-flutter_unity_widget_2-6000/example/unity/DemoApp
unity.projectPath=<path>flutter-unity-view-widget-flutter_unity_widget_2-6000/example/unity/DemoApp
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

The easiest fix seems to be to copy Unity's gradle.properties file during the export.

FlutterUnityIntegration/editor/build.cs around line 250.

// private static void DoBuildAndroid
	Copy(buildPath, AndroidExportPath);
	// Unity 6000 shared folder
	string sharedPath = Path.Combine(APKPath, "shared");
	if (Directory.Exists(sharedPath)) 
	{
		Copy(sharedPath, Path.Combine(AndroidExportPath, "shared"));
	}
+ // Unity 6.2 requires unity.androidNdkPath and unity.androidSdkPath from gradle.properties.
+ File.Copy(Path.Combine(APKPath, "gradle.properties"), Path.Combine(AndroidExportPath, "gradle.properties"), true);
	// Modify build.gradle
	ModifyAndroidGradle(isPlugin);
	if(isPlugin)
	{
		SetupAndroidProjectForPlugin();
	} else
	{
		SetupAndroidProject();
	}

Alternatively you could define your own values in the android/gradle.properties of your Flutter project.

unity.androidSdkPath=
unity.androidNdkPath=

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /