Ionic issue: cant build android app - android

in a simple example of building an ionic app for android when i executed the command:
ionic build android
the terminal display this (im on ubuntu 16.04): Error: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
searching for the answer in internet i already define de ANDROID_HOME path and that things, here is my bashrc file:
ANT_HOME="/usr/share/ant"
ANDROID_HOME="/home/cristopher_ramirez/Android/Sdk"
PATH=$PATH:$ANDROID_HOME/tools
PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
PATH="$PATH:$ANT_HOME/bin"
even i modify the profile file and set the path there but that doesn't work too.
i already download the android targets from 18 to 25 (nougat) but that doesn't work either
anyone have any suggestions? i tried a lot of stuff but nothing works for me.
EDIT: i solve the problem:
first i have to install the latest version of gradle, then i set the
path of gradle in the bashrc file (after doing that refresh it with
source ~/.bashrc)
then you have to give root permission to cordova with this command sudo chown -R $(whoami) /home/USERNAME/.cordova
finally i reconfigured the cordova configuration for android and that just worked for me.
Gradle and cordova are the ones you have to focus to solve this problem.

I think you need to set the path untill the sdk tool itself,
My android_home is C:\Program Files (x86)\Android\android-sdk\tools
for exemple
Even if your logic is the same idea

Related

React Native: JAVA_HOME is not set and no 'java' command could be found in your PATH

