Cordova/ionic build failed: Exit code 1

When trying to run Cordova or Ionic app on Android, I got errors like:

:transformClassesWithDexForDebugjava.lang.UnsupportedClassVersionError: com/android/dx/command/Main : 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 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"
FAILED
 
FAILURE: Build failed with an exception.

The reason is incorrect version of JDK(in my case it was openjdk-7)- it should be at least JDK8. But there is also another solution(maybe only if you write app for Android SDK < 6 or 5, I’m not sure) – you can create file yourproject/platforms/android/gradle.properties with

cdvBuildToolsVersion=23.0.3

inside. It will make Gradle(build tool used by Cordova) use Android Build Tools in previous version, which works with JDK7. Remember to install Android Build Tools 23.0.3 in your Android SDK Manager.

Enjoy Cordova 🙂

Sources: