Ant Build Android Project With Dependencies - android

I'm trying to build an app (let's call it android-app) with a dependency on an SDK (let's call it sdk) via Ant. Eclipse is not installed on this computer (for reasoning, it's a CI box with Jenkins).
Both projects are in two completely separate directories side by side. android-app is in the directory ~/.jenkins/jobs/android-app/workspace and sdk is in the directory ~/.jenkins/jobs/sdk/workspace.
Let's assume both projects are "vanilla" and have not been built with Ant before. I cd to the ../android-app/workspace directory and run android update project -p . --library ~/.jenkins/jobs/sdk/workspace which passes. I then cd to the ../sdk/workspace directory and run android update project -p . which also passes.
At this point I cd back to the ../android-app/workspace directory and run ant clean build. It fails with the error:
BUILD FAILED
/path/to/ant/build.xml:440:
/path/to/sdk/workspace resolve to a path with no project.properties file for
project /path/to/android-app/workspace
... where /path/to is the full path to the directories. I simplified it here.
If I cd to the sdk workspace and open project.properties, I receive the following:
# ProGuard
proguard.config=proguard.cfg
# Project target.
target=android-10
android.library=true
It does exist. So do all of these files:
So, why is this failing? What am I doing wrong? I tried to provide as many details as possible. Please let me know if I can provide anything additional.

Well, I encounter this problem too.
I use strace to find out what the hell is going on and found that the path you specified in project.properties will be appended with your current folder path as its prefix.
For example,
/home/myfolder/project > ant debug
And the library you specified in project.properties is /path/to/library
Then, the path will become
/home/myfolder/project/path/to/library

Just to fill in the answer gap here, my Java version was completely off. I'm super embarrassed.

Related

How to use ant to build with android

I want to set up a ant build for my project. I found a tutorial saying that I need to write the following command in order to prepare for ant build:
android update project -p
then I get the result
Updated local.properties
Updated file ./proguard-project.txt
It seems that there are sub-projects. If you want to update them
please use the --subprojects parameter.
so If I try
android update project -p . --subprojects
then I get:
Updated local.properties
Updated file ./proguard-project.txt
Error: The project either has no target set or the target is invalid.
Please provide a --target to the 'android update' command.
and if I try
ant release
I get
sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var
Can some one please help me in setting up the project with ant.
Thanks
I also had the same problem.
My problem problem got solved by the following command.
android update project --path . --subprojects --target android-19
ANT will automatically set your sdk.dir into correct one.
Don't put anything inside your local.properties.
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
Be sure to have a target set in your projects (main project and libraries as well).
on Eclipse:
Right click on the project -> Properties -> Android and select your target SDK. This means the Android SDK version you are targeting. If you take a look in the manifest.xml, you should see that almost at the beginning:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
This is the target version for your project, and usually is recommended to be as highest (newest) as possible.
After that, be sure that the file project.properties has a line similar to this one:
target=Google Inc.:Google APIs:17
This file will be read by ANT to know the target of your project. You can add that line manually. Actually, I'm pretty sure that will be included automatically if you set the target for the projects in Eclipse (as I said above) before running android update project -p . --subprojects
About this error:
sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var
It means you didn't define the sdk.dir property, which should point to the android sdk root directory in your file system. After running android update project -p . --subprojects it should be generated automatically for all your projects. It's possible that it wasn't due to the previous error. So check all your projects for the file called local.properties and be sure that contains a line similar to this:
sdk.dir=/home/path/to/android/sdk/android-sdk-linux

library resolve to a path with no project.properties file

