对于发布和调试版本,我们需要具有不同配置的gradle.properties
文件,因为我们使用的某些功能是实验性的,会破坏某些功能。那可能吗?
我们的gradle.properties
文件的示例
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx1500m -XX:MaxPermSize=512m
org.gradle.parallel=true
kotlin.incremental=true
android.enableD8=true
最佳答案
根据官方文档:
您可以在android块内的模块级build.gradle文件中创建和配置构建类型。创建新模块时,Android Studio会自动为您创建调试和发布构建类型。尽管调试构建类型未出现在构建配置文件中,但Android Studio会将其配置为可调试true。这使您可以在安全的Android设备上调试应用程序,并使用通用调试密钥库配置APK签名。
如果要添加或更改某些设置,可以将调试构建类型添加到配置中。下面的示例为调试构建类型指定一个applicationIdSuffix,并配置一个“阶段”构建类型,该类型使用调试构建类型中的设置进行初始化。
您可以将相同的build.gradle用于发布和 Debug模式,例如:
buildTypes {
release {
// Do whatever you want to do in release mode
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
// Do whatever you want to do in debug mode
applicationIdSuffix ".debug"
debuggable true
}
/**
* The `initWith` property allows you to copy configurations from other build types,
* then configure just the settings you want to change. This one copies the debug build
* type, and then changes the manifest placeholder and application ID.
*/
staging {
initWith debug
manifestPlaceholders = [hostName:"internal.example.com"]
applicationIdSuffix ".debugStaging"
}
}
引用:Source