Problems building cca android app on mac - android

I've recently updated a few dependencies on my mac after a while not doing much cca development and now the "cca run android" command is no longer working on my machine.
I get the following strange error:
BUILD FAILED
<my project path>/platforms/android/build.xml:90: Cannot find /usr/local/tools/ant/build.xml imported from <my project path>/platforms/android/build.xml
Total time: 0 seconds
<my project directory>/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: ant with args: debug,-f,<my project directory>/platforms/android/build.xml,-Dsdk.dir=/usr/local
It's looking for a build file that doesn't exist. I'm concerned about the section that says -Dsdk.dir=/usr/local. Clearly it should be looking at my android home directory, which seems to be set properly:
$ echo $ANDROID_HOME
/usr/local/opt/android-sdk
And if that variable was being set properly, it would find one:
ls $ANDROID_HOME/tools/ant/build.xml
/usr/local/opt/android-sdk/tools/ant/build.xml
Has anyone run into this recently using recent versions of cca with android? Hoping there's some obvious mistake I'm making that can be easily remedied.

I got a response from the MobileChromeApps developers on their github issue tracker. It turns out that the sdk.dir was not being set by the $ANDROID_HOME variable, but instead by the $PATH variable that matches the first android executable. By fixing my path to move $ANDROID_HOME before anything else in the path it fixed the issue, and they filed a bug to prioritize $ANDROID_HOME in a future build.

Related

Can't get Android to run in Ionic because of a PATH error I don't understand.

I get this error message now.
Error: ANDROID_HOME is set to a non-existant path:
at /Users/SubjectiveEffect/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/lib/check_reqs.js:162:19
My .bash_profile looks like this:
export ANDROID_HOME=/Users/SubjectiveEffect/Development/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
and the path to the android SDK (that I got from here: https://developer.android.com/sdk/index.html#Other
is indeed "Users/SubjectiveEffect/Development/android-sdk-macosx".
I just cannot understand why I'm getting this error. I've changed the .bash_profile according to the other advice on this site (and others). How can it be wrong?
When I use "echo $PATH" I get this:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Development/adt-bundle-mac/sdk/platform-tools:/Development/adt-bundle-mac/sdk/tools:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools
What is going on?
When you echo $PATH the output is showing multiple locations for the required platform-tools and tools folders (that contain Android SDK etc that are needed to build your project)
I've removed the semicolons for clarity - the following locations are all in your PATH
/Development/adt-bundle-mac/sdk/platform-tools
/Development/adt-bundle-mac/sdk/tools
/Development/adt-bundle/sdk/platform-tools
/Development/adt-bundle/sdk/tools
none of which match up with what you have in your .bash_profile It might be as simple as a stale environment, quite possible if you've only just edited your .bash_profile - the file is only run when you start a new Terminal session so open a new Terminal window (or if you're getting this error in your IDE then try a close / restart) and try building again.
If you're still having problems can you run echo $PATH from a new Terminal window and post your entire .bash_profile?

Cordova Android Install On Linux

I've been pulling my hair out for the past two days trying to get cordova to detect and install the android platform for a project.
The specific error:
Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
Command finished with error code 8
I have scoured the net for solutions. Here is the .bashrc file:
export ANDROID_HOME=~/adt-bundle-linux-x86_64-20140702/sdk/platform-tools
export ANDROID_SDK_HOME=~/adt-bundle-linux-x86_64-20140702/sdk/platform-tools
export PATH=${PATH}:~/adt-bundle-linux-x86_64-20140702/sdk/tools
export PATH=${PATH}:~/adt-bundle-linux-x86_64-20140702/sdk/platform-tools
I get the error when running this command:
sudo cordova platform add android -d
Any help would be appreciated!
More Info:
If I run the "android" command, I get the SDK app startup, so I know that works. Ive also installed the latest builders, tools for the SDK.
After a lot of trial an error, it seems the issue was "sudo" all along. Sometimes it's the simplest things that we overlook.
There were also some unnecessary lines in my export commands. The following is all you need:
export ANDROID_HOME=~/adt-bundle-linux-x86_64-20140702/sdk
export PATH=${PATH}:~/adt-bundle-linux-x86_64-20140702/sdk/tools
export PATH=${PATH}:~/adt-bundle-linux-x86_64-20140702/sdk/platform-tools
If you get an error that ANDROID_HOME does not exist, change the location to use the absolute path. ie: /home/user_name/....
My project directory needed to be 777, as well.
Finally, make sure you run the following command:
sudo apt-get install lib32stdc++6
Looks like without it, I get build errors.
Hope this helps anyone else in the future. There definitely was not enough clear answers on the web, before.