I'm having trouble building my project with Jenkins and referencing the Sherlock project library.
I can build the project with ant on my local system. The problem seems to be referencing the Sherlock library on the build server.
I pass an environment variable to ant with the relative path to the Sherlock library project:
android.library.reference.1=../../buildlibraries/androidlibraries/sherlock/library
I'm getting this error.
**BUILD FAILED**
/SDK/android-sdk-macosx/tools/ant/build.xml:595:
The following error occurred while executing this line:
/SDK/android-sdk-macosx/tools/ant/build.xml:571:
../../buildlibraries/androidlibraries/sherlock/library resolve to a path with
no project.properties file for project /Users/Jenkins/buildlibraries/androidlibraries/sherlock/library
I checked and a project.properties file does exist at that location.
It has these properties:
android.library=true
# Project target.
target=android-14
I had the same thing happen to me just now. I use both a Windows and Mac to develop with. I watne d to test my project on both platforms. It built just fine on my Windows machine, but broke on my Mac. When I looked at my project.properties in my Android application (not library projects) on the Mac, I saw that my library projects were referenced this way:
android.library.reference.1=LibraryProjects\\my_lib_project
I changed it to the line below, and it worked just fine!
android.library.reference.1=LibraryProjects/my_lib_project
I solved the issue by editing and checking in the project.properties file with the same property: android.library.reference.1=../../buildlibraries/androidlibraries/sherlock/library
I'm not sure why it works. Why would ant care if the property is passed in by Jenkins vs. declared in the project's property file?
Now I have two paths in my project.properties file: one for a local build and one for the build on Jenkins.
I had similar issue with error ../google-play-services_lib resolve to a path with no project.properties file for project. It has to work in Jenkins CI (Cloudbees), so no manual project.properties editing.
My solution was to replace android update lib-project --path ... with ugly but working echo "android.library.reference.1=../../../..$ANDROID_HOME/extras/google/google_play_services/libproject/google-play-services_lib" >> project.properties in Jenkins shell command.
I had this problem because I hadn't downloaded the google play services package using the android tool. When I checked my android sdk directory ($ANDROID_HOME) there was no "$ANDROID_HOME/extras/google" folder.
I fixed this by running android and downloading "Google Play services" found in the extras section.

Adding android library project to an android project prevents Ant from building

I'm adding an android library project to my android app (in this case, Beintoo). It's not mine; It's an external library. However, it doesn't come with a build.xml. Building in Eclipse works fine, but when I attempt to build my app with ant, I get this:
BUILD FAILED
C:\Sandbox\MyProject\build.xml:110: The following error occurred while executing this line:
C:\Sandbox\MyProject\build.xml:41: The following error occurred while executing this line:
C:\Program Files (x86)\Android\android-sdk\tools\ant\build.xml:515: Invalid file: C:\Git\Beintoo-Android\beintoo-android-sdk\BeintooSDK\build.xml
It's perfectly true. The file is invalid, because it doesn't exist. I wouldn't know what to do to add it safely, nor if that's even a good idea.
I have learnt that I can't simply build the library project into a jar. How can I get my project to build in Ant with this library project?
Ok, so, Error 454's answer was close, but not quite right. Since r14 of Android Tools, every library project must have it's own build.xml if it is to be built by Ant, as noted here:
https://groups.google.com/forum/?fromgroups#!topic/adt-dev/Z2e3dY-3Ma0
Running android update lib-project (which, as Error 454 notes, is in the android-sdk/tools folder which should be in PATH) on the library project will add a generic build.xml, and allow the main project to build.
For library projects, you need to browse to the library project root and run:
android update lib-project -p .
The android executable is in the android sdk/tools folder which should be added to your path variable in your OS. Once you run this, the necessary build files will be generated and your ant build should succeed.
Similarly, if your root project doesn't have the necessary build files, you will need to browse to the main project root and run:
android update project -p .
Additionally to the two previous correct answers I had to add --target android-16 because I was getting an "Error: The project either has no target set or the target is invalid."
So in my case
android update lib-project -p . --target android-16
Did it. (replace the 16 as you need)

New android SDK 17 issue in my app?

Today i was update my android sdk to new android adk-17 .
i am facing some problems in this, that is unable to show AddMob in my app, if i remove addmob in the code able to run the app without any errors otherwise not. what is the solution for this, is this bug in new sdk.
this is the Logcat information
Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView in loader
dalvik.system.PathClassLoader[/data/app/com.veritra.iflipout-1.apk]
Maybe the ADK update has messed-up with your project's build-path.
Try removing the admob JAR and add it again to your libs folder, add it to your Build Path and do a Clean Project.
Anyway it's hard to help you without more details on the error you encounter.
EDIT following poster's comment about not having a libs folder:
You should try this:
Remove all references to the AdMob JAR in your project -> your code should not build without error anymore
Create à libs folder at the root of your project
Copy the AdMob JAR into the libs folder
Make sure this AdMob JAR is in your Build Path (this will allow your code to build wihtout error)
(If still not running OK) Right click your project > Android Tools > Fix Project Properties
The 'problem' here is that the SDK is a lot more strict about the libraries. If you do not check the library as 'exported' in eclipse, it is not added to your APK, leading to this nasty class not found exception. You should mark your libraries as exported.
Project Properties | Java Build Path | Order and Export
when I updated my SDK it was total mess. Well, the only I had to change was the PATH in Environment Variables.
http://developer.android.com/sdk/installing.html :
Adding both tools/ and platform-tools/ to your PATH lets you run command line tools without needing to supply the full path to the tool directories. Depending on your operating system, you can include these directories in your PATH in the following way:
On Windows, right-click on My Computer, and select Properties. Under the Advanced tab, hit the Environment Variables button, and in the dialog that comes up, double-click on Path (under System Variables). Add the full path to the tools/ and platform-tools/ directories to the path.
On Linux, edit your ~/.bash_profile or ~/.bashrc file. Look for a line that sets the PATH environment variable and add the full path to the tools/ and platform-tools/ directories to it. If you don't see a line setting the path, you can add one:
export PATH=${PATH}:/tools:/platform-tools
On a Mac OS X, look in your home directory for .bash_profile and proceed as for Linux. You can create the .bash_profile if you don't already have one.

