86

Error:

Invalid command android
UnityEditor.HostView:OnGUI()

CommandInvokationFailure:

Unable to list target platforms. Please make sure the android sdk path is correct. See the Console for more details. 
C:/Program Files/Java/jdk1.8.0_121\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/Users/great/AppData/Local/Android/Sdk\tools" -Dfile.encoding=UTF8 -jar "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\sdktools.jar" -

stderr[
Error:Invalid command android
]
stdout[

]
exit code: 64
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommandInternal (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommandSafe (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.HostView:OnGUI()

Error building Player:

CommandInvokationFailure: Unable to list target platforms. Please make sure the android sdk path is correct. See the Console for more details. 
C:/Program Files/Java/jdk1.8.0_121\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/Users/great/AppData/Local/Android/Sdk\tools" -Dfile.encoding=UTF8 -jar "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\sdktools.jar" -

stderr[
Error:Invalid command android
]
stdout[

]
exit code: 64

Screenshot:

screenshot

3
  • 1
    Try this and see if that helps...
    – Programmer
    Mar 1, 2017 at 17:43
  • I had no problem working with unity 2017.0.2f and sdk 25.2.5 until I installed Unity 2017.0.3f and suddenly Nothing worked after!
    – Ghasem
    Dec 31, 2017 at 4:51
  • A year later, still an issue. Weird thing is the error says: "CommandInvokationFailure: Unable to list target platforms. Please make sure the android sdk path is correct. C:/Users/Francois/AppData/Local/Android/Sdk\tools\bin\avdmanager.bat list target -c" If I run that exact command, I get a list of target platforms. So beside the \ vs / mess in the path, the command works.
    – FMaz008
    Mar 8, 2018 at 23:12

11 Answers 11

198

I have same problem.

I fixed by android sdk tool version downgrade.

The steps.

  1. Delete android sdk "tools" folder : [Your Android SDK root]/tools -> tools

  2. Download SDK Tools: http://dl-ssl.google.com/android/repository/tools_r25.2.5-windows.zip

  3. Extract that to Android SDK root

  4. Build your project

13
  • This fix produces another error: Error: [Temp\StagingArea\AndroidManifest-main.xml:12, C:\Users\Admin\Documents\Google VR\Temp\StagingArea\android-libraries\gvr-permissionsupport-release\AndroidManifest.xml:3] Main manifest has <uses-sdk android:minSdkVersion='16'> but library uses minSdkVersion='19'
    – Ajq
    Mar 4, 2017 at 8:26
  • Also need to ensure to set the Minimum API Level to the same level as the SDK. This is done in Play settings -> Other settings. In my case I had to set it to 19 as it was set to 16.
    – Ajq
    Mar 4, 2017 at 9:22
  • 20
    for MacOS: cd $ANDROID_HOME; rm -rf tools; wget http://dl-ssl.google.com/android/repository/tools_r25.2.5-macosx.zip; unzip tools_r25.2.5-macosx.zip Mar 15, 2017 at 23:42
  • How Can I solve it for Mac? The terminal command is not working for me. May 3, 2017 at 14:54
  • 4
    I still had issues after this. Apparently JDK 1.9.0 still has issue. Installing 1.8.0 worked for me. My combination that works for me: Unity 2017.2.0f3 Android SDK 26 Android SDK Tools 25.2.5 JDK 1.8.0_151
    – justinl
    Nov 8, 2017 at 22:10
34

The issue is due to incompatibility of unity with latest Android build tools. For MacOS here's a one liner that will get it working for you:

cd $ANDROID_HOME; rm -rf tools; wget http://dl-ssl.google.com/android/repository/tools_r25.2.5-ma‌​cosx.zip; unzip tools_r25.2.5-macosx.zip
5
  • mirrors.neusoft.edu.cn/android/repository/… This link worked for me Apr 27, 2017 at 8:04
  • Oddly, I couldn't go to that link with wget (was getting a 404), but when I opened it in a browser, it started a download as I'd expect.
    – livingtech
    May 18, 2017 at 0:26
  • 1
    @livingtech unfortunately thats because when u copy it from SO, it has a space in the url. May 25, 2017 at 20:22
  • 1
    Perfect sound, but must install homebrew and wget first! Another way, download zip file and unzip manualy !
    – BSQ
    Oct 1, 2017 at 4:40
  • if you don't have wget, you can use cd $ANDROID_HOME; rm -rf tools; curl http://dl-ssl.google.com/android/repository/tools_r25.2.5-ma‌​cosx.zip > tools_r25.2.5-ma‌​cosx.zip; unzip tools_r25.2.5-macosx.zip
    – Kirk Boyer
    Oct 4, 2018 at 18:08
13

1- Just open https://developer.android.com/studio/index.html

2- scroll down to the bottom of that page

3- download last version of tools for your OS (for example tools_r25.2.3-windows.zip)

4- Unzip it

5- Delete folder tools from previous Android Sdk folder

6- Copy new folder tools to Android SDK Folder like this image:

enter image description here

1
  • I have tried downloading it and following ur steps, but still having the issue! May 3, 2017 at 15:34
6

Unity 5.6.1 / 2017.1 fixes the Android SDK Tools 25.3.1+ compatibility issue. This is noted in Unity bug tracker under issue 888859 and their 5.6.1 release notes.

3
  • 8
    Unity 2017.2 breaks it again. Nov 30, 2017 at 22:08
  • 1
    I use 2017.3.1 and I'm having this problem.
    – FMaz008
    Mar 8, 2018 at 23:14
  • i'm using 2018.2.1 but still having same issue
    – user8215153
    Dec 15, 2018 at 15:05
6

These are the steps that eventually worked for me...

  • Install JDK jdk1.8.0_131 (yes, this specific version, not a later version) and set it as the JDK Path in Unity.

  • Delete android sdk tools folder : [android_sdk_root]/tools

  • Download SDK Tools v25.2.5 (this specific version) from http://dl-ssl.google.com/android/repository/tools_r25.2.5-windows.zip

  • Extract the tools folder in that archive to Android SDK root

  • Build your project

1
  • This is not about the Install JDK jdk1.8.0_131 (specific version), it worked for me with the jdk1.8.0_151. The problem is about the repository tools, like you wrote (only that one). Nov 17, 2017 at 10:52
6

For Mac OS Users :

Go to your Android SDK folder and delete the tools folder (I recommend you to make a copy before deleting it, in case this solution does not solve the problem for you)

Then download the tools folder here :

http://dl-ssl.google.com/android/repository/tools_r25.2.5-macosx.zip

You can find all tools zip version here :

https://androidsdkoffline.blogspot.fr/p/android-sdk-build-tools.html

Then unzip the download file and place it in the Android sdk folder.

Hope it helps

0
5

Easier solution: set the environment variable USE_SDK_WRAPPER=1, or hack tools/android.bat to add the line "set USE_SDK_WRAPPER=1". This prevents android.bat from popping up a "y/n" prompt, which is what's confusing Unity.

1
  • 1
    @paul-du-bois Had the same problem right now with 2018.1x and 2018.2x versions of unity, and adding the wrapper line in default "android.bat" file solved the issue. Thanks!
    – asethi
    Jul 18, 2018 at 16:42
5
  1. Delete android sdk "tools" folder : [Your Android SDK root]/tools -> tools

  2. Download SDK Tools: http://dl-ssl.google.com/android/repository/tools_r25.2.5-windows.zip

  3. Extract that to Android SDK root

  4. Build your project

After that it didn't work for me yet, I had to

  1. Go to the Java archives (http://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html)

  2. Search for the jdk-8u131 release.

  3. Accept the Licence Agreement,make an account and download the release.

  4. Install it and define it as JDK path in Unity.

source : https://www.reddit.com/r/Unity3D/comments/77azfb/i_cant_get_unity_to_build_run_my_game/

1
  • 1
    thanks you you saved me :o 12/04/2018 and this is still not working Apr 12, 2018 at 5:43
2

I solved the problem by uninstalling JDK 9.

2
  • This is very relevant actually - for some reason Unity is detecting the most recent JDK, so even setting the correct path doesn't work - the newer JDKs, beyond 8, must be uninstalled. Jul 20, 2018 at 13:47
  • For me it worked by adding JAVA_HOME and ANDROID_HOME to system variables while using latest JDK and Android Build Tools. set ANDROID_HOME=C:\ installation location \android-sdk set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
    – asethi
    Jul 20, 2018 at 21:02
1

In my case, I was trying to build and get APK for an old Unity 3D project (so that I can play the game in my Android phone). I was using the most recent Android Studio version, and all the SDK packages I could download via SDK Manager in Android Studio. SDK Packages was located in

C:/Users/Onat/AppData/Local/Android/Sdk And the error message I got was the same except the JDK (Java Development Kit) version "jdk-12.0.2" . JDK was located in

C:\Program Files\Java\jdk-12.0.2 And Environment Variable in Windows was JAVA_HOME : C:\Program Files\Java\jdk-12.0.2

After 3 hours of research, I found out that Unity does not support JDK 10. As told in https://forum.unity.com/threads/gradle-build-failed-error-could-not-determine-java-version-from-10-0-1.532169/ . My suggestion is:

1.Uninstall unwanted JDK if you have one installed already. https://www.java.com/tr/download/help/uninstall_java.xml

2.Head to http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

3.Login to/Open a Oracle account if not already logged in.

4.Download the older but functional JDK 8 for your computer set-up(32 bit/64 bit, Windows/Linux etc.)

5.Install the JDK. Remember the installation path. (https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/)

6.If you are using Windows, Open Environment Variables and change Java Path via Right click My Computer/This PC>Properties>Advanced System Settings>Environment Variables>New>Variable Name: JAVA_HOME>Variable Value: [YOUR JDK Path, Mine was "C:\Program Files\Java\jdk1.8.0_221"]

7.In Unity 3D, press Edit > Preferences > External Tools and fill in the JDK path (Mine was "C:\Program Files\Java\jdk1.8.0_221").

8.Also, in the same pop-up, edit SDK Path. (Get it from Android Studio > SDK Manager > Android SDK > Android SDK Location.)

9.If needed, restart your computer for changes to take effect.

0

Linux Users:

cp -r Android AndroidUnity
cd AndroidUnity/Sdk
rm -rf tools
wget http://dl-ssl.google.com/android/repository/tools_r25.2.5-windows.zip
unzip tools_r25.2.5-windows.zip

In Unity preferences change to this newly created sdk folder.

Not the answer you're looking for? Browse other questions tagged or ask your own question.