I've followed step by step the official Getting Started. I started from a clean linux install and installed everything required as per the "Building Projects with Native Code" tab. I have also read the troubleshooting section. I've already created the project using the terminal.
This is the error when I run react-native run-android:
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
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
It does not find JAVA_HOME because the latest versions of Android Studio don't require Java to be installed in the system. Instead an internal JRE is used.
Duplicate disclaimer: I've already read this question. This is not what I want. I know how to set the Java home. I just want to run the react project WITHOUT having to install a separate Java.
Questions:
How could I find the internal Java inside the Android Studio folder so that I could point JAVA_HOME to it?
If not possible, could I open and run the project inside the android folder with Android Studio? How would I refresh this project after modifying the React JavaScript code in the parent folder?
Windows 10:
Android Studio -> File -> Other Settings -> Default Project Structure... -> JDK location:
copy string is shown, such as:
C:\Program Files\Android\Android Studio\jre
In the file locator directory window, right-click on "This PC" ->
Properties -> Advanced System Settings -> Environment Variables... -> System Variables
click on the New... button under System Variables, then type and paste respectively:
.......Variable name: JAVA_HOME
.......Variable value: C:\Program Files\Android\Android Studio\jre
and hit the OK buttons to close out.
Some installations may also require JRE_HOME to be set in the same way.
To check, open a NEW black console window, then type echo %JAVA_HOME%. You should get back the full path you typed into the system variable. Windows 10 supports spaces in the filename paths for system variables very well and does not need ~tilde eliding.
I'll answer my own questions and sponfeed my fellow linux users:
1- To point JAVA_HOME to the JRE included with Android Studio first locate the Android Studio installation folder, then find the /jre directory. That directory's full path is what you need to set JAVA_PATH to (thanks to #TentenPonce for his answer).
On linux, you can set JAVA_HOME by adding this line to your .bashrc or .bash_profile files:
export JAVA_HOME=<Your Android Studio path here>/jre
This file (one or the other) is the same as the one you added ANDROID_HOME to if you were following the React Native Getting Started for Linux. Both are hidden by default and can be found in your home directory. After adding the line you need to reload the terminal so that it can pick up the new environment variable. So type:
source $HOME/.bash_profile
or
source $HOME/.bashrc
and now you can run react-native run-android in that same terminal. Another option is to restart the OS. Other terminals might work differently.
NOTE: for the project to actually run, you need to start an Android emulator in advance, or have a real device connected. The easiest way is to open an already existing Android Studio project and launch the emulator from there, then close Android Studio.
2- Since what react-native run-android appears to do is just this:
cd android && ./gradlew installDebug
You can actually open the nested android project with Android Studio and run it manually. JS changes can be reloaded if you enable live reload in the emulator. Type CTRL + M (CMD + M on MacOS) and select the "Enable live reload" option in the menu that appears (Kudos to #BKO for his answer)
I think the right way to find the internal Java used by the Android Studio is to
Open Android Studio
Go to File->Other Settings->Default Project Structure/JDK Location:
and copy what ever string is specified there
This will not require memorising the folder or searching for java and also these steps wil take of any future changes to the java location by the Android Studio team changes I suppose
I'm using Ubuntu 20 on my machine, I have got the same problem the thing that worked for me was:
sudo apt-get install default-jre
you can verify that if the installation was successful or not by:
java --version
you are gonna see something like this in your terminal
openjdk 11.0.12 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+7-Ubuntu-0ubuntu3)
OpenJDK 64-Bit Server VM (build 11.0.12+7-Ubuntu-0ubuntu3, mixed mode, sharing)
It is located on the Android Studio folder itself, on where you installed it.
Please add the JAVA_HOME in the System variable no in the user variable
Create the Variable name as JAVA_HOME
Please use these format in the value box --> C:\Program Files\Java\jdk(version) what you have or downloaded.
I fixed this issue by installing jre, I have jdk already installed but jre was not installed.
For those still not able to set JAVA_HOME from Android Studio installation, for me the path was actually not in C:\...\Android Studio\jre
but rather in the ...\Android Studio\jre\jre.
Don't ask me why though.
Environment variables jre location snippet
For ubuntu 16.0+
You can find the jre folder in android studio on this path /snap/android-studio/current/android-studio/jre
add the following line in your .bashrc or .bash_profile
export JAVA_HOME=/snap/android-studio/current/android-studio/jre
type
sudo nano $HOME/.bashrc
or
sudo nano $HOME/.bash_profile
after this execute the following line to in your terminal where you are executing the npx react-native run-android to reload the terminal with the new changes
source $HOME/.bashrc
or
source $HOME/.bash_profile
All I did is go to my project directory from the cmd (command prompt) I typed java -version.it told me what version it was looking for. so I Installed that version and I changed the path to were the jdk of that version was located .
apparently the system variables were not in sync with the user
variables
run as admin on command prompt and set the variable
i also saw some tips to close the node window and the vscode terminal for
the variable to take effect
tip from this site
https://confluence.atlassian.com/doc/setting-the-java_home-variable-in-windows-8895.html
setx -m JAVA_HOME "C:\Progra~1\Java\jdk1.8.0_XX"
and then
echo %JAVA_HOME%
For fish users:
Open ~/.config/fish/config.fish;
Include line set JAVA_HOME /home/ronald/Documents/android-studio/jre and set PATH $PATH $JAVA_HOME;
Re-open fish terminal.
Welcome :)
After adding the environmental variable , please restart the editor. It may save your ton of time.
Make sure you have java installed
your path is wrong
do this:
export | grep JAVA
THE RESULT: what java home is set to
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
follow the path to see if the directories are correct
i did this in my terminal:
open /Library
then i went to /Java/JavaVirturalMachines
turns out I had the wrong "jdk1.8.0_202.jdk" folder, there was another number...
4. you can use this command to set java_home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
I ran this in the command prompt(have windows 7 os):
JAVA_HOME=C:\Program Files\Android\Android Studio\jre
where what its = to is the path to that jre folder, so anyone's can be different.
what I did to solve this on windows was to go to the environment variables and set the variable name to JAVA_HOME and then set the variable value to C:\Program Files\OpenJDK\openjdk-8u312-b07
then I set the path to C:\Program Files\OpenJDK\openjdk-8u312-b07\bin
From Android Studio, go to File, Settings, "Build, Execution, Deployment", Build Tools, Gradle. You should see the path to your JDK there, as visible in the screenshot (tested on Android Studio version 2020.3.1). Set an environment variable called JAVA_HOME containing that path (just google "set an environment variable" and followed by your Operating System name).
for those who are new to react native development
please set JAVA_HOME like this
instead of
C:\Program Files\Java\jdk1.8.0_301\bin
just remove "\bin" from path
C:\Program Files\Java\jdk1.8.0_301 after removing \bin
Guys after fight a lot to find the solution, including pass for many of that articles. I just realized that when you extract the Android SDK it doesn't come inside the folder cmdline-tools/latest and doesn't matter the place that I put the folder, opt/Androd_SDK, $HOME/Android_SDK the sequence of the error were the same. Until I got this error running:
➜ bin ./sdkmanager -version
Error: Could not determine SDK root.
Error: Either specify it explicitly with --sdk_root= or move this package into its expected location: /cmdline-tools/latest/
So, basic the solution was add the content of the SDK zip inside of the folders cmdline-tools/latest.
Once you do this, SDK and all the commands will work normally. Just don't forget to finish the configuration, like create the environment of the Android SDK, JAVA and so on.
An awesome article is that one:
https://medium.com/#khairold/setting-up-react-native-on-linux-without-android-studio-a65f3e011bbb
;)
if someone still facing similar issue and looking for an answer for the same? I would like to share the solution which worked for me. And by the way I haven't installed JAVA JDK/SDK in order to resolve the issue.
I am using Visual Studio code to develop react-native apps (using nox player for android app testing), I ran into the similar issue:
Issue:
$
› Building app...
$
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
$
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
C:\Users...\android\gradlew.bat exited with non-zero code: 1
Resolution: In package.json file I have changed "main": "index.js" to "main": "node_modules/expo/AppEntry.js" it worked for me.
It would be great if this solution helps anyone, let me know for any additional information.
Make sure you have installed the following:
Java
JDK
JRE
If you use Ubuntu, maybe its helpful this tutorial. You have solution for how to solve error ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH..
There are many solutions found for Windows or Mac OS on internet to resolve this error. I'm using Ubuntu 22.10 kinetic
Solution:
Go to your Android Studio folder, find folder named jbr, copy all content folder, and if you don't have, create a folder named jre and copy in jre folder, all contents from jbr folder. Case close. Error solved.
java is not set
Video

