build Android app using gradle command line

As a newbie to Android App, I post this …

set ANDROID_HOME if you encounter below problem

$ ./gradlew
Starting a new Gradle Daemon for this build (subsequent builds will be faster).
Parallel execution is an incubating feature.
Download https://jcenter.bintray.com/com/google/gms/google-services/3.0.0/google-services-3.0.0.pom
Download https://jcenter.bintray.com/com/google/gms/google-services/3.0.0/google-services-3.0.0.jar

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.474 secs
echo "export ANDROID_HOME=/home/owenwen/Android/Sdk"

and, this is what under my /home/owenwen/Android/Sdk, a normal SDK folder

$ ll ~/Android/Sdk/
total 44K
drwxrwxr-x 7 owenwen owenwen 4.0K Feb 9 21:40 add-ons
drwxrwxr-x 5 owenwen owenwen 4.0K Feb 9 21:40 build-tools
drwxrwxr-x 4 owenwen owenwen 4.0K Oct 20 17:23 extras
drwxrwxr-x 2 owenwen owenwen 4.0K Oct 25 13:40 licenses
drwxrwxr-x 3 owenwen owenwen 4.0K Oct 20 17:22 patcher
drwxrwxr-x 8 owenwen owenwen 4.0K Feb 9 21:40 platforms
drwxrwxr-x 5 owenwen owenwen 4.0K Dec 29 15:40 platform-tools
drwxrwxr-x 7 owenwen owenwen 4.0K Dec 29 16:04 sources
drwxrwxr-x 6 owenwen owenwen 4.0K Dec 29 16:04 system-images
drwxrwxr-x 2 owenwen owenwen 4.0K Dec 29 16:07 temp
drwxrwxr-x 12 owenwen owenwen 4.0K Dec 29 15:39 tools

list below some useful gradle command

$ ./gradlew tasks (to see what command gradle provide, e.g. build, clean, androidDependencies, test)
$ ./gradlew build (just build the project)

I see three files after build, I still not know what difference between them

$ ll app//build/outputs/apk/
total 27M
-rw-rw-r-- 1 owenwen owenwen 8.9M Feb 9 22:00 app-activation_launcher-4.11.0_191.apk
-rw-rw-r-- 1 owenwen owenwen 9.2M Feb 9 22:00 app-activation_launcher.apk
-rw-rw-r-- 1 owenwen owenwen 8.8M Feb 9 22:01 app-releaseUnsigned-unsigned.apk

If you see below build break message, you can skip it by “abortOnError false", but better to fix it

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':common:lint'.
> Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...

below shows you how to add “abortOnError false"

+++ b/common/build.gradle
@@ -22,6 +22,9 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
+ lintOptions {
+ abortOnError false
+ }
}

below shows how to build sign apk

http://stackoverflow.com/a/21020469/1117177

Put this into ~/.gradle/gradle.properties

RELEASE_STORE_FILE={path to your keystore}
RELEASE_STORE_PASSWORD=*****
RELEASE_KEY_ALIAS=*****
RELEASE_KEY_PASSWORD=*****

Modify your build.gradle like this:

...
signingConfigs {

release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}

buildTypes {
release {
signingConfig signingConfigs.release
}
}
....