android 每日构建
In this tutorial, we’ll be discussing Android Build Types and Product Flavors. We’ll see how they make our Android Development easier and faster especially when we’re creating applications with minimal differences. These differences can be as small as changes in themes and app icons or can be for different stages of the product such as dev, beta, production etc.
在本教程中,我们将讨论Android构建类型和产品风味。 我们将了解它们如何使我们的Android开发更加轻松快捷,尤其是在创建差异最小的应用程序时。 这些差异可以与主题和应用程序图标的变化一样小,也可以针对产品的不同阶段(例如开发,测试版,生产等)进行。
Create a new project in your Android Studio and choose the Basic activity. In the next section, we’ll look at build types.
在Android Studio中创建一个新项目,然后选择基本活动。 在下一节中,我们将介绍构建类型。
Android构建类型 (Android Build Types)
Once the new project is created, by default it consists of two build types/variants – debug, release.
创建新项目后,默认情况下,它由两种构建类型/变量组成:调试,发布。
Debug is the build type that is used when we run the application from the IDE directly onto a device.
调试是当我们从IDE直接在设备上运行应用程序时使用的构建类型。
A release is the build type that requires you to sign the APK. The release builds are meant to be uploaded to the play store. In the release build type, we obfuscate the code using ProGuard to prevent reverse engineering.
发布是一种构建类型,要求您对APK进行签名。 该发行版本应上传到Play商店。 在发行版本类型中,我们使用ProGuard混淆代码以防止进行逆向工程。
Following image shows the default build types.
In the build.gradle
by default, only the release build type block is written:
默认情况下,在build.gradle
,仅写入release构建类型块:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
We can add properties on the other build types too.
Before we do that let’s add some signingConfigs
to the android
block.
我们也可以在其他构建类型上添加属性。
在此之前,让我们向android
块添加一些signingConfigs
。
signingConfigs {
release {
storeFile file("release-key.keystore")
storePassword 'password'
keyAlias 'alias'
keyPassword 'journaldev'
}
}