Cordova run android : ANDROID_HOME not set and android not in my path

When i run for android, i see this error :
ERROR: Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
But this "variable" are ok. "Android" launch SDK manager and ANDROID_HOME redirect to my sdk folder.
I don't understand this error.
FYI my export :
export ANDROID_HOME=`brew --prefix android`
export PATH=${PATH}:$ANDROID_HOME/bin
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
I answer me !
My solution :
sudo chown -R your-user /usr/local/lib/node_modules/cordova
Remove and add platform
Ubuntu 14.04
gedit /root/.bashrc
add line
export JAVA_HOME=/usr/lib/jvm/java-8-oracle/
ANDROID_HOME=/root/android/sdk/
export ANDROID_HOME=$ANDROID_HOME
PATH=$PATH:$ANDROID_HOME/tools
PATH=$PATH:$ANDROID_HOME/platform-tools
PATH=$PATH:$ANDROID_HOME/build-tools
IN TERMINAL
source ~/.bashrc
Resolveu pra mim/Solved for me!
When my environment is OK (which means that running 'android' via CLI will open the android sdk manager), but I still get this error...
I do the follow:
1 - Remove the platform Android from your project cordova platform remove android
2 - Then I just run again phonegap run android (it'll add the platform Android automatically)
Took me longer than I care to admit to solve this problem, so I thought I'd share how I got this working on Mac for the more novice users such as myself and also those who have not installed with Homebrew:
1) Open your bash profile file (the path to finding this file is 'User/.bash_profile', the name of your file may be .profile or something similar).
2) Add a path to wherever you have saved the Android SDK (you may add something like this: 'export PATH=${PATH}:/Applications/adt-bundle/sdk/platform-tools:/Applications/adt-bundle/sdk/tools' or you may add something like this: 'export PATH=${PATH}:/Desktop/adt-bundle/sdk/platform-tools:/Desktop/adt-bundle/sdk/tools').
Make sure the file name 'adt-bundle' shown in the path above is the name you have saved for the folder! If it isn't, either save the folder with this name, or alter the path to reflect what you have saved the folder as.
3) Try again. You might encounter some further errors, I resolved mine by visiting this page: Cordova 3.5.0 Install Error- Please Install Android Target 19 I typed 'Android' in the terminal to head straight to the package manager in Eclipse. After installing the required version the command worked and installed the Android package to my Cordova application.
I found the following pages very helpful in coming to the above conclusions:
-Understanding the path (needed a refresher on using path! Last time I had to bother with this was ages ago when installing the rbenv Ruby environment): http://help.exercism.io/understanding-path.html
-Setting up for Android (where I found the path): http://docs.phonegap.com/en/edge/guide_platforms_android_index.md.html#Using%20Plugman%20to%20Manage%0APlugins
No 'sudo' required.
I had to close and re-open my windows console (or open a new console), and then open the SDK manager (ran android), after which a bunch of updates and installs had to complete.
For me following steps work :
sudo chown -R your-user /usr/local/lib/node_modules/cordova
export PATH=$PATH:/users/your-user/android-sdks/tools
and then update your android if it is not updated to latest version.
http://blog.codersight.com/2015/05/error-androidhome-is-not-set-and.html
For anybody like me who has tried everything in the answers and have all the environmental variables set up but still gets an error. You might need to remove and add the android platform to your project with the cordova CLI.
cordova platform rm android
cordova platform add android

