JDK Error or something


#1

Cannot build apk, when I run “ionic cordova build android”.
Is it JDK related issue, or something else?

Here is everything from cli:

D:\helloWorld>ionic cordova build android
Running app-scripts build: --platform android --target cordova
[06:51:28]  build dev started ...
[06:51:28]  clean started ...
[06:51:28]  clean finished in 15 ms
[06:51:28]  copy started ...
[06:51:28]  deeplinks started ...
[06:51:28]  deeplinks finished in 16 ms
[06:51:28]  transpile started ...
[06:51:31]  transpile finished in 2.44 s
[06:51:31]  preprocess started ...
[06:51:31]  preprocess finished in less than 1 ms
[06:51:31]  webpack started ...
[06:51:31]  copy finished in 2.58 s
[06:51:35]  webpack finished in 4.39 s
[06:51:35]  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 w
arning.
[06:51:36]  sass finished in 687 ms
[06:51:36]  postprocess started ...
[06:51:36]  postprocess finished in 6 ms
[06:51:36]  lint started ...
[06:51:36]  build dev finished in 7.63 s
> cordova build android
Android Studio project detected

ANDROID_HOME=C:\Users\Am\AppData\Local\Android\sdk
JAVA_HOME=C:\Javas\jdk-9.0.4
(node:248) UnhandledPromiseRejectionWarning: CordovaError: Requirements check fa
iled for JDK 1.8 or greater
    at D:\helloWorld\platforms\android\cordova\lib\check_reqs.js:370:19
    at _fulfilled (D:\helloWorld\platforms\android\cordova\node_modules\q\q.js:8
54:54)
    at self.promiseDispatch.done (D:\helloWorld\platforms\android\cordova\node_m
odules\q\q.js:883:30)
    at Promise.promise.promiseDispatch (D:\helloWorld\platforms\android\cordova\
node_modules\q\q.js:816:13)
    at D:\helloWorld\platforms\android\cordova\node_modules\q\q.js:624:44
    at runSingle (D:\helloWorld\platforms\android\cordova\node_modules\q\q.js:13
7:13)
    at flush (D:\helloWorld\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:248) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This e
rror originated either by throwing inside of an async function without a catch b
lock, or by rejecting a promise which was not handled with .catch(). (rejection
id: 1)
(node:248) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprec
ated. In the future, promise rejections that are not handled will terminate the
Node.js process with a non-zero exit code.
[06:51:38]  lint finished in 1.85 s


D:\helloWorld>

Please help


#2

Install Java 8 instead of Java 9, that should work.


#3

Thanks @Sujan12 I already changed to Java 8.
Now new issue: gradle & Java
Its working and working long time (when I’m online) with some dots.
CLI display:

D:\t5>ionic cordova build android
Running app-scripts build: --platform android --target cordova
[23:21:52]  build dev started ...
[23:21:52]  clean started ...
[23:21:52]  clean finished in less than 1 ms
[23:21:52]  copy started ...
[23:21:52]  deeplinks started ...
[23:21:52]  deeplinks finished in 16 ms
[23:21:52]  transpile started ...
[23:21:54]  transpile finished in 2.46 s
[23:21:54]  preprocess started ...
[23:21:54]  preprocess finished in less than 1 ms
[23:21:54]  webpack started ...
[23:21:54]  copy finished in 2.61 s
[23:21:58]  webpack finished in 4.28 s
[23:21:58]  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 w
arning.
[23:21:59]  sass finished in 721 ms
[23:21:59]  postprocess started ...
[23:21:59]  postprocess finished in 7 ms
[23:21:59]  lint started ...
[23:21:59]  build dev finished in 7.60 s
> cordova build android
Android Studio project detected

ANDROID_HOME=C:\Users\Am\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_144
studio
Subproject Path: CordovaLib
Subproject Path: app
Downloading https://services.gradle.org/distributions/gradle-4.1-all.zip

[23:22:01]  lint finished in 2.00 s
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
                                                                 

But when I’m offline. CLI Display:


D:\t5>ionic cordova build android
Running app-scripts build: --platform android --target cordova
[23:27:42]  build dev started ...
[23:27:42]  clean started ...
[23:27:42]  clean finished in less than 1 ms
[23:27:42]  copy started ...
[23:27:42]  deeplinks started ...
[23:27:42]  deeplinks finished in 16 ms
[23:27:42]  transpile started ...
[23:27:44]  transpile finished in 2.40 s
[23:27:44]  preprocess started ...
[23:27:44]  preprocess finished in less than 1 ms
[23:27:44]  webpack started ...
[23:27:45]  copy finished in 2.55 s
[23:27:49]  webpack finished in 4.20 s
[23:27:49]  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 w
arning.
[23:27:49]  sass finished in 653 ms
[23:27:49]  postprocess started ...
[23:27:49]  postprocess finished in less than 1 ms
[23:27:49]  lint started ...
[23:27:49]  build dev finished in 7.40 s
> cordova build android
Android Studio project detected

ANDROID_HOME=C:\Users\Am\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_144
studio
Subproject Path: CordovaLib
Subproject Path: app
Downloading https://services.gradle.org/distributions/gradle-4.1-all.zip


Exception in thread "main"
java.net.UnknownHostException: services.gradle.org

        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java
:184)

        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
        at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173
)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:180)

        at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
        at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
        at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewH
ttpClient(AbstractDelegateHttpsURLConnection.java:191)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConn
ection.java:1138)

        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
ction.java:1032)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(AbstractDelegateHttpsURLConnection.java:177)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLCo
nnection.java:1546)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:1474)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Http
sURLConnectionImpl.java:254)
        at org.gradle.wrapper.Download.downloadInternal(Download.java:66)
        at org.gradle.wrapper.Download.download(Download.java:51)
        at org.gradle.wrapper.Install$1.call(Install.java:62)
        at org.gradle.wrapper.Install$1.call(Install.java:48)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc
essManager.java:69)
        at org.gradle.wrapper.Install.createDist(Install.java:48)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
(node:3648) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with ex
it code 1 Error output:
Exception in thread "main" java.net.UnknownHostException: services.gradle.org
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java
:184)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
        at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173
)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
        at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
        at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewH
ttpClient(AbstractDelegateHttpsURLConnection.java:191)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConn
ection.java:1138)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
ction.java:1032)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(AbstractDelegateHttpsURLConnection.java:177)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLCo
nnection.java:1546)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:1474)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Http
sURLConnectionImpl.java:254)
        at org.gradle.wrapper.Download.downloadInternal(Download.java:66)
        at org.gradle.wrapper.Download.download(Download.java:51)
        at org.gradle.wrapper.Install$1.call(Install.java:62)
        at org.gradle.wrapper.Install$1.call(Install.java:48)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc
essManager.java:69)
        at org.gradle.wrapper.Install.createDist(Install.java:48)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
    at ChildProcess.whenDone (D:\t5\platforms\android\cordova\node_modules\cordo
va-common\src\superspawn.js:169:23)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
(node:3648) 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:3648) [DEP0018] DeprecationWarning: Unhandled promise rejections are depre
cated. In the future, promise rejections that are not handled will terminate the
 Node.js process with a non-zero exit code.

[23:27:51]  lint finished in 1.91 s

D:\t5>

#4

Finally the APK was built.
I think, when run build command for the first time, it requires lot of downloads.