如何自动化Android应用程序构建

时间:2023-01-20 20:48:29

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.

我假设我在IntelliJ中有一个android项目。现在,我正在更改strings.xml资源文件的一些细节,并在每次更改后构建一个新的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?

我想创建一个自动构建apk文件的第二个程序。我可以更改strings.xml文件的参数,然后自动构建而无需访问IntelliJ,是否可能?它只与Java语言有关吗?或者我可以用C#或任何其他语言构建它吗?

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!

我确实读过关于Maven和Ant的内容,但我不知道如何正确使用它们,我想要一个能够引导我一些示例或教程的答案,谢谢!

1 个解决方案

#1


5  

The common approach is to use three things:

常见的方法是使用三件事:

  • Build system (Ant, Maven or Gradle) - for Android apps Gradle is becoming standard
  • 构建系统(Ant,Maven或Gradle) - 对于Android应用程序,Gradle正在成为标准
  • Version Control System (e.g. Git)
  • 版本控制系统(例如Git)
  • Continuous Integration Server (Jenkins, Travis or other)
  • 持续集成服务器(Jenkins,Travis或其他)

Gradle Build System

Gradle构建系统

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:

在Android Studio中创建默认项目时,您已经使用Gradle创建了它。 Android Studio还允许您将项目从Ant转换为Gradle。我不能解释你,如何在一篇文章中使用Gradle,因为它可以是整篇文章甚至是书。基本上,您有build.gradle文件,您可以在其中定义项目中的依赖项并构建配置。您可以在系统中安装Gradle,但最好的做法是使用Gradle Wrapper,它是一个* .jar文件,可以用来构建您的应用程序。使用Gradle配置项目后,可以从命令行构建它,如下所示:

./gradlew build

./gradlew build

On MS Windows:

在MS Windows上:

gradlew.bat build

gradlew.bat构建

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.

使用Gradle配置项目后,可以将其源代码推送到Git存储库,并在Continuous Integration服务器上创建一个作业,该服务器将负责构建项目。在构建中,您可以使用已编译的* .apk文件创建工件,执行测试并运行静态代码分析。您可以通过Git提交挂钩或通过持续集成服务器上的轮询来触发您的工作。它取决于所选的技术堆栈,但它可以自动化。

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.

如果您需要大量的自定义和免费解决方案,Jenkins CI将是一个不错的选择,但您必须自己配置很多东西并自己配置服务器。在我看来,当你有适当的基础设施和时间进行设置时,这样的选择在团队项目中是有意义的。如果你想要一个简单的配置,并且你愿意花钱或创建一个开源项目,我推荐使用GitHub和Travis CI。对于个人开发者来说,这也是一个不错的选择。我不确定如何在Travis CI上使用* .apk文件生成工件,但我想它可以完成,你总是可以请求支持来帮助你。当然,工件可以在Jenkins CI作业中存档。

#1


5  

The common approach is to use three things:

常见的方法是使用三件事:

  • Build system (Ant, Maven or Gradle) - for Android apps Gradle is becoming standard
  • 构建系统(Ant,Maven或Gradle) - 对于Android应用程序,Gradle正在成为标准
  • Version Control System (e.g. Git)
  • 版本控制系统(例如Git)
  • Continuous Integration Server (Jenkins, Travis or other)
  • 持续集成服务器(Jenkins,Travis或其他)

Gradle Build System

Gradle构建系统

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:

在Android Studio中创建默认项目时,您已经使用Gradle创建了它。 Android Studio还允许您将项目从Ant转换为Gradle。我不能解释你,如何在一篇文章中使用Gradle,因为它可以是整篇文章甚至是书。基本上,您有build.gradle文件,您可以在其中定义项目中的依赖项并构建配置。您可以在系统中安装Gradle,但最好的做法是使用Gradle Wrapper,它是一个* .jar文件,可以用来构建您的应用程序。使用Gradle配置项目后,可以从命令行构建它,如下所示:

./gradlew build

./gradlew build

On MS Windows:

在MS Windows上:

gradlew.bat build

gradlew.bat构建

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.

使用Gradle配置项目后,可以将其源代码推送到Git存储库,并在Continuous Integration服务器上创建一个作业,该服务器将负责构建项目。在构建中,您可以使用已编译的* .apk文件创建工件,执行测试并运行静态代码分析。您可以通过Git提交挂钩或通过持续集成服务器上的轮询来触发您的工作。它取决于所选的技术堆栈,但它可以自动化。

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.

如果您需要大量的自定义和免费解决方案,Jenkins CI将是一个不错的选择,但您必须自己配置很多东西并自己配置服务器。在我看来,当你有适当的基础设施和时间进行设置时,这样的选择在团队项目中是有意义的。如果你想要一个简单的配置,并且你愿意花钱或创建一个开源项目,我推荐使用GitHub和Travis CI。对于个人开发者来说,这也是一个不错的选择。我不确定如何在Travis CI上使用* .apk文件生成工件,但我想它可以完成,你总是可以请求支持来帮助你。当然,工件可以在Jenkins CI作业中存档。