Build Android Artifact from Command-line
Theory
Everything you do that builds Android artifacts from Android Studio is based on Android command-line tools, so you can just build them from command-line.
Why Build Android Artifact from Command-line?
So that you can do it in an automated pipeline, I have a Dockerfile for that.
In my use case, I keep the release signing key from the team for property protection, when a release artifact should be build, it will be built in a pipeline that can retrieve the release signing key.
How?
The official document explains it well.
Use gradlew
command instead of gradle
Don't use gradle
command which you installed separately to execute Android project's gradle tasks,
it will fail due to configurations and throws exception like:
> Task :app:kaptDebugKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
> java.lang.reflect.InvocationTargetException (no error message)
Android project needs its own touch.
Just use the gradlew
bash command included in project to execute Android project's gradle tasks like build
or clean
.