How to build and package the android project with Ant - android

How to build and package the android project with Ant.
I want to build and package a android project automatic with Ant,not the Eclipse.
Someone give me some examples or some Ant build files.

Assuming you are inside the root folder of your project, execute from a terminal/shell/console/command prompt:
android update project -p .
This will generate the necessary files, including build.xml. Modify it for your requirements, or leave it as it is for standard build behaviour.
To create a debug build, execute:
ant debug
Or swap out debug for release for a release build. Note that you will need to provide details to the release key in order to complete the signing process (keystore location, keystore password, key alias and key password). If you don't, you will end up with an unsigned apk that you'll have to manually sign using the appropriate key.
I prefer to do a clean with most builds as well, so the command I issue with every release build looks like:
ant clean release
References:
Managing Projects from the Command Line
Building and Running

Related

Need to run a Gradle task after Android APK generated through Studio Build menu, but not when deploying/testing a release build on local device

I'm not 100% certain this is possible, but I have set up a gradle task that tags my git repo with info about the build, which runs when I generate my signed apk just before releasing. I generate the apk using the Android Studio Build -> Generate signed bundle/apk menu option (mainly because it has all my keystore info in it and it's easy to do).
However, when I sometimes test the release build of my app, rather than the debug build, and I run it on my phone plugged in, just by clicking the green 'play' triangle button, it also tags the current git head with the same info.
Is there any gradle task that runs purely when I do the Generate signed bundle/apk menu option? I don't know of anyway of finding it out.
I feel like the only task there might be is some sort of signing task. Unless when i test on my device, it's also signing the apk, in which case...how? I'm 99% certain i don't have my keystore password anywhere so it couldn't use it...could it?
EDIT It appears I do use a plain text file called keystore.properties which has all my keystore details in it (I made it over 2yrs ago so forgot all about it!), so this must be being used for the release build. So in fact is there no diff between me testing my release build (and the apk it generates) and running Build -> Generate apk?
Thanks

How to get the updated Apk file from the android studio.?

I am developing an android application. All the things is going well when I run the application into genymotion virtual device.And Since the apk is stored in F:...\app\build\outputs\apk location. So I just want to collect it from this location and download it to install in a android phone.As I simultaneously updating the application with code but this apk doesn't provide me the updated apk file according to the updated code .They just give me the old apk file even if i run my application again and again from the android studio. Can anyone suggest me why this is happening ??? I just want to run this apk into phone or download this apk file for another purpose.
This three steps will do Go build->Build apk
Go to Build > Build APK to generate a normal APK.
Go to Build > Generate Signed APK to generate signed APK.
Signed APK are those which we generate to release our application. Here it is, why is it necessary to generate signed APKs: Why should I Sign my Application APK before release
If you build a debug APK, it will still work on all devices but you cannot release it.
From terminal run the following command to make sure that you get the updated apk.
1. gradle clean (from windows )
-or-
./gradlew clean (from linux) -
Above command deletes the build folder.
2. gradle build (from windows)
-or-
./gradlew build(from linux)
Above command builds all the flavor for your application.
Edit: Original answer
Signed apk is needed to install in any other non debug device. This will be same as the debug app that runs in your test device/emulator.
Build -> Generate signed apk

Android Can anyone suggest me how to create apk from command line step by step?

My Requirement to create the .apk from my code without using android studio and eclipse.
My code is on svn.
This can be done with Apache ANT. You can download it from here: Apache ANT Home Page
Follow this link here to get everything set up to use ANT.
Once you have ANT installed and setup, navigate to your project folder and type
ant release
This will create a debug release for you to test on a real device.
If you would like, you can configure the Android build script to automatically sign and align your application package. To do so, you must provide the path to your keystore and the name of your key alias in your project’s ant.properties file. With this information provided, the build script will prompt you for your keystore and alias password when you build in release mode and produce your final application package, which will be ready for distribution.
To specify your keystore and alias, open the project ant.properties file (found in the root of the project directory) and add entries for key.store and key.alias as below
key.store=<App-Name>.keystore
key.alias=Alias-Name
Save your changes then type this in the command prompt
ant release
Enter your keystore and alias passwords when prompted.
More advanced info can be found here
Add JAVA_HOME (Jdk path )
Add Ant path
Add sdk path
Then open command prompt set the location of your project,
gradlew.bat assembleDebug
after building you can see apk at build location of your project.

Updating apk SHA1 differs even after using same keystore

I have uploaded my app to Goggle Play few months back after signing it with a release keystore, I have stored that Keystore for future updation. Now I have updated the apk with some changes, while trying to upload the new apk signed with same keystore along with same alias and password, the apk is not allowed to upload to Goggle Play.
Playstore shows me following error :
The only change is, earlier the appication was developed and build using eclipse and now in android studio Can this be the reason for showing the above error???
From the error message I would say you have mixed up the keystores, or android studio is just using the wrong one to do the release build. The best way to be completely sure is to clearly setup your build.gradle, and build it yourself on the command line using
./gradlew clean assembleRelease
What is probably happening is that Android Studio is using your debug keystore (ie. the default) to sign the release build because it can't find the original keystore you used in eclipse, or you have the wrong password somewhere...
Have a look at this configuration, note the location of the keystores, the naming convention and how it corresponds to the build.gradle. Note the signingconfigs and how they are setup for the release build. To build from the command line, simply cd into the directory with your "gradlew" file, and run
./gradlew clean assembleRelease
to build the release apk, or
./gradlew clean assembleDebug
to build the debug apk. If it fails, try
./gradlew clean assembleRelease --stacktrace
Screenshot of build.gradle and filesystem setup
But please remember not to put your keys in your source control! That means editing your .gitignore file.
There is a stack of information on how to do this here:
http://developer.android.com/tools/publishing/app-signing.html

Batch exporting of Android APKs

Let's say I have a whole lot of Android projects, how would I go about, export and digitally sign them all at once, is it even possible to do through eclipse?
Any thoughts of the matter will be greatly appreciated.
In Eclipse it's not possible to export multiple projects without human intervention.
You can script it by creating ANT build.xml files for all of your projects. The ANT build files allow you to specify the keystore path and key alias that you want to use to sign your APK.
You can create a simple script that goes through all of your projects, and calls the ant release target. This will generate a signed APK file.
That way, you can export all of your apps with a single script.
More information can be found on :
http://developer.android.com/guide/developing/building/building-cmdline.html

Categories

Resources