Ionic build error: Unsupported major.minor version 52.0

When running an “android build” I am getting the following error:


FAILURE: Build failed with an exception.

* Where:
Build file ‘D:\myApp\platforms\android\build.gradle’ line: 20

* What went wrong:
A problem occurred evaluating root project ‘android’.
> java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* Where:
Build file ‘D:\myApp\platforms\android\build.gradle’ line: 20

* What went wrong:
A problem occurred evaluating root project ‘android’.
> java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.


This build was working not so long ago so not sure whats stopped it working. here are my versions:

ionic cli 1.7.6
cordova 7.0.1
JDK 1.8.0_92

I have searched through the forums and seen a few people with similar issues and followed their advice to get it working but I still cant get it to work.

Okay so I know what the issue is however Im not sure why it has changed or what I can do to fix it permanently.

The problem is that when I run “ionic platform add android” it is using Java 1.8 however when I build the application it is using 1.7 (as my JAVA_HOME variable is set to 1.7 because this is a requirement of another application).

This was working fine before with my JAVA_HOME variable being set to 1.7 so why would it stop working?

If there is no way to get the build to work with Java 1.7 is there anyway I can tell ionic to use Java 1.8 without changing the JAVA_HOME system variable? I dont want to have to keep changing it every time I switch applications.