*名词解析:*我们通常会分不同的编译环境进行打包,比如有debug、release、beta等环境参数,像这种我们就称之为buildTypes.
您可以在模块级 build.gradle
文件的 android {}
代码块内部创建和配置构建类型。当您创建新模块时,Android Studio 会自动为您创建调试和发布这两种构建类型。尽管调试构建类型不会出现在构建配置文件中,Android Studio 会将其配置为 debuggable true
。这样,您可以在安全的 Android 设备上调试应用并使用通用调试密钥库配置 APK 签署。
如果您希望添加或更改特定设置,您可以将调试构建类型添加到您的配置中。以下示例为调试构建类型指定了 applicationIdSuffix
,并配置了一个使用调试构建类型中的设置进行初始化的jnidebug
构建类型。
applicationIdSuffix:
字段表示,在不改变你默认的程序ID(包名)的情况下,为其添加后缀。比如你的包名是com.rae.app
,但你想区分测试包和正式包的情况,这个时候将applicationIdSuffix
设置为.debug
,那么你的应用程序对应的包名就变成了com.rae.app.debug
android {
…
defaultConfig {…}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’
}
debug {
applicationIdSuffix “.debug”
}
/**
- The ‘initWith’ property allows you to copy configurations from other build types,
- so you don’t have to configure one from the beginning. You can then configure
- just the settings you want to change. The following line initializes
- ‘jnidebug’ using the debug build type, and changes only the
- applicationIdSuffix and versionNameSuffix settings.
*/
jnidebug {
// This copies