[Solved]Ionic build error - need urgent solution - Im very frustrated one week - pls help


#1

Hi All,

I’m new to ionic and I need some help from you.

I’m learning ionic through one of the YouTube tutorial. I followed the below steps and no issues.

  • npm install -g cordova ionic
  • ionic start myApp sidemenu
  • ionic serve --lab

everything working proper until here. But,when I run the build android code it gives errors. I don’t know how to solve it. I search and read many forums. But, can’t get exact solution because, each one says different solution and I got confused. I kindly request you to please help and guide me to solve this.

I installed Android studio 2.1.1

My ionic version is
Cordova CLI: 6.3.1
Ionic Framework Version: 1.3.1
Ionic CLI Version: 2.0.0
Ionic App Lib Version: 2.0.0-beta.20
OS: Windows 7 SP1
Node Version: v4.5.0

In Node.js command prompt,
after added platform android I followed these steps
step1: c:\users\myname\newApp\platforms\android\ionic android --release
step2: c:\users\myname\newApp\platforms\android\cd…
step3: c:\users\myname\newApp\platforms\cd…
step4: c:\users\myname\newApp\ionic build android --release

The errors are:
Running command: “C:\Program Files\nodejs\node.exe” C:\Users\myname\newApp\hooks\after_prepare\010_add_platform_class.js C:\Users\myname\newApp

add to body class: platform-android

ANDROID_HOME=C:\Users\myname\AppData\Local\Android\sdk

JAVA_HOME=C:\Program Files\java\jdk1.6.0_45

Observed package id ‘add-ons;addon-google_apis-google-23’ in inconsistent location ‘C:\Users\myname\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-23-1’ (Expected ‘C:\Users\myname\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-23’)

Already observed package id ‘add-ons;addon-google_apis-google-23’ in ‘C:\Users\myname\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-23’. Skipping duplicate at ‘C:\Users\myname\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-23-1’

Default language level for compileSdkVersion ‘android-23’ is 1.7, but the JDK used is 1.6, so the JDK language level will be used.

Incremental java compilation is an incubating feature.

Default language level for compileSdkVersion ‘android-23’ is 1.7, but the JDK used is 1.6, so the JDK language level will be used.

Default language level for compileSdkVersion ‘android-23’ is 1.7, but the JDK used is 1.6, so the JDK language level will be used.

Default language level for compileSdkVersion ‘android-23’ is 1.7, but the JDK used is 1.6, so the JDK language level will be used.

BLAH BLAH…

