在 strings.xml 中
<resources>
<string>name="app_name">App_Name</string>
<string>name="app_port">https://example.com</string>
<string>name="app_key">App_Key</string>
</resources>
Run Code Online (Sandbox Code Playgroud)
在 build.gradle 中
productFlavors {
production {
applicationId = "com.example.production"
}
staging {
applicationId = "com.example.staging"
//code to manipulate strings.xml value because for production and staging app_name, app_port and key are different
}
}
Run Code Online (Sandbox Code Playgroud)
我需要一个代码来操作 build.gradle 文件的 ProductFlavours 中的 strings.xml,而不是为暂存和生产创建单独的文件夹。