The command 'android' failed

I've read this: Cordova and setting Android using command line
and that How to add android to cordova platform? PATH error? and generally speaking whole documentation. I've added both 'platform-tool' and 'tool' paths, installed android 4.4 and I'm still getting the error from the tittle when I'm trying cordova platform add android to my current project ( in cmd and in netbeans ).
The only thing I haven't done is adding java and ant to path. I was trying with ;%JAVA_HOME%\bin;%ANT_HOME%\bin but still those commands aren't recognizable.
What else can I do?
EDIT:
I've added java and ant to PATH. This is what I get in cmd:
C:\xampp\htdocs\mobile_maps>cordova platform add android
[Error: The command `android` failed. Make sure you have the latest Android SDK
installed, and the `android` command (inside the tools/ folder) added to your pa
th. Output: ]
Second EDIT:
i also get 'xcopy' is not recognized as an internal or external command even though I've added %SystemRoot%\System32; %SystemRoot%; %SystemRoot%\System32\wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0 . I really don't know what else I can do..
usually this happens when:
1. Java is not installed
2. Java is not exported (no JAVA_HOME env variable) or paths are wrong
3. only 64bit version of Java is installed
to fix install 32bit support on your system.
and (as comments below) relog in Windows to environment changes take effect.

An error occurred during creation of android sub-project because a path is not found

I'm trying to do phonegap build android and I have this message :
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] adding the Android platform...
[error] An error occured during creation of android sub-project. Path not found
Phonegap is looking for "C:\Documents and Settings\corbg\.cordova\lib\android\cordova\3.0.0\bin\create". There is nothing under the directory "3.0.0". I installed cordova like this npm install -g cordova.
I have the some problem when I run cordova platform add android.
Did I missing something?
In Windows machine you have to delete .cordova directory under
C:\Users\user_name\
I have face the same issue, then i corrected my application path, afterthat it is worked out for me.
If you are using win 7 then add the Android ADK path in
open the mycomputer -> Properties -> Change Settings-> Advanced -> Environment Variable -> User variable for ....-> path
add the Android ADK path here like as following
C:\AndroidDev\adt-bundle-windows-x86-20131030\sdk\tools; C:\AndroidDev\adt-bundle-windows-x86-20131030\sdk\platform-tools
also add JAVA_HOME and ANT_HOME.
- Abdul Jabbar
Did you set your PATH variable? Sometimes this error occurs in Windows when the PATH variable is not set correctly to access "java" and "ant" exes. If you want to test if they are correctly set, you can simply execute both (from any folder in your command line):
> java
or
> ant
and both programs should be found.
It was a problem with my proxy. Cordova create a .cordova directory and try to download something on the internet. The download did not work. Next time, it check if there is a .cordova directory. It don't try to redownload something because the directory exist and it show the error.
I removed the .cordova directory and I solved my problems with proxy. Now, everythings works.
What solved the issue for me was having 2 directories on my PATH, the android platform-tools and tools.
In my pc those folders were at
C:\Program Files (x86)\Android\android-sdk\tools
C:\Program Files (x86)\Android\android-sdk\platform-tools
Also make sure you have the following environment variables
JAVA_HOME (C:\Program Files\Java\jdk1.7.0_51)
ANT_HOME (C:\Program Files\apache\apache-ant-1.9.3)
ANDROID_HOME (C:\Program Files (x86)\Android\android-sdk\platform-tools)
I removed the .cordova folder under my user folder but I'm not quite sure if that helped as well.
These links may help you
An error occured during creation of android sub-project
android' is not recognized as an internal or external command
I had the exact same problem for a different reason. I had an old version of ant (1.7.1). At least version 1.8.2 is needed for the build to work.
its either due to improper installation or no installation of ANT or JAVA. But moreover we need to add Android SDk and prepare Android Targets via SDK manager before going through this.
This is because you haven't installed ANT!
download it from here and install it step by step
https://ant.apache.org/manual/install.html
Then running the last command it will install the dependencies needed.

