react-native run-android command failed, but gradlew installDebug work - android

I'm using react-native 0.43.3 on OSX.
I tried to running app on Android and get message
react-native run-android
Scanning 568 folders for symlinks in /Users/ruci.k/project/mayacrew/supermembers/supermembers/node_modules (5ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
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
./gradlew installDebug gave me some errors and fixed it all.
Finally build get successed and app is working on Android device.
But react-native run-android command still not work.
Only ./gradlew installDebug command work.
Is there anything can I check to use react-native run-android command?
I can't understand how could it happened.

Running
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
worked for me

Run the following command
chmod 755 android/gradlew
inside your app root folder
then run
react-native run-android

After you create your react native app ,try
sudo chmod -R 777 node-modules
sudo chmod -R 777 android
export ANDROID_HOME=~/Library/Android/sdk
now run
react-native run-android

Try removing android,ios folders and then do react-native upgrade then try again react-native run-android After that if you get an error like
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
then create a file named local.properties inside the folder
android
and insert the following line sdk.dir =/path/to/Android/Sdk After this everything should be fine
Note: If you have made some changes in android/ios folder please keep its backup before removing the folders

cd android && sudo ./gradlew clean
This worked for me. Try it out and let me know if it helps folks

I have faced the same issue when I have imported the project from the GitHub.
Follow the below steps to run your react-native project in the Android device from the MAC OS
Remove the 'node_modules' folder from the root project.
Run the below command in the project root folder.
npm install
Move to the android folder in the project root folder.
cd android
Run the following commands one after another to give permissions to gradlew file.
chmod +x ./gradlew
xattr -l ./gradlew
xattr -d com.apple.quarantine ./gradlew
Now, come back to project root folder and run the project in android device.
react-native run-android
Now you can see the launched application on your connected Android device/emulator.

In Ubuntu, I have used this command and it worked for me:
sudo react-native run-android

I had the same issue, and just opened the project in android studio, and that's all. Solved!

this issue come from two reasons
1- Permission issue
How to Fix it
sudo react-native run-android
Or
chmod 755 android/gradlew
2- Mismatch java version with Gradle
make sure you are using Java 8 as $JAVA_HOME environment variable
depending on which terminal you are using to run your code at
For zsh shell, export $JAVA_HOME at ~/.zshenv or ~/.zshrc.
For bash shell, export $JAVA_HOME at ~/.bash_profile or ~/.bashrc.
get installed JDK by this command
/usr/libexec/java_home -V
example for using zsh
vi ~/.zshrc
// paste the java export inside it
export JAVA_HOME="JDK_8_Path_from_previous command"
to save your change
:x
make sure your changes applied
source ~/.zshrc
now for testing
echo $JAVA_HOME

You must change your build.gradle:
compileSdkVersion 28
buildToolsVersion "28.0.2"
minSdkVersion 16
targetSdkVersion 27
and add this line:
implementation "com.android.support:appcompat-v7:28.0.0"

Check whether your emulator is connected or not:
set ANDROID_HOME path: E:\android-sdk-windows
set path D:C:\Program Files\nodejs;C:\Program Files\Java\jdk1.8.0_111\bin;E:\android-sdk-windows\platform-tools

go to folder android in terminal
gradlew clean
run react-native run-android

maybe install watchman?
https://github.com/facebook/react-native/issues/10056
Otherwise, for me I actually use 'npm start' inside of the folder. npm will know to run the right command to start react native because it's in a react native directory.

So what i did was to download this jar file from: 1: https://drive.google.com/file/d/1MHSJx-_0RHRzlrXBLAePKeWKQteke0Um/view?usp=sharing and placed it inside android/gradle/wrapper then i went back to the project directory and did npm install i then changed directory to android by doing: cd android then i ran the following commands
chmod +x ./gradlew
xattr -l ./gradlew
Now i went back to the project directory and ran react-native run-android

Go to C:\Users\ [username]
Rename or delete ".gradle"
Then run "react-native run-android"

So here are the three solution for this bug , from which one will most probably solve your issue :
1: Adding local.properties file in your android folder
https://stackoverflow.com/questions/32634352/react-native-android-build-failed-sdk-location-not-found
2: Try deleting .gradle file and then build (react-native run-android)
3: Might be possible that under SDK tools NDK(side by side) and CMake are not installed .
Steps for the same is
Android Studio which include direction for opening sdk manager
Open android folder in Android Studio
Click on the SDK Manager (which is at the third position from the top left )
After opening SDK manager you have to go to SDK Tools Installation image for NDK and CMake
Under SDK Tools select NDK(side by side) and CMake and press the okay button and let the installation complete .
After the close the Android Studio and react-native run-android.

1 . you should have space in your phone
2 . developer option on
3 . USB debugging option also on
4 . check "adb devices" devices is connected or not

I have to perform these steps to get it running.
First install dos2unix
Run dos2unix ./gradlew inside android folder
then run ./gradlew clean
at last run react-native run-android.

For me, this had to do with running low on RAM om my Mac.
in gradle.properties put -XX:MaxPermSize=4096
for example like this:
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m
After that, it runs again.

What worked for me is,
Uninstalling the previous installed app version on the emulator device, and running react-native run-android after.

Check the error messages carefully. It will give a clue to what went wrong. In my case, after installing expo in my react-native project, the MainApplication.java got corrupted. I made a comparison with the a backup (you can check an earlier working commit), then removed the erroring lines.
After this, it worked.

Related

Cordova build android "no android build tools"

So im running into a probelm with cordova
I am running a linux machine trying to build a cordova app how ever,
When i try
$ Cordova build android
I get a the following error
No installed build tools found. Install the Android build tools version 19.1.0 or higher.
How ever i do have it installed
And i have edit my .bashrc & .profile to reflect the changes needed for
$ANDROID_HOME
Am i missing something?
This seems to be an error of the paths:
You need to define paths as:
vim .bashrc
Add the following lines:
export ANDROID_HOME=/Users/user/Software/Android
export PATH=${PATH}:/Users/user/Software/Android/tools
export PATH=${PATH}:/Users/user/Software/Android/platform-tools
Note: When you edit the environment variables you need to reload them.
$source .bashrc //for ubuntu
$source .bash_profile //for mac
Type the following command:
$android
in terminal and hit enter.
If everything is working fine you can try running
$cordova build android
This seems to be a duplicate of the question: questions/31190355/ionic-build-android-error-no-installed-build-tools-found-please-install-the

'gradlew' is not recognized as an internal or external command error in Android Studio terminal

Getting error - 'gradlew' is not recognized as an internal or external command. operable program or batch file. inside Android Studio terminal.
Can anyone please tell why it's not recognizing gradlew
gradlew command is available in your project directory. If you are trying to run this command from somewhere else it will throw error.
Also gradlew command package is automatically generated by Android studio when you create a new project. It will also prompt you to generate new gradle wrapper when you open the project.
you have to use ./gradlew instead of gradlew , if you are using Mac or Linux
It's under the Android folder, so you have to do cd Android first from your project root folder, then :
PS C:\code\my_app\android> ./gradlew signingReport
in vscode do this step
go to your project directory
cd to android
type ./gradlew in your terminal instead of gradlew
voila, it works for windows user
Assume that you app's name is video_compresser, so when you open terminal on Windows PC(because I am trying this on Windows) it shows the prompt like this.
C:\Users\Nuwan\StudioProjects\video_compresser>
If you run gradlew from here you will get the below message
'gradlew' is not recognized as an internal or external command,
operable program or batch file.
so you have to go to android directory by typing cd android command from terminal.
then the prompt should be like this,
C:\Users\Nuwan\StudioProjects\video_compresser\android>
then type gradlew followed by other commands you need and the error should be gone.
Try using,
./gradle clean
./gradle assembleRelease
worked for me.
make sure you have debug.keystore file in
PS C:\code\my_app\android>
before you run
./gradlew signingReport
Instead of the powershell, use the Windows Command Prompt to run the command.
(This is an accidental finding. I used the visual studio code terminal to run the command gradlew assembleRelease to build the apk of a react-native project, but it outputs an error similar to above. I tried bash terminal, again failed to run. Out of curiosity, I used the Windows command prompt, then it worked. Hope this will help if other solutions are not working).
If you use powershell, and the gradlew file is in the terminal current work directory, try .\gradlew instead of gradlew. Powershell don't run the command in the current work directory automatically.
ionic cordova build android --prod --release --alias=cos-android --password=abcd --versionCode=00001 --versionName=00001 -- -- -- --packageType=bundle
cordova build android --prod --release --alias=cos-android --password=abcd --versionCode=00001 --versionName=00001 -- -- --packageType=bundle
gradlew command is only available in your project directory or gradlew file location. If you are trying to run this command from somewhere else it will throw error.
so go to that particular location where gradlew file available
go to android directory by typing
"cd android" in terminal.
then the prompt should be like this,
PS C:\src\offx> cd android
PS C:\src\offx\android>
(//then type) ".\gradlew signinReport"
PS C:\src\offx\android> .\gradlew signinReport
Then you will get your sha keys
I am using windows OS and have to run a Java project in IntelliJ. I used the command prompt in admin mode then it worked for me.

React-Native run-android command issue

When starting android project with React-Native it is giving this error:
React-Native Command run-android unrecognized.Did you mean to run this inside a react-native project?
You can try to do npm install before react-native run-android
First we have to install react-native then upgrade packages if you need and run android.
npm install --save react-native#latest
react-native upgrade
react-native run-android
A lot of developers fail to mention the crucial point,that certain commands require you to be a particular directory. In this case, to "react-native run-android", you have to be in your project directory!
Command run-android unrecognized. Make sure that you have run npm install and that you are inside a react-native project.
I faced this issue, the problem is we need to navigate to or project folder.
example: I created the project in "MyApps" with app name "DemoApp" in D drive
the command line root should be like this:
D:\MyApps\DemoApp>react-native run-android
now it will run with out any issue.
The problem is your android related info is presents inside the app not t=in the main directory.
I was facing the same problem and the above solutions did not work. Try using:
yarn add react-native-cli
First of all please see if devices/emulator is attached and working by following command
adb devices
there should be some devices showing connected
it is better to restart/reconnect you emulator/device and then try to run application again
if not working you can also try
npm install
You need to make sure that you are inside the project like cd AwesomeProject and do npm i and after that execute npx react-native run-android
In my case the problem was that I was in the android folder of my project due to this command cd android && ./gradlew assembleRelease.So the solution was to cd ../ and come to root of project and then running this command
react-native run-android --variant=release
ran fine.
For me the issue was I was not inside the project directory AwesomeProject( Project that I created using this command :
react-native init AwesomeProject )
I got it fixed after adding Android sdk-tools to PATH, and restarting VSCode/Terminal.
/Users/<username>/Library/Android/sdk/build-tools
Earlier my path set to
/Users/<username>/Library/Android/sdk
1.make sure java jdk installed
2.make sure npm installed in your project root folder
3.this works for me

ionic build Android | error: No installed build tools found. Please install the Android build tools

When I run ionic build android command in root of ionic project, I am getting this error:
FAILURE: Build failed with an exception.
Where: Script '/home/javad/Desktop/javadApp/platforms/android/CordovaLib/cordova.gradle'
line: 64
What went wrong: A problem occurred evaluating root project 'android'.
No installed build tools found. Please 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.
javad#javad:~/Desktop/javadApp$ ionic build android
Running command: /home/javad/Desktop/javadApp/hooks/after_prepare/010_add_platform_class.js /home/javad/Desktop/javadApp
add to body class: platform-android
Running command: /home/javad/Desktop/javadApp/platforms/android/cordova/build
ANDROID_HOME=/opt/android-sdk
JAVA_HOME=/usr/lib/jvm/default-java
Running: /home/javad/Desktop/javadApp/platforms/android/gradlew cdvBuildDebug -b /home/javad/Desktop/javadApp/platforms/android/build.gradle -Dorg.gradle.daemon=true
FAILURE: Build failed with an exception.
* Where:
Script '/home/javad/Desktop/javadApp/platforms/android/CordovaLib/cordova.gradle' line: 64
* What went wrong:
A problem occurred evaluating root project 'android'.
> No installed build tools found. Please 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.
BUILD FAILED
Total time: 1.564 secs
/home/javad/Desktop/javadApp/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: /home/javad/Desktop/javadApp/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/javad/Desktop/javadApp/platforms/android/build.gradle,-Dorg.gradle.daemon=true
ERROR building one of the platforms: Error: /home/javad/Desktop/javadApp/platforms/android/cordova/build: Command failed with exit code 8
You may not have the required environment or OS to build this project
Error: /home/javad/Desktop/javadApp/platforms/android/cordova/build: Command failed with exit code 8
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
in ~/.profile i have:
export PATH=$PATH:/opt/android-sdk/tools
export PATH=$PATH:/opt/android-sdk/platform-tools
export PATH=$PATH:/opt/node/bin
export JAVA_HOME=/usr/lib/jvm/default-java
export ANDROID_HOME=/opt/android-sdk
$PATH is:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/android-sdk/tools:/opt/android-sdk/platform-tools:/opt/node/bin
Important issue:
in file:
/home/javad/Desktop/javadApp/platforms/android/CordovaLib/cordova.gradle | line 38:
String[] getAvailableBuildTools() {
def buildToolsDir = new File(getAndroidSdkDir(), "build-tools")
buildToolsDir.list()
.findAll { it ==~ /[0-9.]+/ }
.sort { a, b -> compareVersions(b, a) }
}
just returned /opt/android-sdk/build-tools !!!
in /opt/android-sdk/build-tools folder i have:
android-5.1 folder that extract from:
https://dl.google.com/android/repository/build-tools_r22-linux.zip
I fix this by downloading sdk package called platform-tools and buid-tools using sdkmanager. You can use sdkmanager.exe or if you are using SDK CLI, go to ~\AppData\Local\Android\sdk\tools\bin and run this command:
sdkmanager "platform-tools" "platforms;android-26"
or
sdkmanager "build-tools;27.0.3"
or both
After that you should be able to run ionic cordova run android or ionic build android.
Note: globalize sdkmanager command by adding ~\AppData\Local\Android\sdk\tools and ~\AppData\Local\Android\sdk\tools\bin to your environment variable.
For me running these three commands fix the issue on my Mac:
export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
For ease of copying here's one-liner
export ANDROID_HOME=~/Library/Android/sdk && export PATH=${PATH}:${ANDROID_HOME}/tools && export PATH=${PATH}:${ANDROID_HOME}/platform-tools && export ANDROID_SDK_ROOT=~/Library/Android/sdk
To add Permanently
Follow these steps:
Open the .bash_profile file in your home directory (for example, /Users/your-user-name/.bash_profile) in a text editor.
Add export PATH="The above exports here" to the last line of the file, where your-dir is the directory you want to add.
Save the .bash_profile or .zshrc file.
Restart your terminal. Or run source ~/.bash_profile or source ~/.zshrc depending on your terminal settings.
Adding to bash process for different systems
You are missing android SDK tools. Please try the following:
android list sdk --all
android update sdk -u -a -t <package no.>
Where <package no.> is 1,2,3,n and
-u (--no-ui) # Headless mode
-a (--all) # Includes all packages (also obsolete ones)
-t (--filter) # Filter by package index
as the error says 'No installed build tools found'
it means that
1 : It really really really did not found build tools
2 : To make him find build tools you need to define these paths correctly
export ANDROID_HOME=/Users/vijay/Software/android-sdk-macosx
export PATH=${PATH}:/Users/vijay/Software/android-sdk-macosx/tools
export PATH=${PATH}:/Users/vijay/Software/android-sdk-macosx/platform-tools
3 : IMPORTANT IMPORTANT as soon as you set environmental variables you need to reload evnironmental variables.
//For ubuntu
$source .bashrc
//For macos
$source .bash_profile
4 : Then check in terminal
$printenv ANDROID_HOME
$printenv PATH
Note : if you did not find your changes in printenv then restart the pc and try again printenv PATH, printenv ANDROID_HOME .There is also command to reload environmental variables .
4 : then open terminal and write HALF TEXT '$and' and hit tab. On hitting tab you should see full '$android' name.this verifys all paths are correct
5 : write $android in terminal and hit enter
Please install the Android build tools version 19.1.0 or higher.
The following commands can update Android SDK on Ubuntu quickly and fix the above error:
android list sdk --all
android update sdk -u -a -t 19
android update sdk -u -a -t 20
I fix the error by changing the ANDROID_HOME to
C:\Users\Gebru\AppData\Local\Android\Sdk from wrong previous directory.
I know this doesn't look related, especially given the error message, but I fixed this by installing a newer version of the Android SDK Build tools.
2018
The "android" command is deprecated.
try
sdkmanager "build-tools;27.0.3"
This work for me, as #Fadhil said
In my case, the Enviroument Variable ANDROID_HOME was pointed to wrong (old) directory. I reallocated to correct one. In my case
ANDROID_HOME=F:\Program Files (x86)\Android\android-sdk
For me, the problem was that ANDROID_HOME was pointing to an old Android SDK path. After installing Android Studio, I had to update ~/.bash_profile accordingly for MAC (El Capitan)
export ANDROID_HOME="/Users/corneliusparkin/Library/Android/sdk"
Remember to re-start terminal or run this command after updating ~/.bash_profile
source ~/.bash_profile
FOR WINDOW: I have faced this type of issue. But after exploring it solved in my case. I am using window 10. just follow few steps below:
download Android SKD Manager for windows. https://developer.android.com/studio at the
end of this page. It is zip file. after extracting it will show tools directory.
Go to drive C:\ create new folder 'android-sdk'. copy tools folder and past in
C:\android-sdk
open command prompt as Administrator. Go to cd " c:\android-sdk\tools\bin ".
sdkmanager will be show here. type
skdmanager, it will show like this
[=======================================] 100% Computing updates...
after that type "sdkmanager platform-tools" it will create platform-tools directory
in C:\android-sdk
Now set System environment variables: right click on PC select
properties. system settings will popup. click on > Environment Variables. Environment
Variables will popup.
At this window System variables as like this. C:\android-sdk\platform-tools and
C:\android-sdk\tools\bin
run command to build tools sdkmanager "build-tools;27.0.3"
Also make sure java path is defined. I hope it will solve problem.
Type android on your command line and install "Android SDK Build-tools"
I Search this problem for days.... I hope it will be usefull
FINAL SOLUTION:
(I assume that you have installed Oracle-JDK and ANDROID)
open /etc/environment with
sudo nano /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/shoniisra/Android/Sdk/tools:/home/shoniisra/Android/Sdk/platform-tools:/home/shoniisra/Android/Sdk/build-tools:/home/shoniisra/Android/Sdk:/home/shoniisra/android-studio/bin"
JAVA_HOME="/home/shoniisra/java/jdk1.8.0_231"
ANDROID_HOME="/home/shoniisra/Android/Sdk/build-tools/29.0.2"
ANDROID_SDK_ROOT="/home/shoniisra/Android/Sdk"
ANT_HOME="/home/shoniisra/ant/apache-ant-1.9.14"
Save and exit (CTRL+o CTRL+X)
Reload file source /etc/environment
If you recently installed Android you should accept some licences
cd ~/Android/Sdk/tools/bin/
Execute sdkmanager:
./sdkmanager --licenses
Then Accept all, and Finally generate your APK
cd {yourproyect}
sudo ionic cordova build android
I have solved this issue by following steps:
Go to cordova.gradle file
(platform/android/cordovaLib/cordova.gradle)
Search for getAndroidSdkDir() method
Now simply replace System.getenv("ANDROID_HOME") with your real Android SDK path
In build.gradle script it checks if build-tools version is lower than maxVersion from Gradle configuration.
So in my case, I had environment SDK vars set, but my version was higher than allowed.
def highestBuildToolsVersion = buildToolsDirContents
.collect { new Version(it) }
// Invalid inputs will be handled as 0.0.0
.findAll { it.isHigherThan('0.0.0') && it.isLowerThan(maxVersion) }
.max()
In my case the problem was that ANDROID_HOME was pointing to ~/Library/Android/ for some reason.
The correct path is ~/Library/Android/sdk
This problem I solved with the following detail, somehow the android SDK manage installed all the dependencies and necessary files, but forget this `templates` files where is found templates> gradle> wrapper. This set of files is missing.
Path in mac
/Users/giogio/Library/Android/sdk/tools/templates
I had the same problem. I tried all the solutions on this page, but what worked for me was installing the EXACT version of build-tools requested. In my case, I had a later version installed(33.0.0), but in order to make it work I had to download an older one 30.0.3.
This works for me! be careful with the new java versions because they cause error, check that you have everything installed and in your specific directory,
I did not use openJDK
export JAVA_HOME="/usr/lib/jvm/java-8-jdk" \
&& export PATH=$JAVA_HOME/bin:$PATH \
&& export ANDROID_HOME=$HOME/Android/Sdk \
&& export PATH=${PATH}:${ANDROID_HOME}/tools \
&& export PATH=${PATH}:${ANDROID_HOME}/platform-tools \
&& export GRADLE_HOME=/usr/share/java/gradle/bin/gradle \
export PATH=$PATH:$GRADLE_HOME/bin
Linux 4.14.39-1-MANJARO #1 SMP PREEMPT Wed May 2 19:03:39 UTC 2018 x86_64 GNU/Linux
I added <preference name="android-minSdkVersion" value="19" />
to my conf.xml and the build was successful.
The solution for this question is here
https://docops.ca.com/devtest-solutions/8-0-2/en/installing/setting-up-the-mobile-testing-environment/preinstallation-steps-for-mobile-testing/
Please follow this steps, and solve your problem.
The Android SDK package contains a component called compile tools. The mobile test requires at least version 19.0.1, 19.1.0 or 20.0.0.
If these versions are not installed with your ADT package, you may receive an error message when creating a mobile asset in the DevTest Workstation:
Mac IOS
Edit ~/.bash_profile by using vi or other shell editor
vi ~/.bash_profile
Add the following lines:
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:~/Software/android-sdk-macosx/tools:~/Software/android-sdk-macosx/platform-tools"
(save the file, and exit)
load those updated env variables to the current shell env:
. ~/.bash_profile
If from some reason you have an old version of the build tools, you can update them from the android development studio:
Configure --> SDK Manager --> select "Android SDK Build-Tools
Check the "Show Package details"
review the versions of this package, update if needed
Well Many people give their answer, some answer is same, some answer id different. I try many answer but they are did not work for me, of course I try from above answer also but did not solve my issue. And I don't know why but I have the same error even my issue solved by this ANSWER. I just want to write it might be helpful for someone.
I have tried all the above solution. None works.
Until I was linked to https://forum.ionicframework.com/t/ionic-v4-no-installed-build-tools-found/152150.
Apparently, you must run the command as root. Sudo is not enough. You need to change to root user before you can run all the commands.
Open Command Prompt Check for ANDROID_HOME path using SET ANDROID_HOME, if not set then set using below command.
SET ANDROID_HOME="C:\Users\VenkateshMogili\AppData\Local\Android\Sdk"
OR
open system environment variables and create new variable as
Variable Name: ANDROID_HOME
Variable Value: C:\Users\VenkateshMogili\AppData\Local\Android\Sdk
and open cordova.gradle file (/platforms/android/CordovaLib/cordova.gradle) and search for getAndroidSdkDir() method and Replace the ANDROID_HOME path ("C:/Users/VenkateshMogili/AppData/Local/Android/Sdk") instead of System.getenv("ANDROID_HOME")
If license problem arises then type below command by opening the command prompt in C:\Users\VenkateshMogili\AppData\Local\Android\Sdk\tools\bin
sdkmanager "build-tools;27.0.3" //<-that will create build-tools folder and licenses folder.
It works for me.
Warning for developers using Virtual Machines
I spent a very long time trying to resolve this issue. I tried everything in this post and many more solutions on the web. However, after many failures and going through what everyone on the web was saying I still couldn't resolve the issue on my VM - which is a Windows 10 image on VMWare Workstation.
After reviewing all the solutions and descriptions of machines/operating systems people were developing on the glaring difference in my setup was I was developing in a VM.
Solution: I pulled all my code onto the host machine (Windows 10 OS), reinstalled all the dependencies, and sure as heck it all worked out first go around. After a lot of research I found some warnings that Android Studio has some known issues around installing properly in some VMs. So if you were like me & tried all solutions (many times over) and nothing worked, but you're in a VM, you may need to consider building on your host (or other physical machine)
This issue also occur if you do an upgrade to you cordova installation.
Check if your log error has something like:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting) <-------------
ANDROID_HOME=/{path}/android-sdk-linux (DEPRECATED)
Using Android SDK: /usr/lib/android-sdk
Starting a Gradle Daemon (subsequent builds will be faster)
In such case, just change ANDROID_HOME to ANDROID_SDK_ROOT in your ~/.bashrc
or similar config file.
Where before was:
export ANDROID_HOME="/{path}/android-sdk-linux"
Now is:
export ANDROID_SDK_ROOT="/{path}/android-sdk-linux"
Don't forget source it: $ . ~/.bashrc after edition.
Check whether you have added android SDK paths to the environment file (.bash_profile). If you installed android studio with default path, then add the below lines to your environment file. In my case, I am using bash so I have updated the .bash_profile
export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd
I wasted a day to resolve this issue and finally I got solution
-First I removed ionic cordova platform android
-Install ionic cordova platform android#8
That's it
create a ~/.bash_profile and ~/.zshrc file.
touch ~/.bash_profile;
touch ~/.zshrc;
edit and copy/paste this in your ~/.bash_profile or ~/.zshrc file
So, go to your file manager and show all hidden files by using Cmd+Shift+. or Cmd+>
i) Edit your .zshrc file
export LANG=en_US.UTF-8
export ANDROID_HOME=/Users/bookwarm/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/sdkmanager
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/platform-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/build-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/bin
export ANDROID_NDK=/Users/{your name}/Library/Android/sdk/ndk-bundle
export JAVA_HOME=$(/usr/libexec/java_home)
ii) Edit your .bash_profile file
export ANDROID_HOME=/Users/{your name}/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/sdkmanager
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/platform-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/build-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/bin
export ANDROID_NDK=/Users/{your name}/Library/Android/sdk/ndk-bundle
export JAVA_HOME=$(/usr/libexec/java_home)
Save your file with file->save like you would save any regular file, after that write this in your terminal
source ~/.bash_profile;
source ~/.zshrc;
Close you terminal and run your command now

