how to generate apk using ant - android

i want to know how can we generate apk file using ant script. i came to know that we can use "ant debug" command to do that.but when i am running this command it is returning error that " Target "debug" does not exist in the project". i am using ant1.7.0.is it the issue?i have tried given below code to generate apk.
<target depends="build-subprojects,build-project" name="build">
<jar destfile="bin/test.apk" basedir="bin/classes" >
<manifest>
<attribute name="Main-Class" value="test.Main" />
</manifest>
</jar>
</target>
but the generated apk is different from auto generated apk while build the app using eclipse.Please guide me.

but when i am running this command it is returning error that " Target "debug" does not exist in the project"
Then you did not create your Android project properly, or you modified your build.xml file, or something else is broken.
As a test, I just ran the following command from my /tmp directory on Linux:
android create project --target android-17 --path Foo --package com.foo --activity Foo
I then changed into the Foo directory and ran ant debug. The app compiled, and in my bin/ directory is Foo-debug.apk.
If you are not getting this sort of result, delete your build.xml file and run android update project --path ..., where ... is the path to your project, to create a fresh build.xml file.

Related

Build application from command line

I'm trying to build an apk file from command line. I created a sample project usng the following command:
android create project --target 1 --name MyApp --path ./MyProject --activity MyActivity --package com.example.myapp
Which created the following structure:
/bin
/res
/src
/libs
AndroidManifest.xml
ant.properties
build.xml
local.properties
proguard-project.txt
project.properties
Now when I try to build the project, I get:
$ gradle build
gradle will not execute and completion _gradle exists.
I couldn't find any info on this error, so I ran:
$ _gradle build
_arguments:comparguments:312: can only be called from completion function
user has logged on pts/7 from :0.0.
Any hints on what am I doing wrong? Thanks!
android create project creates project in structure expected by Eclipse, not gradle based (Android Studio) projects.
I was able to build the apk using the following lines:
ant debug
adb install bin/HelloWorld-debug.apk

ActionBarSherlock: How To Build ViewPagerTutorial? No build.xml

I downloaded the ActionBarSherlock ViewPagerTutorial from here:
http://www.androidbegin.com/tutorial/android-actionbarsherlock-viewpager-tabs-tutorial/
But when I try to build the package it errors out saying:
$ ant debug
Buildfile: build.xml does not exist!
Build failed
Where can I find the build.xml file for this package?
Where can I find the build.xml file for this package?
You create it, by running the android update project command.

Use ant (build.xml) to compile jni directory

I'm using ant to build my android app (ant compile, ant install and so on) and I'm adding some NDK sources (inside jni/ directory) and I want to have a rule to recompile the jni/ directory with ant and THEN install my app into my device/emulator, like this:
$ ant jni-and-install
Instead of:
$ make -f jni/Makefile APP=myapp
(jni compilation & installation)
...
$ ant install
I was trying to find the place to put my rules in build.xml but I don't know where.
What should I edit for ant to call make on jni/ directory before installing into device?
You could use the exec ant task :
<target name="install">
<!-- ... -->
</target>
<target name="jni">
<exec executable="make">
<arg line="-f jni/Makefile APP=myapp"/>
</exec>
</target>
<target name="jni-and-install" depends="jni, install"/>
You can use an exec ant task for this. I think putting the following in your -pre-build target in build.xml will do the trick:
<exec executable="make" failonerror="true">
<arg line="-f jni/Makefile APP=myapp"/>
</exec>
Edit: JB's solution allows for things like ant jni to build the jni code without building the rest of your project. You can get the best of both worlds by wrapping the above in a target named "jni" and then adding depends="jni" to your -pre-build target.

Android ==> ant and proguard?

I am getting the following error while obfuscating my application.
How can i define the output jar in my build.xml?
[java] Shrinking...
[java] java.io.IOException: The output jar is empty. Did you specify the proper '-keep' options?
[java] at proguard.shrink.Shrinker.execute(Shrinker.java:148)
[java] at proguard.ProGuard.shrink(ProGuard.java:294)
[java] at proguard.ProGuard.execute(ProGuard.java:100)
[java] at proguard.ProGuard.main(ProGuard.java:499)
Use Android SDK Tools revision 8 or later
If you do not have build.xml for your project, run command like this in some empty directory
android create project --name <Your Project Name> --package <Your Company Name> --target 7 --path . --activity dummy Find build.xml which you can copy to root directory of the project.
In default.properties add reference to proguard settings (proguard.config=proguard.cfg)
Turn off android:debuggable in application manifest.
Run 'ant release' command
You should find directory called ./bin/proguard and ./bin/-release.apk. You can find more details here.
The tutorial here has never gone wrong for me.

Build android project from command line

I would like to build and android project from command line on Linux. In the root directory of the project there are the following files and directories:
AndroidManifest.xml build.xml default.properties res/ src/
Can you provide a sample Makefile how to build this project?
Do you have 'ant' installed? Try ant debug
The build.xml file is input to the Ant program, which will build your project. Use "ant build"

Categories

Resources