How to add android to cordova platform? PATH error?

I am trying to add android as a cordova platform so that I can build apps with phonegap. When I tried to add android thus:
$ cordova platform add android
I received this error message:
[Error: The command android failed. Make sure you have the latest
Android SDK installed, and the android command (inside the tools/
folder) added to your path. Output: /bin/sh: android: command not
found ]
I do have the latest Android SDK installed, so I suppose I need to add android to my path. I've googled on how to do that, and searched this forum, but I have little knowledge of command line use and I don't understand the answers.
If someone could provide very simple steps to add android to my path, I would be most grateful.
There's step-by-step instructions on the PhoneGap Doc's. Check it out here, and then go to Step 3B. I linked to the 2.8 version of PhoneGap since from a quick look it doesn't seem to explain how to set up PATH on the 3.0 version docs.
I just figured this out. You need to use the path where your android tools are actually installed. Mine happen to be in the default location (and I'm using x64) so, /Applications/adtbundle name/
Just see for yourself!
I was running into a rather silly problem here. The path that I cut and pasted had the adt-bundle listed as "adt-bundle" (as one might expect :)) but I never changed the name of the directory as it was downloaded, which was "adt-bundle-mac-x86_64-20131030."
Additionally, the path ($PATH) that I cut and pasted into my .bash_profile began with "/Development" when it should have begun with "~/Development" since the Development directory was in my home directory.
I don't know if anyone else might find this info useful, but it was a relief to me when I realized that I just needed to correct the paths I'd specified in .bash_profile.
Its very easy. Just Download the android SDK, later set the path android sdk having folder tools and platforms tools in the system variables. Now later the set the path of ANDROID_HOME in the user variable. That's it. Now you can add, run , build your android platform.
On MAC - I got this problem after installing Android Studio (it was working before).
I had to do:
touch ~/.bash_profile; open ~/.bash_profile
and then add the line
export PATH=$PATH:/Users/<USR>/Library/Android/sdk/tools
and restart terminal.
If you used Eclipse to install and manage Android SDK then do following:
Open Window->Android SDK Manager in Eclipse and in new window you will be able to see SDK Path on the top
Now you should include this path as ANDROID_HOME system variable and export /tools and /build-tools it to system PATH variable
On OS X you can include system variables like following:
In Terminal run nano ~/.bash_profile (because probably the .bash profile is not create yet, it will we created in root folder of your User)
In my case SDK path was '/Users/markusila/android-sdks'
Insert following code, but using your SDK path, into the editor opened
export ANDROID_HOME=/Users/YOUR_USER_NAME/android-sdks
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Now simply run . ~/.bash_profile and changes will be included.
In addition to the answers above, don't forget to update the file based in your favorite shell, for example:
ZSH:
1. vi ~/.zshrc
2. Considering that my Android SDK is in "/Users/wils/Library/Android/sdk/" and using vi as editor:
export PATH="/Users/wils/Library/Android/sdk/platform-tools:/Users/wils/Library/Android/sdk/tools:$PATH"
3. Save
4. source ~/.zshrc
BASH:
1. vi ~/.bash_profile
2. Considering that my Android SDK is in "/Users/wils/Library/Android/sdk/" and using vi as editor:
export PATH="/Users/wils/Library/Android/sdk/platform-tools:/Users/wils/Library/Android/sdk/tools:$PATH"
3. Save
4. source ~/.bash_profile
I hope it help somebody else.
Piece \o/

Categories

Resources