Unable to install android though ionic

I am getting error that java is not installed while java is correctly installed.

$ ionic cordova build android

cordova build android
Android Studio project detected

Running command: “C:\Program Files\nodejs\node.exe” C:\Users\User\baechat\hooks\after_prepare\010_add_platform_class.js C:\Users\User\baechat

(node:11216) UnhandledPromiseRejectionWarning: CordovaError: Failed to run “javac -version”, make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: C:\Program Files\Java\jdk-10;%JAVA_HOME%\bin;

at C:\Users\User\baechat\platforms\android\cordova\lib\check_reqs.js:47:27
at ChildProcess.exithandler (child_process.js:280:5)
at ChildProcess.emit (events.js:180:13)
at maybeClose (internal/child_process.js:936:16)
at Socket.stream.socket.on (internal/child_process.js:353:11)
at Socket.emit (events.js:180:13)
at Pipe._handle.close [as _onclose] (net.js:541:12)

(node:11216) 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:11216) [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.

This is my ionic info

$ ionic info

cli packages: (C:\Users\User\AppData\Roaming\npm\node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 8.0.0
Gulp CLI              : CLI version 3.9.1 Local version 3.9.1

local packages:

Cordova Platforms : android 7.0.0
Ionic Framework   : ionic1 1.3.1

System:

Node : v9.9.0
npm  : 5.6.0
OS   : Windows 10

Environment Variables:

ANDROID_HOME : C:\Users\User\AppData\Local\Android\Sdk;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;

Misc:

backend : pro

See Java is correctly installed

$ java -version
java version “10” 2018-03-20
Java™ SE Runtime Environment 18.3 (build 10+46)
Java HotSpot™ 64-Bit Server VM 18.3 (build 10+46, mixed mode)

Cordova (or Android tooling) only works with JDK(1.)8, not 9 or 10. Install that, then it will work.

do you mean JDK version 8 ?

As far as i know… Java latest release is still at 8 (shit i was horribly outdated)

Your JAVA_HOME is invalid: C:\Program Files\Java\jdk-10;%JAVA_HOME%\bin;

Actually your issue is most likely because of undefined JAVA_HOME in your environmental variable

Follow this instructions
https://confluence.atlassian.com/doc/setting-the-java_home-variable-in-windows-8895.html

JAVA_HOME is a valid directory i have already checked

Same error after installing the JAVA (1.)8 version

$ ionic cordova build android
> cordova build android
Android Studio project detected

Running command: “C:\Program Files\nodejs\node.exe” C:\Users\User\baechat\hooks\after_prepare\010_add_platform_class.js C:\Users\User\baechat

ANDROID_HOME=C:\Users\win8\android-sdks
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161;C:\Program Files\Java\jdk1.8.0_161\bin
studio
Subproject Path: CordovaLib
Subproject Path: app

ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_161;C:\Program Files\Java\jdk1.8.0_161\bin

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
(node:5172) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with exit code 1
at ChildProcess.whenDone (C:\Users\User\baechat\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
at ChildProcess.emit (events.js:180:13)
** at maybeClose (internal/child_process.js:936:16)**
** at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)**
(node:5172) 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:5172) [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.

But now you are running a Java version that could work.

What does ionic cordova requirements say?

$ ionic cordova requirements
> cordova requirements
Android Studio project detected

Requirements check results for android:

Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed
cmd: Command failed with exit code 1
Gradle: installed C:\Program Files\Android\Android Studio\gradle\gradle-4.4\bin\gradle
(node:5024) UnhandledPromiseRejectionWarning: CordovaError: Some of requirements check failed
** at C:\Users\User\AppData\Roaming\npm\node_modules\cordova\src\cli.js:414:27**
** at _fulfilled (C:\Users\User\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:787:54)**
** at self.promiseDispatch.done (C:\Users\User\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:816:30)**
** at Promise.promise.promiseDispatch (C:\Users\User\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:749:13)**
** at C:\Users\User\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:557:44**
** at flush (C:\Users\User\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:108:17)**
** at process._tickCallback (internal/process/next_tick.js:112:11)**
(node:5024) 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:5024) [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.

Fix this.

Best also install a standalone gradle from Gradle | Installation

1 Like

i have installed gradle (4.4) but still facing error with JAVA_HOME please help me out

$ gradle -v

ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_161;C:\Program Files\Java\jdk1.8.0_161\bin

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Java is also installed :-

$ java -version
java version "1.8.0_161"
Java™ SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot™ 64-Bit Server VM (build 25.161-b12, mixed mode)

i am also attaching the JAVA_HOME directory location.

I see a list of directories set as JAVA_HOME. Maybe it only wants one?

so which one shall i remove?

You have 2 options. Try them and let us know which one worked.

both doesnt worked for me :frowning:

$ gradle -v

ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_161\bin

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

$ gradle -v

ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_161\bin

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

You posted the same thing twice.
You should probably test both paths, not the same one twice.

apk has been build but the URL i have pointed on www/index.html file its not opening on the app its only loading. and i have got this logs after running the command

$ ionic cordova build android
> cordova build android
Android Studio project detected

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\img\Thumbs.db

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\lib\awlert\demo\resources\Thumbs.db

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\lib\awlert\demo\resources\android\icon\Thumbs.db

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\lib\awlert\demo\resources\ios\icon\Thumbs.db

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\lib\ionic-ion-tinder-cards\example\www\res\icon\android\Thumbs.db

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\lib\ionic-ion-tinder-cards\example\www\res\icon\bada-wac\Thumbs.db

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\lib\ionic-ion-tinder-cards\example\www\res\icon\bada\Thumbs.db

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\lib\ionic-ion-tinder-cards\example\www\res\icon\blackberry\Thumbs.db

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\lib\ionic-ion-tinder-cards\example\www\res\icon\ios\Thumbs.db

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\lib\ionic-ion-tinder-cards\example\www\res\icon\tizen\Thumbs.db

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\lib\ionic-ion-tinder-cards\example\www\res\icon\webos\Thumbs.db

cp: copyFileSync: could not write to dest file (code=EPERM):C:\Users\User\Desktop\baechat\platforms\android\app\src\main\assets\www\lib\ionic-ion-tinder-cards\example\www\res\icon\windows-phone\Thumbs.db

Running command: “C:\Program Files\nodejs\node.exe” C:\Users\User\Desktop\baechat\hooks\after_prepare\010_add_platform_class.js C:\Users\User\Desktop\baechat

ANDROID_HOME=C:\Users\win8\android-sdks
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161
studio
Starting a Gradle Daemon (subsequent builds will be faster)

:wrapper

BUILD SUCCESSFUL in 26s
1 actionable task: 1 executed
Subproject Path: CordovaLib
Subproject Path: app
Starting a Gradle Daemon (subsequent builds will be faster)

publishNonDefault is deprecated and has no effect anymore. All variants are now published.

File C:\Users\User.android\repositories.cfg could not be loaded.
Checking the license for package Android SDK Platform 26 in C:\Users\win8\android-sdks\licenses
License for package Android SDK Platform 26 accepted.
Preparing “Install Android SDK Platform 26 (revision: 2)”.
"Install Android SDK Platform 26 (revision: 2)" ready.
Installing Android SDK Platform 26 in C:\Users\win8\android-sdks\platforms\android-26

"Install Android SDK Platform 26 (revision: 2)" complete.
"Install Android SDK Platform 26 (revision: 2)" finished.
Download https://repo1.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar

The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
** at build_dvnle02kivhqqebpazfeb5cwn.run(C:\Users\User\Desktop\baechat\platforms\android\app\build.gradle:143)**
:CordovaLib:preBuild
** UP-TO-DATE**
:CordovaLib:preDebugBuild

UP-TO-DATE
:CordovaLib:compileDebugAidl

:CordovaLib:compileDebugRenderscript

:CordovaLib:checkDebugManifest

:CordovaLib:generateDebugBuildConfig

:CordovaLib:prepareLintJar

:CordovaLib:generateDebugResValues

:CordovaLib:generateDebugResources

:CordovaLib:packageDebugResources

:CordovaLib:platformAttrExtractor

:CordovaLib:processDebugManifest

:CordovaLib:javaPreCompileDebug

:CordovaLib:processDebugJavaRes

NO-SOURCE
:app:preBuild
** UP-TO-DATE**

:app:preDebugBuild

:app:compileDebugAidl

:CordovaLib:packageDebugRenderscript

NO-SOURCE
:app:compileDebugRenderscript

:app:checkDebugManifest

:app:generateDebugBuildConfig

:app:prepareLintJar

:app:generateDebugResValues

:app:generateDebugResources

:app:mergeDebugResources

:app:createDebugCompatibleScreenManifests

:app:processDebugManifest

:CordovaLib:processDebugResources

:CordovaLib:generateDebugSources
:CordovaLib:compileDebugJavaWithJavac
Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

:CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug

:app:splitsDiscoveryTaskDebug

:app:processDebugResources

:app:generateDebugSources
:app:javaPreCompileDebug

:app:compileDebugJavaWithJavac
Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

:app:compileDebugNdk

NO-SOURCE
:app:compileDebugSources
:CordovaLib:mergeDebugShaders

:CordovaLib:compileDebugShaders

:CordovaLib:generateDebugAssets
:CordovaLib:mergeDebugAssets

:app:mergeDebugShaders

:app:compileDebugShaders

:app:generateDebugAssets
:app:mergeDebugAssets

:app:extractTryWithResourcesSupportJarDebug

:app:transformClassesWithStackFramesFixerForDebug

:app:transformClassesWithDesugarForDebug

:app:transformClassesWithDexBuilderForDebug

:app:transformDexArchiveWithExternalLibsDexMergerForDebug

:app:transformDexArchiveWithDexMergerForDebug

:CordovaLib:compileDebugNdk

NO-SOURCE
:CordovaLib:mergeDebugJniLibFolders

:CordovaLib:transformNativeLibsWithMergeJniLibsForDebug

:CordovaLib:transformNativeLibsWithIntermediateJniLibsForDebug

:app:mergeDebugJniLibFolders

:app:transformNativeLibsWithMergeJniLibsForDebug

:app:processDebugJavaRes

NO-SOURCE
:app:transformResourcesWithMergeJavaResForDebug

:app:validateSigningDebug

:app:packageDebug

:app:assembleDebug
:app:cdvBuildDebug

BUILD SUCCESSFUL in 4m 9s
47 actionable tasks: 47 executed
Built the following apk(s):
** C:\Users\User\Desktop\baechat\platforms\android\app\build\outputs\apk\debug\app-debug.apk**

I’ve never used Windows, so can’t be more specific, but EPERM would seem to indicate that whatever user you are running the build as does not have write access to the build folder of the project.

now opening app on android after installing shows

Application Error

The connection to the server was unsuccessful. (file://android_asset/www/index.html)

try ionic cordova build android and see what output it gives

check the above msg i have did the same and the output appeared and with that i got apk which is having a problem