phonegap build problems (android)

When I try to build my app, using Linux ElementaryOS (Ubuntu 12.04 (I think?)) I get thousands of errors saying:
rm: could not remove file (code EACCESS)
The results of the following show:
$ phonegap -v
3.5.0-0.20.4
$ cordova -v
3.5.0-0.2.4
$ ant -v
Apache Ant(TM) version 1.8.2 compiled on December 3 2011
Trying the default build file: build.xml
Buildfile: build.xml does not exist!
Build failed
Any suggestions? I've been battling through several errors for about a week now :(
Thanks in advance!
Update
Update I just changes the permissions of platforms/android too 777 (not a great solution I know). It's now giving me the following:
[Error: An error occurred while listing Android targets] { [Error: /var/www/ppl/app/platforms/android/cordova/build: Command failed with exit code 2] code: 2 } –
Okay, after much pain and anguish... I figured it out.
1). I installed ANT after I installed ionic/cordova/phonegap etc, the best order to install everything in is, java, ant, then cordova/phonegap/ionic.
2). I'm using 64-bit Ubuntu, if you are using the same then you need to install several android 32-bit libs.
3). I deleted the entire project (apart from my css, added js files and my html templates), created a new one using $ ionic start test-app then I ran $ ionic platform add android then ran $ ionic run android and it worked.
4). Make sure your paths are correct in ~/.bashrc mine look as followed:
export PATH=$PATH:/home/ewan/adt-bundle/tools
export PATH=$PATH:/home/ewan/adt-bundle/platform-tools
Here's a video that helped me, especially with the 32-bit libs. https://www.youtube.com/watch?v=zEQIwKK7YjY
Don't give up, it's worth it in the end. Best of luck!

Gradle, Android and the ANDROID_HOME SDK location

