83

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

Salman Khan
  • 857
  • 1
  • 8
  • 15
  • 1
    Try [this](http://stackoverflow.com/a/36959457/3785314) and see if that helps... – Programmer Mar 01 '17 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! – Alex Jolig Dec 31 '17 at 04: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 08 '18 at 23:12

11 Answers11

197

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

Choi Yonggui
  • 1,994
  • 1
  • 7
  • 3
  • 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 but library uses minSdkVersion='19' – Ajq Mar 04 '17 at 08: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 04 '17 at 09: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` – electronix384128 Mar 15 '17 at 23:42
  • How Can I solve it for Mac? The terminal command is not working for me. – Mago Nicolas Palacios May 03 '17 at 14:54
  • My Error is that it Seems it can't find the file at that URL – Mago Nicolas Palacios May 03 '17 at 15:32
  • @Noah Cristino Did updating to Unity 5.6.1 not fix the issue for you? – jkasten Jun 29 '17 at 21:04
  • No it didn't the answer fixed it – Noah Cristino Jun 30 '17 at 15:01
  • No it didn't the answer fixed it – Noah Cristino Jun 30 '17 at 15:01
  • New SDK versions still have problem and still your answer is solving the problem thanx :) – ayortanli Oct 17 '17 at 20:22
  • 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 08 '17 at 22:10
  • 11/17/2017 - still issue, Unity 2017.2.0f3, and your solution works. – Olivier Pons Nov 17 '17 at 11:01
  • Do not delete tools folder, that may affect Android Studio. Instead, duplicate the Sdk folder and do the stuff there and point unity to this new folder. – vishalknishad Jun 17 '18 at 08:10
  • If you want the latest version 26.1.1 you can download 25.2.5 and after extracting tools folder, just upgrade with Android Studio SDK manager. – geekley Jul 18 '20 at 01:46
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
Derlin
  • 8,518
  • 2
  • 22
  • 42
electronix384128
  • 6,286
  • 10
  • 39
  • 64
  • http://mirrors.neusoft.edu.cn/android/repository/tools_r25.2.5-macosx.zip This link worked for me – Noor Ali Butt Apr 27 '17 at 08: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 '17 at 00:26
  • 1
    @livingtech unfortunately thats because when u copy it from SO, it has a space in the url. – electronix384128 May 25 '17 at 20:22
  • 1
    Perfect sound, but must install homebrew and wget first! Another way, download zip file and unzip manualy ! – BSQ Oct 01 '17 at 04: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 04 '18 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

Ayub
  • 1,705
  • 21
  • 27
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.

jkasten
  • 3,729
  • 3
  • 29
  • 48
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

Greg Quinn
  • 1,597
  • 1
  • 19
  • 22
  • 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). – Olivier Pons Nov 17 '17 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

fandro
  • 4,281
  • 7
  • 35
  • 56
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.

Paul Du Bois
  • 1,936
  • 1
  • 19
  • 29
  • 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 '18 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/

Garvit Jain
  • 1,232
  • 2
  • 17
  • 24
2

I solved the problem by uninstalling JDK 9.

DmitryKanunnikoff
  • 2,116
  • 1
  • 19
  • 29
  • 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. – Evan Knowles Jul 20 '18 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 '18 at 21:02
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.

vishalknishad
  • 374
  • 3
  • 11
0

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.

Onat Korucu
  • 512
  • 6
  • 9