So I'm getting this error
~/projects/personal-projects/react/myapp ⌚ 18:12:24
$ react-native run-android --variant=release
Scanning folders for symlinks in /Users/user/projects/personal-projects/react/myapp/node_modules (22ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installRelease)...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 14.706 secs
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 already have my android sdk installed and I also have java installed.
this is what is in my .bach_profile
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
export JAVA_HOME=$Home/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
I've tried adding a local.properties file and added sdk.dir pointing to my Android/sdk folder. But still this error persists. How do I fix this?
Please make file local.properties in folder android then add the following line on file
sdk.dir=/Users/apple/Library/Android/sdk(Please add your sdk path here)
You need to add ANDROID_HOME, JAVA_HOME variables in environmental variables and
tools and platform-tools in path of system to run android apk.
Setting ANDROID_HOME variable in environmental variables.
Setting JAVA_HOME variable in environmental variables.
So the solution to my problem was:
1) add my ANDROID_HOME and JAVA_HOME paths in my .bash_profile
Solution by #rana_sadam
2) Create local.properties and add sdk.dir=<PATH TO ANDROID SDK> inside the android folder.
Solution by #nisarg Thakkar
Related
I've created a new project using react-native 0.63
and when I run on ios simulator everything works fine
but when try to run it on android, it does not work and gives me this error
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:installDebug'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Volumes/SSD2/developer/MyProject/AwesomeProject/android/local.properties'.
* 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 2s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
i install react-native like
react-native Setting up
and this is the output from my react-native doctor
✓ Node.js
✓ npm
✓ Watchman - Used for watching changes in the filesystem when in development mode
Android
✓ JDK
✓ Android Studio - Required for building and installing your app on Android
✖ Android SDK - Required for building and installing your app on Android
- Versions found: N/A
- Version supported: 29.0.2
✖ ANDROID_HOME
iOS
✓ Xcode - Required for building and installing your app on iOS
✓ CocoaPods - Required for installing iOS dependencies
✓ ios-deploy - Required for installing your app on a physical device with the CLI
Errors: 2
Warnings: 0
and if I run npx react-native start then the application runs from android studio smoothly.
Edit
if i run project from terminal source .bash_profile
emulator start but project not run
"--no-jetifier" flag.
Jetifier found 5194 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...
env: sh\r: No such file or directory
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
env: sh\r: No such file or directory
Looks like you need to set the ANDROID_HOME environment variable.
Add the following lines to your $HOME/.bash_profile or $HOME/.bashrc (if you are using zsh then ~/.zprofile or ~/.zshrc) config file:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
Type source $HOME/.bash_profile for bash or source $HOME/.zprofile to load the config into your current shell. Verify that ANDROID_HOME has been set by running echo $ANDROID_HOME and the appropriate directories have been added to your path by running echo $PATH.
Please make sure you use the correct Android SDK path. You can find the actual location of the SDK in the Android Studio "Preferences" dialog, under Appearance & Behavior → System Settings → Android SDK.
References:
https://reactnative.dev/docs/environment-setup 3. Configure the ANDROID_HOME environment variable
Configure the ANDROID_HOME environment variable
The React Native tools require some environment variables to be set up in order to build apps with native code.
Go to Home directory and show hidden files then add the following lines to your ~/.zprofile or ~/.zshrc (if you are using bash terminal, then ~/.bash_profile or ~/.bashrc) config file:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
Run source ~/.zprofile or source ~/.zshrc (or source ~/.bash_profile or source ~/.bashrc for bash) in your root terminal to load the config into your current shell. Verify that ANDROID_HOME has been set by running echo $ANDROID_HOME and the appropriate directories have been added to your path by running echo $PATH.
Restart your system if still error persists.
I'm trying to test and build my android app using Jenkins locally on my machine. I'm on Linux and I launched Jenkins through docker by running the following command:
docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins
Then I opened up my browser and fired Jenkins from localhost:8080. After the initial setup, I added the environment variable with following steps:
Go to Manage Jenkins
Configure System
Go to Global Properties
Check Environment variables
Add ANDROID_SDK_ROOT and ANDROID_HOME environment variables in there
Click Apply and Save
Here's how it looks in Jenkins on my machine:
Basically followed steps from this answer: https://stackoverflow.com/a/29231580/4954322
I also added the same environment variables in my ~/.zshrc file too:
export ANDROID_SDK_ROOT=/home/harry/Android/Sdk/
export ANDROID_HOME=/home/harry/Android/Sdk/
I'm using Use Gradle Wrapper in the Build section of the project configuration with the following commands:
clean
testDebugUnitTes
assembleDebugBuild
After following all of these steps, my build is still failing with message:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable
or by setting the sdk.dir path in your project's local properties
file at '/var/jenkins_home/workspace/MeteorDebugBuild/local.properties'.
My question is how can I fix this error and why the build is still failing with all of this setup?
I think docker containers are isolated from your Jenkins, which means that inside the container there are no environment variables ANDROID_SDK_ROOT and ANDROID_HOME. What you want is:
docker run -e ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT} -e ANDROID_HOME=${ANDROID_HOME} -p 8080:8080 -p 50000:50000 jenkins/jenkins
I have not checked whether it works, but I hope it may be the solution to your problem
I have gone through every similar question on here but can't find a solution. I am testing out react-native on my xubuntu 18.04 and I'm stuck on the last step of launching the app on my phone. I have installed android-sdk and it is located in /usr/lib/android-sdk,
I also see my device attached when I do adb devices
I have added the below inside the .bashrc file and have done $ source ~/.bashrc and restarted the terminal and tried running the app again
export ANDROID_HOME=/usr/lib/android-sdk
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/build-tools/24.0.0:$PATH
I keep getting:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* 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 2s
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 also tried the local file approach with local.properties file and adding sdk..what am I doing wrong here?
Please check the version of the sdk installed and the version of the sdk in the gradle
It should be the same.
It worked for me when giving the same versions.
According to the react-native docs, I have installed Android 8.0 (Oreo) and the rest of the instructions. The only difference is that I have defined the path varibales in .bashrc and not .bash-profile. when I want to run my react-native application I face the Build failed with an exception.
the log looks like below:
sudo react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
the project built for me does not contain the local.properties. but I already have ANDROID_HOME in the Path.
$ printenv | grep Android
ANDROID_HOME=/home/amir/Android/Sdk
PATH=/home/amir/Android/Sdk/tools:/home/amir/Android/Sdk/tools/bin:/home/amir/Android/Sdk/platform-tools:/home/amir/Android/Sdk/emulator
As you mentioned local.properties not exist by default and you should add it to project.
Go to your React native Project -> Android
Create a file local.properties
Open the file
paste your Android SDK path like below
in Windows sdk.dir = C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk
in macOS sdk.dir = /Users/USERNAME/Library/Android/sdk
in linux sdk.dir = /home/USERNAME/Android/Sdk
Replace USERNAME with your user name
Now, Run the react-native run-android in your terminal.
There is an issue with the path. Android Studio SDK is present in my D drive. When I execute the build command I get the following error
"Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: C:\Users\Max\AppData\Local\Android\sdk\tools\templates\gradle\wrapper"
Actual SDK location is in
"D:\Users\Max\AppData\Local\Android\sdk\tools\templates\gradle\wrapper". What should I change in Ionic app such that it looks for SDK in D drive?
Here is the Log
C:\Users\Max\Desktop\Gre\demo\demoApp>ionic build android
Running command: "C:\Program Files\nodejs\node.exe" C:\Users\Max\Desktop\Gre\demo\demoApp\hooks\after_prepare\010_add_platform_class.js C:\Users\Max\Desktop\Gre\demo\demoApp
add to body class: platform-android
ANDROID_HOME=C:\Users\Max\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\java\jdk1.8.0_121
Subproject Path: CordovaLib
Where:
Script 'C:\Users\Max\Desktop\Gre\demo\demoApp\platforms\android\CordovaLib\cordova.gradle' line: 64
What went wrong:
A problem occurred evaluating root project 'android'.
No installed build tools found. Install the Android build tools version 19.1.0 or higher.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Home to update the ANDROID_HOME variable?
Unzip -> copy and paste "tools" >only "templates" folder to your project folder (/Libraries/Android/sdk/tools/)
Example: C:\Users\yourUsers\AppData\Local\Android\sdk\tools
Link http://tools.android.com/recent/androidsdktoolsrevision2530feb2017
Get just the command line tools here : https://developer.android.com/studio/index.html#downloads
Next unzip, copy/paste 'templates' folder in '.../Android/sdk/tools/'