Android Build error (gradle)

I am developing an Ionic 2 app on MacOS Sierra.

I’ve completed in-browser testing but am getting an error when executing ‘ionic build android --release --prod’:

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘/Users/davidebbitt/Desktop/ionic2/cholTracker2/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

The reference line 20 in the gradle file is:

apply plugin: ‘com.android.application’

I am longing to get this app into the Play store, so any help will be greatly appreciated.

Thanks!

Looks like you are building with an old JDK. You need to have your Java environment set up to build with Java 8.

you need to set the JAVA_HOME = /usr/lib/jvm/java-8-oracle

where do we have to set this above path

which OperatingSystem you are working on? If its on ubuntu then open a terminal, move to the project(your ionic2 project) folder and then set that JAVA_HOME variable

I have ionic 3 and I am on ubuntu
In .profile file I have set export JAVA_HOME=$JAVA_HOME:/usr/lib/jvm/java-8-oracle
ionic cordova build android is working fine
but ionic cordova run android is throwing the below error
UILD SUCCESSFUL

Total time: 1.323 secs
Built the following apk(s):
/var/www/html/ionic/myApp/platforms/android/build/outputs/apk/android-debug.apk

ANDROID_HOME=/opt/android-sdk/
JAVA_HOME=/usr/lib/jvm/java-8-oracle
No target specified and no devices found, deploying to emulator

Error: No emulator images (avds) found.

  1. Download desired System Image by running: /opt/android-sdk/tools/android sdk
  2. Create an AVD by running: /opt/android-sdk/tools/android avd
    HINT: For a faster emulator, use an Intel System Image and install the HAXM device driver

[ERROR] Cordova encountered an error.
You may get more insight by running the Cordova command above directly.

[ERROR] An error occurred while running cordova run android (exit code 1).