Does not recognize android command in path

I'm triying to build my first cordova project, when I'm inside the project folder i tip:
sudo cordova build android
and I get the following error:
[Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.]
ERROR building one of the platforms: Error: /home/veritopsecret/hello/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
when I do echo $PATH I get:
veritopsecret#veritopsecret-SATELLITE-PRO-C50-A-1HQ:~/hello$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/veritopsecret/Escriptori/android-sdk-linux/tools:/home/veritopsecret/Escriptori/android-sdk-linux/platform-tools
I have also modified .profile file, but it stills say that it hasn't android command in the PATH. However, if I just write android, it opens the android sdk manager. Help please!!
As I re-read your question, I see you run sudo cordova build android
I think the issue you have is that you define ANDROID_HOME and add the android tools to the path of your user but then you use sudo to run the build.
sudo runs with elevated privileges using a user which is not your user profile that you are logged with, so the path and ANDROID_HOME are not set. (maybe try sudo echo $PATH to be sure of that).
So if you really wanted to use sudo to build, you would need either to define the vars for the sudo user or use instead sudo -E (see this page for more details : https://wiki.archlinux.org/index.php/Sudo#Environment_variables)
But actually, you should be using sudo only when installing cordova, not when using the CLI.
So, just run cordova build android and everything should be fine.

Categories

Resources