Android: How to build a .apk from the terminal? - android

I am developing a dynamic app generator, so I would need to run the command on a runtime basis using Java on a server

From the Android Developer site:
Managing Projects from the Command Line
Building APK from Command Line
You will need Gradle to build from the command line. Once you have that you can create the APK like this:
Windows:
> gradlew.bat assembleRelease
Unix:
$ ./gradlew assembleRelease
This creates your Android application .apk file inside the project
bin/ directory, named -unsigned.apk.

If you may rely on Android SDK, it is as simple as to generate build.xml and some properties file and invoke ant.
You may generate an android project by command android for reference.

ant release command builds release APK

Related

How to install app on android with gradlew.sh?

I have downloaded an android app from Github (Link). But I am unable to install this app on android (I am using Linux). Could someone tell me which direction should I go?
App folder Contains following files:
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle
first install gradle this linke
then you can build the project on Command Line './gradlew assembleDebug'
This creates an APK named module_name-debug.apk in project_name/module_name/build/outputs/apk/. The file is already signed with the debug key and aligned with zipalign, so you can immediately install it on a device.

Generating APK - gradlew is not recognised

Trying to generate signed APK for android using windows 10, I have generated my keystore but how do I run gradlew assembleRelease?
I have unzipped the binary into C:, added gradle to my path. However, gradlew is not recognised, and there is no build.gradle file in android/app/
The react native docs aren't very clear at all. Can anyone help?
Using Android Studio I cannot see any build options either.
Tried cd android && ./gradlew assembleRelease but get the error '&&' is not a valid statement separator
Menu in android studio looks like:
Even though I am using a Mac, it's the same on windows too: you can use the Build->Generate signed APK. That should work by default. If that it's not working I suggest to Invalidate caches and restart your android studio.
Go into your react native project directory and run
cd android && ./gradlew assembleRelease

How to build apache cordova project from command line?

I've setup apache cordova on my Windows/Cygwin platform.
I can create project using the command - cordova create <app_name>.
I have added android platform using the command - cordova platform add android
I can run the sample 'html/css/js' using cordova ripple android.
I can upload the project to build.phonegap and get the .apk file.
I know from docs that I can setup eclipse and do the build. (I'm not looking for this)
But I cannot create .apk file using the command cordova build android. When I run the command, there is not output on the command line, the command just finishes. I cannot locate the .apk file.
Is there a way in which I can create an .apk file from command line?
(Looking for suggestions for other platforms as well)
Thanks,
You should get a more verbose output by running cordova -d build android.
Alternatively, to use the underlying cordova-android scripts to build, you can:
cd platforms/android
./cordova/build
OR, to peel away even more layers, you can use the Android ANT script to run the build (which is what the cordova scripts shell out to anyways):
cd platforms/android
ant debug
For Android the default location for the APKs is the bin directory
The location is defined by ant properties in the Android SDK buil.xml
<import file="${sdk.dir}/tools/ant/build.xml" />
The output apk will be in two formats debug or release
<property name="out.final.file" location="${out.absolute.dir}/${ant.project.name}-debug.apk" />
<property name="out.final.file" location="${out.absolute.dir}/${ant.project.name}-release.apk" />
The location of your apk will be something like this:
myAndroidApp/bin/myAndroidApp-debug.apk
myAndroidApp/bin/myAndroidApp-release.apk
Use cordova compile android
This will output a debug .apk file into platforms/android/bin
This works with Cordova 3.3.1
I was using ant 1.7 which was causing the problem. There was no error message mentioning the version. After changing to Ant 1.8.xx, phonegap was able to install and build the android project.

How to compile APK from command line?

I am interested in making Android apps on demand. Depending on the clients request, my web site would send me a JSON file direct to a Windows application that I have created in Delphi. This one would save the file inside the Android app source folder and then, execute a command line telling the Android compiler to generate the APK file and send it to my client, all that without my presence.
The Android project was made with MotoDev. And it uses the Android SDK that is in my root.
How should I configure the command line to achieve this from inside my Delphi program?
I will also need to change the manifest to put a new version number so it does not conflict with other clients version.
Android uses the Ant build system, so you can create a build.xml and build.properties file for your project.
You'll need to create the build.xml file first though:
android update project -p .
This will generate a build.xml file. You should probably customize the build steps and targets for your project. A good idea in your case would be to have the build.properties file generated by your website for the specific build... Then include it via the build.xml file. In particular, you will need to specify in the build.properties file where the signing keys are, and what the password is:
Build.Properties:
key.store=keystore.dat
key.alias=signing_key
key.store.password=password123
key.alias.password=password123
The build process using ant also allows you to do variable replacements in Java files, which might be another idea. It would allow you to customize the build process further on a client by client basis.
By default, the build is triggered by:
ant clean
ant release
Another neat idea: Have Ant copy the resulting APK file to a network share accessible by the website by placing a < copy ... /> line in the < target name="release" > section.
Create build.xml at project creation time
If you start a new project with:
android create project \
--target 1 \
--name MyName \
--path . \
--activity MyActivity \
--package com.yourdomain.yourproject
the build.xml file used by ant will be generated.
The android tool is present in the tools/ directory of the SDK which you downloaded.
Create debug releases
Besides:
ant release
for final releases, you can also create debug releases with:
ant debug
Location of generated apk
Generated apk are placed under bin/.
The most important outputs are:
MyName-debug.apk
MyName-release.apk
but some intermediate apks are also generated, in particular unaligned and unsigned versions.
But most of the time you can forget where they were created and just run:
ant debug install
ant release install
to get them installed. But make sure it is working with adb first: adb devices command not working
Tested on Ubuntu 15.10, Android 23.
Android doesn't directly use ANT build systems now. It uses Gradle, which is based on Groovy. You can learn more about build systems here.
You can see the list of available tasks you can run on using this command
gradlew tasks
To initiate a debug build, invoke the assembleDebug task
gradlew assembleDebug
You can install your app using the adb tool via this command
adb install path/to/your_app.apk
To learn more about building on command line, follow this comprehensive article.
Also you can read this article on "Why Build Your Java Projects with Gradle Rather than Ant or Maven?"

Ant create android project

I know that Ant is a build tool. We write script (steps while releasing android project) to build an android project and create a signed apk. Thats is one of the uses of Ant. But I want a method/script to create a new project in Android and I also want to build it so that an apk file can be created through that method/script. Is it possible through Ant?i.e. Ant script create a new project with a package name and activity name provided in the script, build it and create an apk file ready to be loaded in the emulator or device.Is there any solution(method/script) to the above mentioned problem?
yes you can do this through ant via a command line call to 'android create project' which will in turn generate all the ant scripts.

Categories

Resources