Emma does not generate coverage.ec

I setup Emma and it used to work for me. Then we had source code changes and now it doesn't generate coverage.ec at all. It does generate coverage.em.
Near the end of testing, it has error messages:
[exec] INSTRUMENTATION_CODE: 0
[echo] Downloading coverage file into project directory...
[exec] remote object '/sdcard/coverage.ec' does not exist
BUILD FAILED
/var/lib/jenkins/android-sdk-linux_x86/tools/ant/build.xml:1056: exec returned: 1.
Line 1056 of build.xml is
"{adb}" failonerror="true".
I see that I do have coverage.em on the desktop, which means my code are instrumented.
the command I use under the \test is
ant emma debug install test
This worked for me before. Running code coverage always crashes for me, usually near the end of the unit test, but it'd always get me some coverage. Now it crashes out and doesn't produce coverage.em.
I also tried to access /sdcard/ and it's perfectly accessible and writable.
This has blocked me for days, any input would be much appreciated. I am also new to all this Android, Ant and Emma, so thanks!!
Update:
I just cleaned up the environment and ran the command again.Now coverage.em is no longer generated either. Which tells me the source code are not instrumented. But the command I used above should instrument project, its test project, install and start test. I didn't change emma def in build.xml except to change the coverage.ec location to /sdcard/coverage.ec. This is because by default it goes to /data/data, and I don't have permission to access data/data on this phone
I am using r15 of Android SDK, and the default build.xml. I only changed the path to coverage.ec to /sdcard/coverage.ec. To run instrumentation
Go to main_project
$andriod update project -p .
Go to main_prject\test
$android update project -m ../ -p .
To start code code
$ant emma debug install test
It generated main_project-instrumented.apk and test_project-debug.apk. Both are installed and I can see it executes testing.
You have to make a test project with the android command line tools first.
Create Project & Test Project
Assuming your project is stored in D:\AndroidProject and your programming against android API level 8. First you use this command to create the project:
android update project --path ./ --name blabla~ --target android-8 --subprojects
Then create an folder for the test project and navigate into that folder:
mkdir Android_test
cd Android_test
Then create the android test project with the below command
android create test-project --main ../AndroidProject --path ./
Ant building with emma coverage report (with root)
Execute this command (from jenkins select and build step) to get a build done with emma reporting:
ant emma debug install test
Caution : For this to work you have to connect rooted device or emulator, then execute ant command!
Change Build xml file (so no root is required)
If you don't want to root your device an alternative solution is to alter the location of these coverage reports. For this you should modify the build.xml file.
(you should googling about that for more information, briefly explained here)
Open the build.xml -> find the location where the coverage.ec file is stored. In most cases this will be stored in /data/data/com.example.Android/coverage.ec
The problem here is that the /data/data/~~~ path is protected (hence the required root).
anyway~ you can get a coverage.html file in your test project folder/bin. The next steps explain how to change this to save this file on the /sdcardinstead!
You can open your build.xml file and at the last line ~ you can find the command import ~~~ build.xml which means that your build.xml file will import anoother build.xml file.
The other build.xml file is part of the android SDK and is located at ${Android-sdk}/tools/ant/build.xml.
Required changes for build.xml file
We can't change this file (without getting into trouble) so instead copy the complete file to an alternative location or directly into your projects build.xml file.
Don't forget to adapt or change the import statement in your build.xml file whatever you choose to do.
This is what you need to change in that new build.xml file:
Erase the import= ~~build.xml
Erase the first line which is xml=ejkwjkw?e jw ""project = "android_rule" ~~ ~blabla)
and last line /project
update address to /sdcard/coverage.ec
Then, you can get coverage.ec file~
I ran into this issue after updating my SDK to r16: Emma code coverage not working in r15 of tools
and this fixed it for me:
ant all clean emma debug install test
But I am unsure if you have the same problem.
I don't have permission to access data/data on this phone
Is it a non-rooted device? Note that the build says:
WARNING: Code Coverage is currently only supported on the emulator and rooted devices.
Maybe you can't work around this limitation by just changing the location of the coverage file. Does it work on a virtual device?

Categories

Resources