Nullpointerexception while ionic cordova run android


#1

Getting nullpointerexception when executing ionic cordova run android --device :


E:\Workspace\Angular\myTabs>ionic cordova run android --device
Running app-scripts build: --address 0.0.0.0 --port 8100 --p 8100 --livereload-port 35729 --r 35729 --iscordovaserve
--externalIpRequired --nobrowser

[13:31:48]  build dev started ...
[13:31:49]  clean started ...
[13:31:49]  clean finished in 18 ms
[13:31:49]  copy started ...
[13:31:49]  transpile started ...
[13:32:04]  transpile finished in 14.96 s
[13:32:04]  preprocess started ...
[13:32:04]  deeplinks started ...
[13:32:04]  deeplinks finished in 61 ms
[13:32:04]  preprocess finished in 66 ms
[13:32:04]  webpack started ...
[13:32:05]  copy finished in 16.44 s
[13:32:45]  webpack finished in 41.65 s
[13:32:45]  sass started ...
[13:32:50]  sass finished in 4.80 s
[13:32:50]  postprocess started ...
[13:32:50]  postprocess finished in 17 ms
[13:32:50]  lint started ...
[13:32:50]  build dev finished in 61.72 s
> cordova run android --device
ANDROID_HOME=C:\Users\ghanendra\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_51
Subproject Path: CordovaLib
[13:33:03]  lint finished in 12.38 s
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_1n7tz8l3280mv8kwgyclznwu1.run(E:\Workspace\Angular\myTabs\platforms\android\build.gradle:137)
Checking the license for package Android SDK Build-Tools 26 in C:\Users\ghanendra\AppData\Local\Android\sdk\licenses

License for package Android SDK Build-Tools 26 accepted.

Preparing "Install Android SDK Build-Tools 26".


BUILD FAILED

Total time: 8.785 secs
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> java.lang.NullPointerException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> java.lang.NullPointerException (no error message)

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


[ERROR] Cordova encountered an error.
        You may get more insight by running the Cordova command above directly.

[ERROR] An error occurred while running cordova run android --device (exit code 1).

I have been searching for a solution, tried manually adding gradle to following path by running gradle wrapper command:

C:\Users\g\AppData\Local\Android\sdk\tools\gradle

Also tried the instructions given at this link

Updated all sdk tools using sdk manager inside the android studio.

I have android studio installed(also able to build andriod native apps using it) and path to sdk tools and ANDRIOD_HOME configured inside the system environment variables.

Please help me figure out how to run the ionic apps on Android.


#2
  • Run the same command with --verbose and --debug.
  • What does ionic cordova requirements return?
  • What is your ionic info output?

#3

Hi, i got following in cmd window:

E:\Workspace\Angular\myTabs>ionic cordova run android --verbose --debug
[DEBUG] Loading global plugin @ionic/cli-plugin-proxy
[DEBUG] Throwing PLUGIN_NOT_INSTALLED for global @ionic/cli-plugin-proxy
[DEBUG] Loading local plugin @ionic/cli-plugin-cordova
[DEBUG] Loading local plugin @ionic/cli-plugin-ionic-angular
[DEBUG] Getting plugin info for ionic
[DEBUG] Getting plugin info for @ionic/cli-plugin-cordova
[DEBUG] Getting plugin info for @ionic/cli-plugin-ionic-angular
[DEBUG] Checking for latest plugin version of ionic@latest.
[DEBUG] Checking for latest plugin version of @ionic/cli-plugin-cordova@latest.
[DEBUG] Checking for latest plugin version of
        @ionic/cli-plugin-ionic-angular@latest.
[DEBUG] Latest version of ionic@latest is 3.4.0.
[DEBUG] Latest version of @ionic/cli-plugin-ionic-angular@latest is 1.3.1.
[DEBUG] Latest version of @ionic/cli-plugin-cordova@latest is 1.4.0.
Running app-scripts build: --address 0.0.0.0 --port 8100 --p 8100 --livereload-p
ort 35729 --r 35729 --iscordovaserve --externalIpRequired --nobrowser

