Andorid build error

Hi,
I tried to build and .apk file but, when I run "ionic cordova build --release android"
I get this error.

$ ionic cordova build --release android
Running app-scripts build: --platform android --target cordova
[18:43:32]  build dev started ...
[18:43:32]  clean started ...
[18:43:32]  clean finished in 19 ms
[18:43:32]  copy started ...
[18:43:33]  deeplinks started ...
[18:43:33]  deeplinks finished in 20 ms
[18:43:33]  transpile started ...
[18:43:44]  transpile finished in 11.19 s
[18:43:44]  preprocess started ...
[18:43:44]  preprocess finished in less than 1 ms
[18:43:44]  webpack started ...
[18:43:44]  copy finished in 12.63 s
[18:43:51]  webpack finished in 7.69 s
[18:43:51]  sass started ...
Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to         `undefined` to prevent this warning.
[18:43:55]  sass finished in 3.12 s
[18:43:55]  postprocess started ...
[18:43:55]  postprocess finished in 28 ms
[18:43:55]  lint started ...
[18:43:55]  build dev finished in 22.87 s
> cordova build android --release
[18:43:57]  lint finished in 2.44 s
Android Studio project detected

ANDROID_HOME=C:\Users\Kuba\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\java\jdk-9.0.4
(node:2648) UnhandledPromiseRejectionWarning: CordovaError: Requirements check failed for JDK 1.8 or greater
    at E:\project\test\platforms\android\cordova\lib\check_reqs.js:370:19
    at _fulfilled (E:\project\test\platforms\android\cordova\node_modules\q\q.js:854:54)
    at self.promiseDispatch.done (E:\project\test\platforms\android\cordova\node_modules\q\q.js:883:30)
    at Promise.promise.promiseDispatch (E:\project\test\platforms\android\cordova\node_modules\q\q.js:816:13)
    at E:\project\test\platforms\android\cordova\node_modules\q\q.js:624:44
    at runSingle (E:\project\test\platforms\android\cordova\node_modules\q\q.js:137:13)
    at flush (E:\project\test\platforms\android\cordova\node_modules\q\q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
(node:2648) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an as        ync function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2648) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are n        ot handled will terminate the Node.js process with a non-zero exit code.

How to fix it?

Install Java JDK (but not version 9, that one is not supported).
Running ionic cordova requirements should give you some additional information.

Thank you for replying,
when I runned "ionic cordova requirements"
I got this:

$ ionic cordova requirements
> cordova requirements
Android Studio project detected


Requirements check results for android:

Java JDK: installed
Android SDK: installed true
Android target: not installed
cmd: 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.<init>(SchemaModule.java:156)
        at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
        at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(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 E:\Program Files\Android\Android Studio\gradle\gradle-4.1\bin\gradle
(node:16988) UnhandledPromiseRejectionWarning: CordovaError: Some of requirements check failed
    at C:\Users\Kuba\AppData\Roaming\npm\node_modules\cordova\src\cli.js:414:27
    at _fulfilled (C:\Users\Kuba\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:787:54)
    at self.promiseDispatch.done (C:\Users\Kuba\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:816:30)
    at Promise.promise.promiseDispatch (C:\Users\Kuba\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:749:13)
    at C:\Users\Kuba\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:557:44
    at flush (C:\Users\Kuba\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:108:17)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
(node:16988) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:16988) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Two things:

  1. Install standalone gradle from http://gradle.org/install/
  2. You have to install the Android targets via the SDK manager.

It will only work if ionic cordova requirements is happy.

How to install Android targets?

I tried to install it and gradle, and now I get this error:

[10:36:18]  lint finished in 2.61 s
Android Studio project detected

(node:7988) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'manifest' of undefined
    at removeOldOptions (E:\project\animacje\plugins\cordova-universal-links-plugin\hooks\lib\android\manifestWriter.js:48:32)
    at Object.writePreferences (E:\project\animacje\plugins\cordova-universal-links-plugin\hooks\lib\android\manifestWriter.js:27:19)
    at activateUniversalLinksInAndroid (E:\project\animacje\plugins\cordova-universal-links-plugin\hooks\afterPrepareHook.js:65:25)
    at E:\project\animacje\plugins\cordova-universal-links-plugin\hooks\afterPrepareHook.js:45:11
    at Array.forEach (<anonymous>)
    at run (E:\project\animacje\plugins\cordova-universal-links-plugin\hooks\afterPrepareHook.js:41:17)
    at module.exports (E:\project\animacje\plugins\cordova-universal-links-plugin\hooks\afterPrepareHook.js:18:3)
    at runScriptViaModuleLoader (C:\Users\Kuba\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:188:18)
    at runScript (C:\Users\Kuba\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:164:16)
    at C:\Users\Kuba\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:132:20
(node:7988) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7988) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.



cordova requirements gives this:

Requirements check results for android:
Java JDK: installed
Android SDK: installed true
Android target: not installed
cmd: 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.<init>(SchemaModule.java:156)
        at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
        at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(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 E:\Program Files\Android\Android Studio\gradle\gradle-4.1\bin\gradle

I gotta Apis from 4.0.1 to 6.01 installed in android studio