I have a number of projects that I work on simultaneously.
Every time I build and run one of them, the apk is located as usual in the bin folder.
If I want to copy this apk to some other folder outside the project, I have to do it manually.
I created a single batch file that copies all my projects' apk files to the desired location.
Is there a way to change the output location of the bin folder to somewhere outside the project or more preferably run the batch file after each build?
NOTICE
I am using eclipse with ADT. I have tried to add a builder that executes the batch file. However, when the batch file is run, the apk file is not yet generated. I tried all combinations of options in the builder and all the possible of sequences of builders.
If you are happy just to use Eclipse whilst you are perfecting the build, then switching to the command line for the final build, then with Ant it's really easy to get what you want with very little effort or configuration.
Assumptions
1) Your sources are in an Android workspace and you will end up with two sets of binaries - one made by Eclipse, the other made by Ant will end up outside the workspace as set by a PROPERTIES file
2) You are using SDK14 or 15 (Ant changed in 14)
3) You have Ant installed and in your path - you'll need to have Ant 1.8.2 - this is not the internal one that Eclipse uses, you may have to get it from the Apache site, it's easy to install
Steps
1) Make a sample project from the command line as described in http://developer.android.com/guide/developing/projects/projects-cmdline.html
For example I used:
android create project --target 8 --name Sample15App --path c:\dev
\projects\samples\Sample15 --activity Sample15Activity --package com.me.samplefifteen
This will make a directory and some files which you will use later as a template in your projects
2) Make a sample project in your workspace from Eclipse, I made EclipseSample in one of my workspaces
3) Copy the following files from Sample15App to the root of your EclipseSample project:
build.xml
ant.properties
local.properties
4) Edit ant.properties (which is initially empty) to be like this example:
projectname=EclipseSample
workspace.dir=/dev/projects/EclipseIndigo/AndroidWorkTwo
base.dir=${workspace.dir}/${projectname}
outbasebase.dir=/dev/projects/AntBuilds
outbase.dir=${outbasebase.dir}/${projectname}
ant.project.name=${projectname}
out.dir=${outbase.dir}/bin
layout.dir=${base.dir}/res/layout
source.dir=${base.dir}/src
From this you can see that my workspace is /dev/projects/EclipseIndigo/AndroidWorkTwo
The eclipse project under this is in directory EclipseSample
I want my apks to end up in /dev/projects/AntBuilds/EclipseSample (i.e outbasebase concatenated with projectname -so for other projects you can use a very similar ant.properties file just change projectname)
5) IMPORTANT - EDIT THE build.xml
Comment out or remove the line :
<project name="Sample15App" default="help">
replace it with just
<project>
This just means it will pick up the project name from ant.properties rather than the build.xml and you can use the same build.xml in all your projects, only ant.properties need change
6) try it with "ant debug" should build the debug apks under /dev/projects/AntBuilds/EclipseSample
7) finally if you want to automate the release build (signing and password entering automatically) add lines like
key.store.password=YourPassword
key.alias.password=YourPassword
key.store=c:/users/you/yourrelease-key.keystore
key.alias=release_alias
to the ant.properties and then you just type "ant release"
If you don't add them it will tell you to sign manually and as no password entries were found in 'build.properties' (- that was what ant.properties used to be called pre SDK 14, they should have corrected this!)
You can add new Builders to your project using Project Properties->Builders->New....
One way to do this is to create an ant build (which copies the file), or just a plain old script or batch file.
Related
I have two Android projects, one shared library and the app. Now I want to compile the app with dependency to the library. In Eclipse, it works very well. After that, I upload it via git to my repository and trigger Jenkins to build both projects.
My problem is, that the error occurs: "sdk/android-sdk-linux/tools/ant/build.xml:440: ../shared-lib resolve to a path with no project.properties file for project". That's clear, because in Jenkins the jobs are stored different than under Eclipse.
Another problem is, that Eclipse compiled the shared to ".jar" and Ant compiled it to "classes.jar" (is named in sdk/android-sdk-linux/tools/ant/build.xml).
Ant scripts should allow you to include whatever files you need. In your case I will suggest you move the reference to the shared-lib to local.properties file (this file should also be read by the ant script generated by update-project. Keep the adequate path for jenkins in the repository and modify the file locally for the local built. In the file in the repository you will need to have something like:
android.library.reference.1=../classes.jar
EDIT By the way the suggestion of the second properties file is just because this file is really meant to store location-specific properties.
I fixed it with copy files. The first project builds my shared-lib.jar. The other projects (phone and tablet) copy this file (shared-lib.jar) to there libs-folder and build correctly. But now I have different projects.propertieson the server and my dev-client. This one is not checked in into git.
I've generated ant build.xml for my android project, using android update project --name <project_name> --target <target_ID> --path path/to/your/project/
(according to http://developer.android.com/guide/developing/other-ide.html) and then modified my build.xml (some custom code is there). So my build.xml is in the VCS.
But in order to perform a build I need local.properties file, which is also generated by android update project and so build.xml gets overwritten.
local.properties is not to be checked into the VCS.
Is there a way to only generate the local.properties so that developers (or a build server) can check out the code and build the project using build.xml from VCS?
Thanks!
Do not put local.properties into the VCS: generate it whenever it does not exist already (after a clean checkout, for instance), by running
android update project -p .
so android can generate it with the right path to the sdk. ant.properties or project.properties are meant to be put in VCS with whatever you need fixed on every possible build environment.
If you do not want the build.xml to be modified, change the version-tag entry to something different to its default value, which is 1. For instance:
<!-- version-tag: custom -->
If you have a look at the build.xml comments, it states that by saying:
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
Given that it (in general) only contains a single property, sdk.dir, pointing to the developer's Android SDK root, I'm inclined to say that it's not asking too much for the developers to just create it by hand.
It seems that if only path parameter is specified (for example android update project --path . when called from the project directory) only local.properties and proguard.cfg files are updated.
I am managing and running my android app from command line without using ant, I followed these steps:
generate R.java
compile R.java and all .java files in src to .class files
assembling set of class files into dex file using the command below
dx --dex --verbose --output=./bin/classes.dex ./bin
.class files are in bin directory.
But I'm getting the following errors in these steps:
java.lang.Runtime exception:.\bin file not found
at com.android.dx.cf.direct.ClassPathOpener.process
at com.android.dx.command.dexer.Main.processOne
at com.android.dx.command.dexer.Main.processAllFiles
at com.android.dx.command.dexer.Main..run
at com.android.dx.command.dexer.Main.main
at com.android.dx.command.Main.main
Due to this, I'm unable to create the Classes.dex file.
Can someone suggest a solution for this?
[not using eclipse and ant only through command line]
If you need to "manage your Android projects from command line", when you should use Ant build.
Ant's build.xml is a official standardized way to build Android projects. Ant scripts can do anything you may need to build your project.
If you want most modern build tools for Android, you can look at Gradle for Android projects. Note: today it's still in alpha stage.
Try entering the full path instead of the relative path.
Also you must put the class files inside a directory named exactly like it's package name. for example for com.test.me.MyActivity you must use com/test/me/MyActivity.class
And since we are on the topic, remember that dx can only work with class files created using Java6 (or less) so if you are using java7 to compile your code, add "source 1.6 target 1.6" parameters to your command line.
I maintain an Android app and am not using Eclipse. I am not using Eclipse. I am using ant and build.xml and build.properties.
I have places my .jar file into the libs/ directory. My code compiles just dandy. But when I run it on the emulator, the output APK does not include the .jar, so I get a runtime stacktrace:
ERROR/AndroidRuntime(470): java.lang.NoClassDefFoundError: com.google.ads.AdView
my build.properties looks like this:
jar.libs.dir=libs
And the libs/ directory contains my .jar file.
What needs to be in build.xml so that the external .jar file is included in the APK?
Edit: In theory this answer should work, but it doesn't for me. Is it out of date? What gives? How to add external jar libraries to an android project from the command line
I just came over a similar problem and noticed that libraries should not be placed in "myprojectdir\lib". When I moved them to "myprojectdir\libs" everything started to work.
It turns out that I needed to upgrade the version of ant I was using to 1.8. During the compile process, I had been getting this error message:
Warning: Reference out.dex.jar.input.ref has not been set at runtime,
but was found duringbuild file parsing, attempting to resolve. Future
versions of Ant may support referencing ids defined in non-executed
targets.
I googled it, and found that I needed to upgrade Ant, and now I don't get this warning, and my application does not force close.
What needs to be in build.xml so that the external .jar file is included in the APK?
Just putting it in libs/ is sufficient.
my build.properties looks like this:
That line should not be necessary. It does not appear in my build.properties files that build successfully with JAR files.
If you use dexdump -f classes.dex from your project's bin/ directory, you will be able to determine whether com.google.ads.AdView made it in there. If it did not, then something is strange with your build scripts. If it did, then perhaps there is a dependent JAR that you are missing (though I would expect a VerifyError in that case).
You use 3rd party library, but you seem didn't run DX on it. Make sure that not only your code processed by DX tool (I assume Ant does it), but also all 3rd party libraries you use. You can look in 7Bee script I use to convert web applications to Android davlik format, so it can work for you too. You can find more about the script on Atjeews page.
Solution:
right click on the project in project tree and select Project
properties
select Java Build Path
select TAB Order
and Export
check GoogleAdMobAdsSdk-4.0.4.jar (or your
version SDK)
press OK
clean project by menu Project
-> Clean
rebuild project (Project – Build Automatically)
I am creating an Android library and it has an assets folder with images.
When I use it in another project the assets doesn't get copied.
Anyone else had this issue?
The new Android Build System that is based on Gradle supports asset folders in library projects!
With ANT based builds it's still not possible:
Library projects cannot include raw assets. (See docs)
But you could
copy the assets manually
or even patch the aapt tool (see http://devmaze.wordpress.com/2011/06/26/enabling-assets-in-android-libraries/)
It is possible to put assets into resulting library jar by small fix:
Put "custom_rules.xml" into you library project home (near the build.xml):
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<target name="-post-compile" if="${project.is.library}">
<echo>Post Compile: add assests from ${asset.absolute.dir} to ${out.library.jar.file}</echo>
<jar destfile="${out.library.jar.file}" update="true">
<zipfileset dir="${asset.absolute.dir}" prefix="assets" excludes="**/*.java ${android.package.excludes}"/>
</jar>
</target>
This will pack your library assets into you resulting library jar. As result, these assets will be included into resulting .apk of your application.
Checked on Android SDK Tools Revision 21.1.0 on OSX
From Eclipse and ANT you can reference the same "assets" folder from multiple projects.
This allows your source tree to have a single copy of the assets files, but have them included in multiple APKs.
See Android: targeted res folders for debugging in eclipse
From ProjectA I was able to reference ..\ProjectA\Assets from ProjectB.
On Eclipse (under Windows at least, I've not tried on Linux yet), I had to create a new variable to reference ..\ProjectA and use that variable in "Linked Folder Location". If I attempted to use ".." in "Linked Folder Location" eclipse wouldn't accept it.
For those using IntelliJ IDEA, you can make a change to your application module's packaging settings to include depedent assets. Note, this was done on version 14.0.2 of IntelliJ Community edition. My main application module now inherits files form my library project's assets folder as if they were right in the main project!
Right click application module > Open Module SEttings. Select Android tree node on module > Packaging Tab. Check "Include assets from dependencies into APK"
Note: I've never used Android Studio, but I would guess there is a similar setting for this in that application.
start by creating android lib project, close after creation. this'll prevert autobuild
use cmd terminal on windows android command is batch file
add tools to path
C:\Users\user_bss>PATH=%PATH%;C:\adt-bundle-windows-x86-20140321\sdk\tools
Generate build.xml for ant
android update project -p C:\Users\user_bss\Documents\Workspace\SDKAdvanced -n SDKAdvanced
notepad custom_rules.xml add the code from above don't forget end tag
run "ant debug" or "ant release" to build
you'll see classes.jar in bin dir this is your packed lib