If you are using JDK 9 or JDK10 and trying to build for Android in Unity - you’re most likely to have your build failed, with message like “Unable to list target platforms” - “Error:Invalid command android”.
We are working together with Google on fixing this issue - it requires fixes on Unity side, but also Android SDK tools need to be updated to be compatible with latest Java.
In the meanwhile, we recommend using Java 8 (JDK 8) 64-bit.
We apologize for the inconvenience caused!
Your Unity Mobile team
EDIT: looks like if you have different JDKs installed, despite selecting JDK8 in the Unity Editor preferences, Android SDK continues to use later JDKs. The only known solution at the moment is to UNINSTALL JDK9 and JDK10, and have only JDK8 (64-bit) installed.
UPDATE: in Unity 2018.3, we are shipping OpenJDK together with Unity. By default, it will be used by the build pipeline, which means - no external JDK installations are needed**,** no version hassle etc.
On the scratch system macos high sierra 10.13 I’ve installed JDK 9 on by homebrew and Unity 2017.2.0f2 didn’t work with it.
After it downloaded JDK 8 from Oracle site and changed path in Unity settings but the issue didn’t solve.
After adding export JAVA_HOME=/usr/libexec/java_home -v 1.8 to ~/.bash_profile it didn’t work too.
Only full removing JDK 9 by command brew cask uninstall jdk - solved the issue
@chantey I assume you forgot to update Unity preferences and it’s still using the older JDK. You can make sure by checking the Editor log. Unfortunately it’s expected to have issues now.
Im finding that I can build with JDK8 but I cant sign my app. The passes are correct as shown in the console but I get:-
CommandInvokationFailure: Failed to sign APK package.
D:\Android\android-sdk\build-tools\25.0.2\apksigner.bat sign --ks "E:/Shared Documents/Work/Android-KeyStore.keystore" --ks-pass pass:"keyStorePass" --ks-key-alias "appAlias" --key-pass pass:"appPass" "E:\Shared Documents\Work\MyProject\Temp/StagingArea/Package.apk"
stderr[
java.lang.UnsupportedClassVersionError: com/android/apksigner/ApkSignerTool : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:412)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Exception in thread "main"
]
I have tried everything I can find, Reinstalling Android Studio, updating the JAVA_HOME environment variable, Deleting build-tools\25.0.2 (to force it to us 23.0.2), copying java.exe from System32 to SystemWOW64, (and other suggestions here ) But nothing works. Any ideas?
EDIT This was in 2017.1f1 by the way- I can even build an unsigned version in 2017.1.2 (see following post)
I think thats the relevant part anyways- the log is epic, but after that it goes on about trying overlay files, finding them and processing them, but I dont see any errors there…tho like I say its the biggest log I have ever seen!
In AndroidManifest.xml find nodes with attributes configChanges (probably lines 28 and 35). Then try to narrow down (one by one), which item is not parsed as valid enum-value and thus treated as string: mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density
Thanks for your reply…Trouble is, I dont actually have an AndroidManifest.xml file with that list of flags in it… I think something maybe generating it on the fly… (I’m using UltimateMobile which merges manifests for you, but none have a string like that in)
And also I am building with the same JDK and Android SDK in both cases above, so why is it only Unity 2017.1.2p1 that is giving me that error? Is it Unity 2017.1.2p1 that is generating that code with a flag that only exists in JDK9 or some newer buildtools (than 25.0.2) or something?
Well made a slight step forwards. I discovered that updating android studio made it store its updated sdk files in E:\Users\thisUser\AppData\Local\Android\sdk rather than its previous location. In there I see a buildTools folder with all the new ones. So I updated the Unity preferences location to that.
BUT it still doesn’t work… Now I get:
E:\Shared Documents\Work\PathToProject\Temp\StagingArea\AndroidManifest-main.xml:8:16-49 Error:
Attribute application@icon value=(@drawable/app_icon) from AndroidManifest-main.xml:8:16-49
is also present at AndroidManifest.xml:13:9-45 value=(@drawable/ic_launcher).
Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest-main.xml:8:3-48:17 to override.
But again I dont have any manifests that have an icon value defined as “@drawable/ic_launcher”
Ive now tried everything on this thread too, to no avail:
Ok using E:\Users\thisUser\AppData\Local\Android\sdk rather than its previous location I cant build an unsigned version in Unity 2017.1.0.f1 either now…
So MONEY MONEY MONEY
what will it take to get some one to sort this building bullshit out for me. I need iOS too which is also not working- but was with the same project a couple of days ago (and for months before)
We are aware of this issue and it will be fixed. For now make sure you have android API 24 or newer installed and selected as a target sdk (if not using auto option). The problem is that aapt tool does not allow density value for the configChanges until API level 24. https://issuetracker.google.com/issues/67580651
thanks @JuliusM I finally got this working- I’m just gonna post what worked for me in case it helps anyone else- I’m not sure exactly which of these steps are 100% necessary but this is what worked for me on Windows 7…
Make sure you are using Unity 2017.1.2p1 (maybe greater, but I didn’t try because I know Unity 2017.2 re-introduces a bug in meshCombiner that stops UMA from working)
Update your AndroidStudio/SDK via the download link in the Edit → Preferences → ExternalTools/ Android/ SDK Download button.
2a) I found after updating Android Studio all the sdk stuff had moved from my previous location, and it was now in C:/Users/YourUserName/AppData/Local/Android/sdk (My ‘Users’ folder is actually on my ‘E:’ drive but you get the idea) So make sure your Edit → Preferences → ExternalTools/ Android/ SDK is actually pointing to where your new SDK stuff actually is
Navigate to the above location and check in the ‘build-tools’ folder to make sure you have 26.0.2 in there
3a) If you dont have that, open Android Studio and go to File → Settings, then in that window in the side pane twirl open ‘Appearance & Behaviour / System Settings / Android SDK’
3b) Select the SDKTools tab in the window pane, ensure ‘Show Package Details’ is checked towards the bottom, and check 26.0.2 and hit ‘Apply’. This should make that download and install. after that it should be in ‘C:/Users/YourUserName/AppData/Local/Android/sdk/build-tools’ If its not, your SDK locations is probably not right, because it will have downloaded it to an ‘Android/sdk/build-tools’ folder somewhere, so you are going to have to figure out where that is…
Update your JDK (Java Development Kit) Dont use the latest version (if you are on this thread I guess you already know jdk 9 is not working lol) instead go here (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) and choose the ‘Java SE Development Kit 8u152’ version.
4a) after you have installed that, right click on ‘My Computer’ or whatever its called now, goto ‘Properties > Advanced System Settings’ and click on the ‘Environment Variables’ button. In there look for the ‘System Variables’ section and find the variable ‘JAVA_HOME’ edit the value of that so it points to where you just installed Java 8 in the step above (in my case it was c:\Program Files\Java\jdk.1…0_152
4b) make sure that in Unity Edit → Preferences → ExternalTools / Android / JDK your path is set to the new JDK 8 you just installed.
Fix your AndroidManifest files. This will vary an awful lot depending on your project, but I was using UltimateMobile/AndroidNative and that was causing ‘merge manifests’ to fail during builds.
This is what they told me to do (and it worked):-
1) Open main AndroidManifest.xml by path: Plugins -> Android:
2) Add this field xmlns:tools="http://schemas.android.com/tools" to tag <Manifest
3) Then add this param tools:replace="android:icon, android:label, android:theme, android:debuggable" to tag <Application
ensuring that the <application tag actually has all those things eg android:icon="@drawable/app_icon" etc
4) Finally open all other AndroidManifest.xml by path (for example): Plugins -> Android -> AN_Res and remove android:icon="@drawable/app_icon" android:label="@string/app_name" from tag <application
After all that I could finally build and sign my Android apps
Really hope that helps anyone considering throwing themselves off a tall building like I was!!
This worked for me, I had the JDK 9.0 installed, I now have both the JDK 8.0 and 9.0 installed, added another path to include JDK 8.0 in the environment variables (Windows 10), and redirected that path in the Preferences window in Unity 5. It now works perfectly, thank you!
Looks like if you have Java9 installed, it’s added to PATH and Android SDK tools are using it despite Unity Editor preferences set to, for example, Java8.