[17:29:56]  build dev started ...
[17:29:56]  clean started ...
[17:29:56]  clean finished in 16 ms
[17:29:56]  copy started ...
[17:29:56]  transpile started ...
[17:30:14]  transpile finished in 18.47 s
[17:30:14]  preprocess started ...
[17:30:14]  deeplinks started ...
[17:30:14]  deeplinks finished in 14 ms
[17:30:14]  preprocess finished in 77 ms
[17:30:14]  webpack started ...
[17:30:16]  copy finished in 20.02 s
[17:30:25]  webpack finished in 10.36 s
[17:30:25]  sass started ...
[17:30:26]  sass finished in 1.56 s
[17:30:26]  postprocess started ...
[17:30:26]  postprocess finished in 7 ms
[17:30:26]  lint started ...
[17:30:26]  build dev finished in 30.59 s
> cordova run android --debug
ANDROID_HOME=C:\Users\ghanendra\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_51
Subproject Path: CordovaLib
[17:30:31]  lint finished in 5.24 s
Starting a Gradle Daemon, 1 busy and 1 incompatible and 1 stopped Daemons could
not be reused, use --status for details

The Task.leftShift(Closure) method has been deprecated and is scheduled to be re
moved in Gradle 5.0. Please use Task.doLast(Action) instead.
        at build_1n7tz8l3280mv8kwgyclznwu1.run(E:\Workspace\Angular\myTabs\platf
orms\android\build.gradle:137)
Checking the license for package Android SDK Build-Tools 26 in C:\Users\ghanendr
a\AppData\Local\Android\Sdk\licenses
License for package Android SDK Build-Tools 26 accepted.
Preparing "Install Android SDK Build-Tools 26".

BUILD FAILED

Total time: 31.083 secs

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> java.lang.NullPointerException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> java.lang.NullPointerException (no error message)

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


[ERROR] Cordova encountered an error.
        You may get more insight by running the Cordova command above directly.

[DEBUG] !!! ERROR ENCOUNTERED !!!
[ERROR] An error occurred while running cordova run android --debug (exit code
        1).



E:\Workspace\Angular\myTabs>

#4

Hey, I ran the cordova command only this time and got some more output, please have a look:

E:\Workspace\Angular\myTabs>cordova run android --info --debug --verbose --stacktrace
No scripts found for hook "before_run".
No scripts found for hook "before_prepare".
Checking config.xml for saved platforms that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at E:\Workspace\Angular\myTabs\platforms\android\re
s\xml\config.xml
Merging project's config.xml into platform-specific android config.xml
Merging and updating files from [www, platforms\android\platform_www] to platforms\android\assets\www
Wrote out android application name "MyApp" to E:\Workspace\Angular\myTabs\platforms\android\res\values\strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (0.0.1): 1
Wrote out Android package name "io.ionic.starter" to E:\Workspace\Angular\myTabs\platforms\android\src\io\ionic\start
er\MainActivity.java
Updating icons at platforms\android\res
Updating splash screens at platforms\android\res
This app does not have additional resource files defined
Prepared android project successfully
No scripts found for hook "after_prepare".
Checking config.xml for saved plugins that haven't been added to the project

ANDROID_HOME=C:\Users\ghanendra\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_51
Subproject Path: CordovaLib
Running command: cmd "/s /c "E:\Workspace\Angular\myTabs\platforms\android\gradlew.bat cdvBuildDebug -b E:\Workspace\
Angular\myTabs\platforms\android\build.gradle -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m -Pandroid.useDe
precatedNdk=true""
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_1n7tz8l3280mv8kwgyclznwu1.run(E:\Workspace\Angular\myTabs\platforms\android\build.gradle:137)
Checking the license for package Android SDK Build-Tools 26 in C:\Users\ghanendra\AppData\Local\Android\Sdk\licenses
License for package Android SDK Build-Tools 26 accepted.
Preparing "Install Android SDK Build-Tools 26".

BUILD FAILED

Total time: 1.989 secs
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> java.lang.NullPointerException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Command finished with error code 1: cmd /s /c "E:\Workspace\Angular\myTabs\platforms\android\gradlew.bat cdvBuildDebu
g -b E:\Workspace\Angular\myTabs\platforms\android\build.gradle -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx204
8m -Pandroid.useDeprecatedNdk=true"
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> java.lang.NullPointerException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    at ChildProcess.whenDone (E:\Workspace\Angular\myTabs\platforms\android\cordova\node_modules\cordova-common\src\s
uperspawn.js:169:23)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:498:12)