warning: java\lang\AbstractStringBuilder.class(java\lang:AbstractStringBuilder.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
warning: java\lang\StringBuffer.class(java\lang:StringBuffer.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
warning: android\content\ContentResolver.class(android\content:ContentResolver.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
warning: android\provider\Settings$Secure.class(android\provider:Settings$Secure.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
Note: C:\Users\v.rajaguru\newApp\platforms\android\src\org\apache\cordova\splashscreen\SplashScreen.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
100 warnings
java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: com.android.dx.command.Main. Program will exit.
Exception in thread “main”

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:transformClassesWithDexForRelease’.

com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘C:\Program Files\Java\jdk1.6.0_45\bin\java.exe’’ finished with non-zero exit value 1

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    Could not find the main class: com.android.dx.command.Main. Program will exit.
    Exception in thread “main”

Please help me how to solve it.

Thanks in advance
Rajaguru.V


#2

did you add ios and android platforms??


#3

Hello Anicacute09,

Thanks for you quick reply.

I added android platform by the below code.

c:\users\myname\newApp\ionic platform add android
and I have now below folders
c:\users\myname\newApp\platforms\android\

But not ios. I ignored as per the guides under “Configure Platforms” in “http://ionicframework.com/docs/guide/installation.html

Thanks,
Rajaguru.V


#4

it’s ok if you add also then run it again let’s see what will be the result this time…


#5

Same error. Can I send the errors?


#6

i think your java version is deprecated or in lower version… what is your java version? it must be the latest version…


#7

I run configure java and navigated to Java tab and view. It shows
Platform 1.7
Product 1.7.0_79
Path C:\Program Files\Java\jre7\bin\javaw.exe
Enabled: selected

but in the error it shows -> JAVA_HOME=C:\Program Files\java\jdk1.6.0_45

Refer 5th line under The errors are, in my first post.


#8

install the latest java version I also having errors when I use 1.7 and below… when I install the latest all the errors are gone…


#9

Do I need to update only Java or JDK or both?


#10

both… you need the java and jdk to be compatible in version…


#11

Thank you very much Anicacute09 :slight_smile:

I will check and let you know the status.

Thanks again.


#12

Hi All,

I’m trying my first simple app using ionic framework for last one week. Unable to build the android app. I’m getting some errors when build. I don’t know what is wrong. I have installed latest version of Java and Ant. But still getting errors. Please help me.

I have installed the below applications
Cordova CLI: 6.3.1
Ionic Framework Version: 1.3.1
Ionic CLI Version: 2.0.0
Ionic App Lib Version: 2.0.0-beta.20
OS: Windows 7 SP1
Node Version: v4.5.0
Java 1.8
Ant 1.9.7
Android studio 2.1.1 (Im not using this. Just installed as per the guide.)

My doubts are
1.I have seen the issue -> To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more
than 2048 MB.

Question: The errors because of Gradle daemon… heap size? if Yes, how to fix and where can I find the file or settings to change it?

2.My Java Runtime Environment Settings is

Question:
1.8.0_101 is enabled but, the error says, Default language level for compileSdkVersion ‘android-23’ is 1.7, but the JDK used is 1.6, so the JDK language level will be used.

Why it used 1.6 instead of 1.8? if this is the cause for error, how to fix this? and where?

3.When I type ant -v in command and press enter (c:…\ant -v and press enter), I get the below error.

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.0_101\lib\tools.jar
Apache Ant™ version 1.9.7 compiled on April 9 2016
Trying the default build file: build.xml
Buildfile: build.xml does not exist!
Build failed

Question: Is this the reason for the errors?

4.How to fix this issue - > Execution failed for task ‘:transformClassesWithDexForDebug’.

I’m very confused in this.

Please help me I’m trying my first output for last one week. And unable to get the apk. Its very frustrated in my work.

Actual errors

Default language level for compileSdkVersion ‘android-23’ is 1.7, but the JDK us
ed is 1.6, so the JDK language level will be used.

Default language level for compileSdkVersion ‘android-23’ is 1.7, but the JDK us
ed is 1.6, so the JDK language level will be used.

blash blash…

:preBuild
UP-TO-DATE
:preDebugBuild
UP-TO-DATE

blash blash…

UP-TO-DATE

:compileDebugJavaWithJavac

UP-TO-DATE
:compileDebugNdk
UP-TO-DATE
:compileDebugSources UP-TO-DATE

:prePackageMarkerForDebug

:transformClassesWithDexForDebug

To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more
than 2048 MB.
To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html

java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupporte
d major.minor version 52.0

    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
  1.  at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
     at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
     at java.security.AccessController.doPrivileged(Native Method)
    
     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    

Could not find the main class: com.android.dx.command.Main. Program will exit.
Exception in thread “main”

:transformClassesWithDexForDebug FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:transformClassesWithDexForDebug’.

BUILD FAILED

Total time: 2.162 secs

com.android.build.api.transform.TransformException: java.lang.RuntimeException
: com.android.ide.common.process.ProcessException: java.util.concurrent.Executio
nException: com.android.ide.common.process.ProcessException: org.gradle.process.
internal.ExecException: Process ‘command ‘C:\Program Files\Java\jdk1.6.0_45\bin
java.exe’’ finished with non-zero exit value 1

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

java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupporte
d major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)

    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
  1.  at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
     at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    

Could not find the main class: com.android.dx.command.Main. Program will exit.
Exception in thread “main”

Error: cmd: Command failed with exit code 1 Error output:
java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupporte
d major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: com.android.dx.command.Main. Program will exit.
Exception in thread “main”

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:transformClassesWithDexForDebug’.

com.android.build.api.transform.TransformException: java.lang.RuntimeException
: com.android.ide.common.process.ProcessException: java.util.concurrent.Executio
nException: com.android.ide.common.process.ProcessException: org.gradle.process.
internal.ExecException: Process ‘command ‘C:\Program Files\Java\jdk1.6.0_45\bin
java.exe’’ finished with non-zero exit value 1

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.
    java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupporte
    d major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
  1.  at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
     at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    

Could not find the main class: com.android.dx.command.Main. Program will exit.
Exception in thread “main”

Thanks in advance
Rajaguru.V


#13

i have the same problem :confused:


#14

Hi Sebastian_A,

I uninstalled all java from control panel and re-installed latest version 1.8. Now its working fine for me. Please try.

Thanks,
Rajaguru.V


#15

glad it works… you just need to update your java version to latest one… and you’ll be fine…


#16

Thanks a lot to you Anicacute09 :slight_smile:


#17

welcome… really glad that I help…


#18

I have same problem, updated Java - this didn’t help