Creating apk in ionic on mac

Hello

I’m new to ionic framework and have been trying to create my first hybrid application. By following some tutorials online, somehow, i managed to create my first application. Now, I’m trying to create apk for android devices but when i run ionic cordova run android --prod --release, it gives me error as requirements check failed for jdk 1.8 or greater. Please note that I’ve installed jdk 9.0 ( which is latest, i guess.).

Editor is vscode and machine is mac.

Looking forward to hearing some useful solutions.

Regards
Tanveer Alam

1 Like

Have you tried to install a lower jdk version?

What does ionic cordova requirements output? Is it happy?
What is your ionic info output?

@inesgomes What version do you suggest me to install ?

@Sujan12 , By running ionic cordova requirements command, I’m getting following results

Requirements check results for android:

Java JDK: installed
Android SDK: installed true
Android target: not installed
avdmanager: Command failed with exit code 1 Error output:
Exception in thread “main” java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:213)
at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:200)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
… 5 more

Gradle: installed /Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle

Error: Some of requirements check failed.

ionic info given me following output
cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.12.0
ionic (Ionic CLI) : 3.12.0

global packages:

cordova (Cordova CLI) : 7.0.1

local packages:

@ionic/app-scripts : 3.0.1
Cordova Platforms  : android 6.2.3
Ionic Framework    : ionic-angular 3.7.1

System:

Node  : v6.11.3
npm   : 3.10.10
OS    : macOS Sierra
Xcode : Xcode 8.2.1 Build version 8C1002

Misc:

backend : pro

@tanvralam what are your ANDROID_HOME and ANDROID_SDK_ROOT environment variables? These affect feature detection when executing the Android builds.

@engineerapart, Thanks indeed for the reply.

How can i check these said environment variables ?

@tanvralam execute the following command in your shell where you are running the build, assuming you are on a Linux-based platform:

env | grep ANDROID

If you are on Windows I’m not sure

@engineerapart, I’m on Mac.

@tanvralam Mac is Linux-based :smiley: (actually was forked from Unix - all the same for our purposes)

:stuck_out_tongue:

By running given command, I’m getting following results

ANDROID_HOME=/Users/tanveeralam/Library/Android/sdk

This should not happen. Fix it, then the rest will probably work.
Easiest way to do this is usually to install Android Studio (2.3.3, not 3.0!).

@Sujan12

Now I’ve installed android studio 2.3.3 but still getting the same error. :disappointed_relieved:

@Sujan12

I don’t know exactly how it’s working but by running ionic cordova requirements command, I’m getting following results now

Requirements check results for android:

Java JDK: installed

Android SDK: installed true
Android target: installed android-27,android-26,android-25,android-24,android-23,android-22,android-21,android-20,android-19,android-18,android-17,android-16

Gradle: installed /Applications/Android Studio.app/Contents/gradle/gradle-3.2/bin/gradle

But ionic cordova run android --prod --release command still returns the same error.

ANDROID_HOME=/Users/tanveeralam/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home
Error: Requirements check failed for JDK 1.8 or greater

Any help would be great !!!

Hi all. OK, so I’ve been through this pain. I’d like to think of myself as quite tech savvy. I’m more than at home in the console than I am in the GUI. But (and I know I’m gonna rub some people up the wrong way here) Java is a real PITA. Anyhoo, I’m straying from the subject a little, so back on point…

By far, the easiest solution is to install Android studio. It will download everything you need (even if like me you never open the UI). The right Java, set the paths, etc, the SDK’s and even the emulators. Hit this up to take care of your Mac-Android woes :slight_smile:

https://developer.android.com/studio/index.html

@Scorch

I’ve already installed Android studio ( 2.3 ) and the path is

/Users/tanveeralam/Library/Android/sdk

I get that error all the time. in terminal I do…
export JAVA_HOME=/usr/libexec/java_home -v 1.8
and then ionic build android will work