简体   繁体   中英

Ionic cordova build android failed: Exception in thread “main” java.lang.NullPointerException

I'm doing an app on Ionic. The problem is when I want to compile for Android. It gives me an error. I've tried a lot of things and it doesn't work. I'm new in this and maybe I'm doing something wrong, so that's why I'm asking for your help. I'll put all the information here, so I hope you can help me.

I'm using windows 10. This is the error that terminal shows me

    > cordova.cmd build android
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=C:\Users\cesal\AppData\Local\Android\Sdk (recommended setting)
ANDROID_HOME=C:\Program Files\Java\jdk1.8.0_231 (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app
Exception in thread "main" java.lang.NullPointerException
        at org.gradle.wrapper.PathAssembler.getDistName(PathAssembler.java:84)
        at org.gradle.wrapper.PathAssembler.getDistribution(PathAssembler.java:40)
        at org.gradle.wrapper.Install.createDist(Install.java:44)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)
D:\OneDrive\Documentos\Proyecto Fashioner\Aplicacion\fashioner-app\Fashioner\platforms\android\gradlew: Command failed with exit code 1 Error output:
Exception in thread "main" java.lang.NullPointerException
        at org.gradle.wrapper.PathAssembler.getDistName(PathAssembler.java:84)
        at org.gradle.wrapper.PathAssembler.getDistribution(PathAssembler.java:40)
        at org.gradle.wrapper.Install.createDist(Install.java:44)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)
[ERROR] An error occurred while running subprocess cordova.

        cordova.cmd build android exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

The information of my Ionic is this:

ionic info

Ionic:

   Ionic CLI                     : 5.4.2 (C:\Users\cesal\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.10.0
   @angular-devkit/build-angular : 0.801.3
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.0.0

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.2, (and 7 other plugins)

Utility:

   cordova-res : 0.8.1

System:

   NodeJS : v10.16.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.11.3
   OS     : Windows 10

The requirements of cordova are these:

cordova requirements

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-29,android-28,android-27
Gradle: installed C:\Gradle\gradle-5.6.4\bin\gradle

So, I'm not sure if the problem are the environment variables of the system. I added as I saw in different forums, but it doesn't work. Here you have the screenshots:

my environment variables

And this is my PATH variable:

PATH Variable

Please help me, I don't know what to do with this problem. I hope you can help me. Thanks

I spend almost 2 days to find solution

Please remove this in environment variable

hopes it work

CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL

Try cleaning up the project from android studio then rebuild.

Try deleting all folders that are not related to the project. I mean, folders like node-modules, platforms, plugins... That kind of folder (anything that could be inside a .gitignore ). Then, use npm install and wait until it finishes. Test if everything works (using ionic serve if you like) and try again. That worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM