I exported my project to build.xml in order to use ant.
When I execute 'ant debug' from the command line it outputs Target "debug" does not exist in the project.
What to do?
If you are trying to build with the auto generated ant scripts from android. You need to do an android update project on the project in question and then use the build.xml file that is generated from that.
To do this:
Go to the project in question with a terminal or command prompt.
Then type the following command android update project -p . This will update the current project that you are inside.
The command above also assumes you have the android.bat location on your path. If you do not, you need to use the entire path to your android.bat location. Which should be similar to android-sdk/tools/android.bat.
Related
I've got an older Android project (still using Eclipse) that I need to build from the command line. It just builds a library (.jar file), not an application (.apk file). I installed ANT, but since there's no build.xml file it doesn't do anything.
All the examples I've found say to use the "android" command to generate build configurations, but I do not have the "android" command on my PC and searching on "download android command" didn't product any useful results.
Where does one get the "android" command? Do I actually need it in my case, or will a simple generic build.xml file of some kind do the trick?
The answer is simple but not exactly easy to find (IMHO), thus this posting.
By default, the Android SDK adds its "platform-tools" sub-directory to your path but the "android" command is in the "tools" sub-directory. So one just needs to manually edit the PC's PATH environment variable to add the "tools" directory.
i am trying to build my first training application for android using only sdk tools. I am using this tutorial: https://developer.android.com/training/basics/firstapp/running-app.html
I am in my project folder which was generated with android create project command.I am using windows 8.1 64 bits.
Unfortunately when i am trying to run gradlew.bat assembleDebug i an got error:
'gradlew.bat' is not recognized as an internal command or external command,operable program or batch file.
I don't know what is going on. I add platform-tools and tools to my path. I would be grateful for help!
When i am using gradle -v i am getting information about gradle. Byt gradlew.bat is not working.
Find the directory where gradlew.bat present and add it your the Environment path.
I found gradlew in he below path and it works!!!!
C:\Program Files
(x86)\Android\android-sdk\tools\templates\gradle\wrapper\
Just do this, this solved my problem before.
Open Control Panel
Go to System → Environment Variables
In PATH add the following entry at the beginning: %SystemRoot%\system32;
I am new to phonegap the tutorials I have referred to says that there should be a cordova.jar file inside the phonegap-2.9.1\lib\android path. But I don't have it in this phonegap 2.9.1 version.
Can I download the cordova.jar from anywhere or is there any alternative?
Someone please help me.
Thanks.
First, you need the following requisites, for sure are covered if you have been playing with phonegap/cordova for a while ;)
Java JDK 1.5 or greater
Apache ANT 1.8.0 or greater
Android SDK http://developer.android.com
And then, to generate the cordova-2.9.1.jar file, follow the next steps:
Download and extract the phonegap-2.9.1.zip file.
In a terminal/cmd window go inside the recently extracted directory:
$ cd phonegap-2.9.1\lib\android\framework\
Execute the following commands (you need android sdk and ant already configured in your system path):
$ android update project -p . -t android-17
If required add the --subprojects parameter:
$ android update project -p . -t android-17 --subprojects
You get a message like this:
Updated project.properties
Updated local.properties
build.xml: Found version-tag: custom. File will not be updated.
Updated file D:\work_NEW\phonegap-2.9.1\lib\android\framework\proguard-project.txt
Updated and renamed default.properties to project.properties
Updated local.properties
No project name specified, using Activity name 'DroidGap'.
If you wish to change it, edit the first line of build.xml.
Added file D:\work_NEW\phonegap-2.9.1\lib\android\framework\bin\build.xml
Added file D:\work_NEW\phonegap-2.9.1\lib\android\framework\bin\proguard-project.txt
Finally run:
$ ant jar
Blablabla....
jar:
[jar] Building jar: xxx\phonegap-2.9.1\lib\android\framework\ cordova-2.9.1.jar
BUILD SUCCESSFUL
Total time: 4 seconds
Done!!!!! The file is ready! And you can find this and other information reading a file inside the phonegap-2.9.1.zip:
phonegap-2.9.1\lib\android\README.md
Since 3.x version phonegap has changed a lot. I suggest you to install 3.3 version and create a proyect following the steps described in the offical page.
Also, you can download cordova from cordova web page, add to path, and create a proyect using terminal:
cordova create app_name
cordova platform add android || cordova build android
In 3.3.0 version, You can get cordova-3.3.0.jar file by following these steps:
Go to Command Prompt:
$ cd %HOMEPATH%/.cordova/lib/android/cordova/3.3.0/framework
$ android update project -p
$ ant jar
After executing these commands you will get cordova-3.3.0.jar in framework folder i.e.
=> %HOMEPATH%/.cordova/lib/android/cordova/3.3.0/framework/cordova-3.3.0.jar
I am trying to automate the android build process using Jenkins
I am using the following site to achieve this
Link to site
I am successfully able to Build it on my own machine. Initially i got error saying that build.xml file not found (build using ant requires this file). So i execute "android update project". So it automatically generate all necessary file for ant.
Now my problem begins when i tried to host my repo to remote server and tried to build from another machine. The error it is giving is the sdk.dir is not correct. When i analysed the project folder ther is a file called local.properties which contains the SDK path of my first machine which is wrong for other machines. So i add that file to gitignore. Now that file is not tracking and because of this the build is failing.
So is there any way to automatically generate the files that is necessary for ant after jenkins is cloning project from the remote repo?
From the website you link to, they precisely explain how to configure sdk.dir:
Configuring the environment
When jenkins builds your project with Ant, it needs to know where your
android sdk folder is. To do this, click Advanced on the Ant target
build step you just configured and add the following variable to the
Properties field. sdk.dir=/opt/android-sdk-linux/
Don’t forget to substitute the value of the variable with the correct
location where the Android SDK is installed on your build server.
Job configuration is done. Click Save. Time to test your build.
We also build android apps with Jenkins, and also need to edit the local.properties.
In my case, I have the file updated with the path to SDK by the Jenkins build itself. Just before the build starts.
You can use a simple sed command on linux or echo the content on windows (overwriting content).
Example flow:
SCM - get sources
Edit the local.properties (as suggested before)
Run ant build
Note - if you are using the "Invoke Ant", you should add an "Execute Shell" step before to deal with the editing of the local.properties.
I hope this helps.
Yes.
If you install the Android Emulator Plugin for Jenkins, you can add the "Create Android build files" build step to your job.
This will automatically detect any Android app, test or library projects in your Jenkins workspace and add/update the build.xml and local.properties files as necessary.
Alternatively, if you're using the Ant build step and already have the build.xml in your repository, you can ignore the need to create a local.properties file, by specifying the sdk.dir property yourself in the Advanced Ant options.
You can configure ant properties in jenkins. So you can specify all properties of your local.properties through the jenkins job configuration.
Of course you will have to install the android sdk on the jenkins build server.
Please read this for info on how setting ant properties with jenkins.
It's not a good practice to put the local.properties under source code management since multiple developers and CI will have different values for those properties.
you can edit the local.properties file in the jenkins workspace folder to the correct sdk path
I think you want to add the build step "Create Android build files" to your configuration. Place it before the ant build.
This invokes the android update project and android update lib-project. Make sure you referenced your library dependencies in the project.properties with relative paths. Like this:
# Project target.
target=Google Inc.:Google APIs:19
android.library.reference.1=../external-libs/google-play-services_lib
android.library.reference.2=../external-libs/android-support-v7-appcompat
After executing the command to create a project...
./create <PATH_TO_PROJECT_DIR> <COM_PATH> <PROJECT_NAME>
I get the error message:
An unexpected error occurred: ANDROID_BIN="${ANDROID_BIN:=$( which android )}" exited with 1
Deleting project...
Troubleshooting responses:
(acconrad provided a smart checklist here for solving Cordova errors...)
Did you download the correct version of PhoneGap from the correct LOCATION? It appears as if
there are versions of PhoneGap that do not come packaged with
Cordova-2.x.0.jar, which is necessary to run the script. Download here
to obtain PhoneGap with the correct JAR file.
I have followed the instructions at the official Apache Cordova API Documentation site and downloaded the cordova-android repository from github. The official documentation does not say anything about this jar file and as such I have not executed it.
Did you already create the folder? The documentation claims that you
can use this command as long as the new folder is blank. This is not
true. Make sure the folder does not exist before attempting to create
the project.
Fresh folder path, never created.
Do you have the latest version of Ant? You will need Ant 1.8.0 or
greater to run PhoneGap with Android. Use ant -v to verify your
version.
Ant version 1.8.2, although running the -v flag pops up the following output...
Apache Ant(TM) version 1.8.2 compiled on June 3 2011
Trying the default build file: build.xml
Buildfile: build.xml does not exist!
Build failed
...as if it was trying to build. I assume -v means verbose and ant is trying to build the current director, in which there is no build.xml file, because I'm not building a project with ant, merely finding the version, which is 1.8.2.
Is your .bash_profile/Environment Varibles PATH set properly? The
official documentation has been updated to reflect this, but you will
absolutely need these variables set correctly in order to create the
project.
Both SDK paths have been set & sourced.
Did you update the terminal to reflect your new PATHs? source
.bash_profile or . .bash_profile in your currently open terminal
window so your paths are updated when running the create command.
Haven't restarted but $PATH outputs the correct android-sdk-macosx paths (platform-tools && tools).
Do you have the correct commons-codec? You may receive an accompanying
error referring to a missing commons-codec file, which you can
download here.
No commons-codec accompanying error is being displayed.
The problem was indeed the PATH variables...
/PATH/TO/android-sdk-maxosx/platform-tools
/PATH/TO/android-sdk-maxosx/tools
removed the macosx from the path name.
Correcting these environment variables in ~/.bash_profile solved this problem.
You should modifying the PATH Environment Variable:
For Ubuntu:
$ nano ~/.bashrc
You will now have the Nano text editor enabled on the terminal. Now, at the very top of the file, enter the following:
#AndroidDev PATH
export PATH=${PATH}:~/android-sdk-linux/tools
export PATH=${PATH}:~/android-sdk-linux/platform-tools
https://help.ubuntu.com/community/AndroidSDK
For Mac OS:
look in your home directory for .bash_profile. Create the .bash_profile file if you don't have one.
Look for the PATH environment variable and add the full path to the tools/ directory to the PATH. If you don't see a line setting the PATH, you can add one: export PATH=${PATH}:/tools
https://sites.google.com/site/richgossweiler/home/android-development-notes/installing-the-android-sdk-on-the-mac-os-x
This also happens if the name of the COM_PATH contains an invalid character or does not have 3 namespaces like:
com.example.project
This is probably because of a wrong PATH. You should edit environment variables in ~/.bash_profile.
Refer this Blog post for a detailed explanation.