Android Build Failing with Command, but not in Android Studio - android-studio

I'm learning React Native and all of sudden my Android build has started to fail. When I type the command 'react-native run-android' the build fails with following error
FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring project ':app'.
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. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1s Could not install the app on the device, read the
error above for details. Make sure you have an Android emulator
running or a device connected and have set up your Android development
environment:
https://facebook.github.io/react-native/docs/getting-started.html
I have closed and re-opened the terminal, emulator, and Android Studio and made sure that the emulator is running before typing the command. But the build still fails. However if I go into Android Studio and click the 'Play' button (Run App), and the build succeeds and my App is displayed on the Android emulator.
I have also tried copying my project to another folder and all of the same errors still occur. Not a pressing issue, more just of an annoyance so if you have any suggestions that'd be great :)

Same error occurs for me when i change gradle version in build.gradle file.
This error of NullPointerException occurs when the version in build.gradle does not match the version installed in your project root folder.
Then change to the same version resolved the error.

Related

How to fix failing the sync project with Gradle files?

`FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring project ':app'.
Invalid revision: 3.22.1-g37088a8-dirty
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
CONFIGURE FAILED in 54s
Invalid revision: 3.22.1-g37088a8-dirty
`
I am using 3.1.2 version of android studio software. gradle version is 4.6. I am getting above error when I going to build the project. I tried change the gradle version to 4.4 too in gradle-wrapper.properties file. But anything didn't work. Can anyone have any solution as well as a reason why this happen?
As well as i have not set gradle in environment >> system variable. Because I thougtht It is installing to project from android studio. (Please tell something if there any wrong)

Gradle works with Android Studio but cmd script fails

I freshly installed Android Studio and created a HelloWorld project. It works fine. But when I tried to build it via commandline gradlew script found in the project directory it first gave me the error that java is not installed.
After installing the java its now giving me the error:
FAILURE: Build failed with an exception.
What went wrong: Could not determine java version from '11.0.1'.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Following image shows the java version and the command I executed:
Note: I am running it on a Mac with MacOS High Sierra (10.13.6)
This had something to do with my gradle version. I set the version to the latest by going to Project Structure selecting Project from side menu and set the Gradle version to 4.10.2.

WSL gradle pre-pending current directory to Android SDK path

I have set the terminal on Android Studio to use WSL, specifically the Ubuntu one. Running builds from the IDE provided buttons works fine for my project. I decided to start using the terminal more and would prefer to run the builds from there, so I tried running
./gradlew tasks
at the root of the project to test out the Gradle I had installed with sdkman in WSL, but I get the following error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> The SDK directory '/mnt/c/Users/Henry-PC/Desktop/DJ-Cloud/C:\Users\Henry-PC\AppData\Local\Android\Sdk' does not exist.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
Any ideas as to what is wrong with?
Just had this issue myself, I had a local.properties file that specified an incorrect directory.
After removing it entirely gradle is able to locate the Android SDK using the exported ANDROID_HOME environment variable

Gradle build error using react native

I get this error when trying to run an app on an android emulator(Android Studio) from a console window:
$ react-native run-android
Scanning folders for symlinks in C:\Users\Brian\desktop\codervets\arrive-alive\aa_app\node_modules (27726ms)
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
Starting a Gradle Daemon (subsequent builds will be faster)
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring project ':app'.
The SDK directory 'c:\Users\eelia001\AppData\local\android\sdk1' does not exist.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Get more help at https://help.gradle.org
BUILD FAILED in 4m 51s
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
And yet my sdk directory in android studio has the following directory:
C:\Users\Brian\AppData\Local\Android\Sdk
Has anyone else ran into this issue? If so, how do I fix it?
The error states:
The SDK directory 'c:\Users\eelia001\AppData\local\android\sdk1' does not exist.
And you say your SDK is in:
C:\Users\Brian\AppData\Local\Android\Sdk
Since those aren't the same directory, my guess is that's the problem. Are you perhaps logged in as the wrong user? You're going to want to check that ANDROID_HOME is set correctly.
So I'm not sure why it was setup the way it was, but the way to fix it is to go to Advanced System Settings → Environment variables. Thank you to #Rich Churcher for the link to a proper tutorial (it's outdated but the steps worked).

java.security.NoSuchAlgorithmException while building a simple android app using Android Studio

I downloaded the Android Studio and trying to build a simple Login Activity. But the Make Project fails with this error.
Environment: Windows 7 64 bit
Gradle:
trouble writing output: java.security.NoSuchAlgorithmException: SHA-1 MessageDigest not available
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':MyApp:dexDebug'.
Running C:\Program Files (x86)\Android\android-studio\sdk\build-tools\android-4.2.2\dx.bat failed. See output
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I have made sure the Gradle zip was downloaded and installed properly
Any hints what else should I check for?
I was using IBM JDK. Switching to Sun/Oracle JDK fixed the problem.

Resources