Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automate android app builds

let's assume I have an android project in IntelliJ.
Now, I am changing some details on the strings.xml resource file, and after every change I build a new apk.

I want to create a second program that will automatically build an apk file.
I could change the parameters for the strings.xml file, and then build automatically without accessing IntelliJ, is it possible? will it only be related to Java language? or could I build it in C# or any other language as well?

I did read about Maven and Ant, but I have no idea how to use them correctly, I would like an answer that will lead me to some examples or tutorials as well, thanks!

like image 454
Ori Frish Avatar asked Mar 15 '23 10:03

Ori Frish


1 Answers

The common approach is to use three things:

  • Build system (Ant, Maven or Gradle) - for Android apps Gradle is becoming standard
  • Version Control System (e.g. Git)
  • Continuous Integration Server (Jenkins, Travis or other)

Gradle Build System

When you create default project in Android Studio, you already have it created with Gradle. Android Studio also allows you to convert project from Ant to Gradle. I cannot explain you, how to use Gradle in a single post, as it can be subject for whole article or even book. Basically, you have build.gradle file in which you can define dependencies in your project and build configuration. You can have installed Gradle in your system, but good practice is to use Gradle Wrapper, which is a single *.jar file and it can be used to build your application. Once you have your project configured with Gradle, you can build it from command line as follows:

./gradlew build

On MS Windows:

gradlew.bat build

Continuous Integration Server

When you have your project configured with Gradle, you can push its source code to your Git repository and create a job on your Continuous Integration server, which will be responsible for building your project. Within the build, you can create an artifact with compiled *.apk file, execute tests and run static code analysis. You can trigger your job via Git commit hooks or via polling on Continuous Integration server. It depends on chosen technology stack, but it can be automated.

If you want a lot of customization and free solution, Jenkins CI would be a good choice, but you'll have to configure a lot of stuff by yourself and host server by yourself. In my opinion, such choice can make sense in a team projects, when you have appropriate infrastructure and time to set it up. If you want an easy configuration and you're willing to spend some money or create an open-source project, I recommend using GitHub and Travis CI. It's also a good choice for individual developers. I'm not sure how to generate artifact with *.apk file on Travis CI, but I suppose it can be done and you can always ask support to help you. For sure, artifact be archived in Jenkins CI job.

like image 61
Piotr Wittchen Avatar answered Mar 31 '23 09:03

Piotr Wittchen