edit: (aug-2016)
That question is from November 2013 (while Android Studio was still in Developer Preview mode),
Currently (AS v2.2, Aug-2016) during instalation AS asks to choose the SDK folder (or install on their default) and it automatically applies to which ever project you're opening.
That means any possible workaround or fix is irrelevant as the issue is not reproducible anymore.
original question:
we have this project with several modules that is already configured and executes correctly on another developer PC using a wrapper. I cloned the complete git submodules into my machine.
Below it's a directly print of my command line:
$ ./gradlew
FAILURE: Build failed with an exception.
* Where:
Build file '/home/budius/project_name/ActionBar-PullToRefresh/library/build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':ActionBar-PullToRefresh:library'.
> 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: 6.378 secs
$ echo $ANDROID_HOME
/home/budius/Applications/android-studio/sdk
$
so, as you can see the ANDROID_HOME is there. What else do they want? What's wrong here.
running on Ubuntu 13.04
edit:
I already created a local.properties file with sdk.dir=<path> on the project root and it works. But that makes the code harder to port across systems n build server, so the question is still open.
Anyone knows why the ANDROID_HOME is not working and what to do to make it work?
In /my_current_project/, I created a file called local.properties and put inside:
sdk.dir=/my_current_path_to/sdk
In the console I need to do:
set ANDROID_HOME=/my_current_path_to/sdk
On OSX, IntelliJ won't pick up the environment variables you set in your .bash_profile or .bash_rc etc...
Try this, substituting the value of your own sdk location:
launchctl setenv ANDROID_HOME /usr/local/opt/android-sdk
Then restart IntelliJ and Bob's your uncle.
Here is a reference to the problem, stated more generally:
https://emmanuelbernard.com/blog/2012/05/09/setting-global-variables-intellij/
In my case settings.gradle was missing.
Save the file and put it at the top level folder in your project, even you can copy from another project too.
Screenshot reference:
Hope this would save your time.
This works for me:
$ export ANDROID_HOME=/path_to_sdk/
$ ./gradlew
The Android Gradle plugin is still in beta and this may simply be a bug. For me, setting ANDROID_HOME works, but we may be on different versions (please try again with the most recent version and let me know if it works or not).
It's also worth setting the environment variable ANDROID_SDK as well as ANDROID_HOME.
I have seen issues with this on some machines, so we do create local.properties in those cases - I have also noticed that the latest version of Android Studio will create this file for you and fill in the sdk.dir property.
Note that you shouldn't check local.properties into version control, we have added it to our gitignore so that it doesn't interfere with porting the code across systems which you rightfully identified as a potential problem.
For whatever reason, the gradle script is not picking up the value of ANDROID_HOME from the environment. Try specifying it on the command line explicitly
$ ANDROID_HOME=<sdk location> ./gradlew
I faced the same issue, though I had local.properties file in my main module, and ANDROID_HOME environment variable set at system level.
What fixed this problem was when I copied the local.properties file which was in my main project module to the root of the whole project (i.e the directory parent to your main module)
Try copying the local.properties file inside modules and the root directory. Should work.
I came across the same problem when opening a cloned git repository. The local.properties file is automatically added to the .gitignore file as it is specific to the build environment of each machine and is therefore not part of the repo.
The solution is to import the project instead of just opening it after you have cloned it from git, this forces android studio to create the local.properties file specific to your machine:
File >> Import Project >>
MAC OSX:
Open up Terminal and edit the file:
~/.bash_profile
to add:
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
Run:
source ~/.bash_profile
Restart the Terminal and Android Studio
How to do it on MAC OSX:
1) Open up Terminal, and Edit: vi ~/.bash_profile If there is no file there, just add it.
2) Add (Change to YOUR USER NAME and add this):
#Java var home:
JAVA_HOME="/usr/libexec/java_home"
ANDROID_HOME="/Users/<YOUR USER NAME>/Library/Android/sdk"
3) Run source ~/.bash_profile.
4) Run echo $JAVA_HOME; echo $ANDROID_HOME;
5) If your output is:
/usr/libexec/java_home
/Users/<YOUR USER NAME>/Library/Android/sdk
So you are good.
and RESTART android studio!
And,
Make sure that you have java :)
java -version
And gradle :)
gradle --version
Copy the local.properties to root folder and run again.
This worked for me (Ubuntu):
Add ANDROID_HOME=/path/to/android-sdk to /etc/environment.
Reboot.
in windows, I set ANDROID_HOME=E:\android\adt-bundle-windows-x86_64-20131030\sdk
Then it works as expect.
When in Linux, you need to set sdk.dir.
The script uses two different variables.
I have the same problem, seems the sample code can not find the android environment, instead to try to fix that I just remove the sample code from settings.gradle and then the installation goes fine.
after that just import the project in eclipse and that's all :)
In Linux, try to run studio.sh from a terminal and set the ANDROID_HOME in this terminal. This worked for me.
If you are using windows plantform, please try run Android Studio as Administrator
Just delete the sdk.dir inside the local.preoperties file and set the ANDROID_HOME environment variable . It worked for me.
export ANDROID_HOME=/xxx/xxx/ in shell, then use it by System.env.ANDROID_HOME in gradle file.
PS: don't forget the 'export' keywords to make the ANDROID_HOME global.
Your local.properties file might be missing. If so add a file named 'local.properties' inside /local.properties and provide the sdk location as following.
sdk.dir=C:\Users\\AppData\Local\Android\Sdk
I have set the ANDROID_HOME = [PATH_OF_MY_ANDROID_SDK] to my environment variable. That solution works for me.
I have just solved the exact same issue by adding the ANDROID_HOME as a system wide variable.
In Ubuntu it should be in /etc/profile or in a shell script file in /etc/profile.d/
Then logout and login again, now Gradle should recognize the ANDROID_HOME variable.
I came across a similar problem. Somehow, I did not have a build folder in my project. By copying this folder from another project to my project I was having an issue with, this fixed this problem.
Installing Build-Tools 23.0.1 instead of 23.0.2 fixed this issue for me.
solutions:
1 add "sdk.dir=path_of_sdk"
2 execute gradlew with evn variable like following:
$ANDROID_HOME=path_of_sdk ./gradlw
You said that versioning local.properties creates problems for you. I've hacked together a script which uses android command line tool to refresh the local.properties file across the machines that are involved in the production. The android update project command, besides the local.properties produces a lot of unwanted trash (at least for me) which is the reason for all those rm commands at the end of the script.
#!/bin/bash
scname="$0"
echo "${scname}: updating local properties..."
ln -fs src/main/AndroidManifest.xml
android update project -t 24 -p "$(pwd)"
echo "${scname}: ...done"
echo "${scname}: removing android update project junk ..."
rm -v project.properties
rm -v build.xml
rm -v proguard-project.txt
rm -v AndroidManifest.xml
echo "${scname}: ...done"
This script is the first thing we run on any new machine where we code. It has to be run in the root project directory. Of course, android studio may have a GUI way of dealing with this, but I wouldn't know as I use a different editor. I also can't claim that the solution is general, but it "Works For Me" (tm).
I have faced with the same issue on Ubuntu(both local.properties and ANDROID_HOME was added), but build fail persisted. So workaround is to
add following lines
export ANDROID_HOME=/home/<user>/Android/Sdk
export PATH=$PATH:/home/<user>/Android/Sdk/tools
directly to the studio.sh script (inside /usr/local/android-studio/bin)
Maybe it will be helpful.
i encountered the same error but in my case i was cloning a project, the cloned project was built with Android API 22 which i did not install at the time(i had API 24 and 25 installed)........so i had to download the sdk tools for API 22
For Windows:
Add ANDROID_HOME to the Environment Variables:
ANDROID_HOME = C:/Users/YOUR_USERNAME/AppData/Local/Android/sdk
Add %ANDROID_HOME%\platform-tools to the PATH.
On my system (Ubuntu 20.04 after two version upgrades from 19.04) the symptoms were as if gradle (4.4.1 installed from APT repos) ignored ANDROID_HOME environment variable, while picking up the sdk.dir value from local.properties if I created one.
The reason appeared to have been that java command referred to openjdk version "11.0.7". After I installed openjdk-8-jdk package and did update-alternatives --config java to make the default java be version 8 ("1.8.0_252"), gradle started working as expected.
My issue was that directory did not exist. The env vars were set correctly, but the underlying directory did not exist. After opening AS the first time and having it create the directory, everything worked.
echo $ANDROID_HOME
/Users/x/Library/Android/sdk
$ echo $ANDROID_SDK_ROOT
/Users/x/Library/Android/sdk
$ cd $ANDROID_HOME
-bash: cd: /Users/x/Library/Android/sdk: No such file or directory

Phonegap 2.5.0: Error during project creation

I'm trying to follow the Getting Started with Android tutorial on Windows. I'm on step 4. Setup a New Project. I type in ./create c:\projects\test com.example.test test, then receive an error:
An unexpected error occurred: ANDROID_BIN="${ANDROID_BIN:=$( which android )}" exited with 1
Deleting project...
I've modified my PATH system environment variable, adding %ANDROID_HOME%\tools and %ANDROID_HOME%\platform-tools. %ANDROID_HOME% points to c:\adt-bundle\sdk.
I can run the following commands successfully:
java
javac
ant
adb
However, running android results in -bash: android: command not found.
I'm stumped. Anyone know what I'm missing in order to be able to create Phonegap projects?
make sure you can run the commands below from your terminal:
ant -version
java -version
android -h
If you get command not found, you need to fix that first before trying to create Phonegap projects. Once you update your PATH variable, you need to restart the command prompt/terminal before be able to use those commands.
To make things easier, make sure you have ANT_HOME, JAVA_HOME and ANDROID_HOME variable defined too!
Edit:
Make sure you are using Window's command prompt and not cygwin shell.

Categories

Resources