Compile and run project via command line

Asked

Viewed 2,168 times

6

I have an Android application developed in Eclipse. I know it is possible to compile and run a project from the console, but I don’t know how to do it.

The basic steps to compile a program JAVA is save with the same class name followed by .java and execute the following command:

#javac HelloWordConsole.java

But I intend to carry out this process to create the .apk and install directly to the device via USB. How can I do this using Windows CMD for both Eclipse IDE and Android Studio?

2 answers

3


Android applications use Gradle for compilation automation. So to compile the code just run the command in the folder where you have the file build.gradle.

To compile a debugging APK, open CMD and navigate to the root of the project directory - in Android Studio, select View > Tool Windows > Terminal. To start a debug build, call the task assembleDebug:

gradle.bat assembleDebug

The command on Macos and Linix is:

$ chmod +x gradle
$ ./gradle assembleDebug

PS: It is necessary to have Gradle installed.

Reference: https://developer.android.com/studio/build/building-cmdline.html

1

Android uses the Ant building system. So you can create a xml build. and archive build.properties for your project.

You will need to create the xml build. file first however:

android update project -p.

This will generate a file xml build..

You should probably customize the construction steps and goals for your project. A good idea in your case would be to have the build properties. file generated by your IDE for the specific build. Then include it through the file xml build..

In particular, it will be necessary to specify in the file build properties., where the signature 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 process of building using ant also allows you to do the replacements of variables in Java files, which may be another idea. Would allow you to customize the construction process still on one customer per customer basis.

By default, the build is triggered by:

ant clean
ant release
  • "Will you need to create the build.xml file first however:" ? Did you get it somewhere? The translation seems not to be legal.

  • Which directory should enter so that "android" is an executable command in order to create build.xml?

  • Sorry about my poor translation @seamusd. I got the answer on this link http://stackoverflow.com/a/15285617/6362228

  • 1

    I am not using signature key. I intend to compile only as debug. My intention is to do exactly what the button run of the Eclipse, however via command line. I had already seen this response in the global OS, but I could not understand it very well.

  • I found this other answer, where it explains how to compile in debug mode: http://stackoverflow.com/a/1433396/6362228

Browser other questions tagged

You are not signed in. Login or sign up in order to post.