我正在使用 Android Studio 构建我的应用程序。我想使用 gradle
buildTypes。我使用 applicationIdSuffix 向包名称添加后缀,以修改测试构建类型的包名称。
buildTypes {
debug {
runProguard false
proguardFile 'proguard-rules.txt'
applicationIdSuffix '.dev'
versionNameSuffix '-dev'
}
}
是否可以在 xml 文件中使用此信息。我的计划是修改账户类型:
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType=<<PACKAGE NAME HERE ??>>
android:icon="@drawable/icon"
android:label="@string/app_name"/>
谢谢!
最佳答案
这是另一个临时解决方法,直到 Android Gradle 插件获得 support for placeholders in resource files .
您可以通过 Gradle 在 defaultConfig
和/或 buildTypes
和/或 productFlavors
闭包中动态创建字符串资源:
android {
defaultConfig {
applicationId 'com.foo.bar'
resValue 'string', 'package_name', applicationId
}
}
然后您可以在 authenticator.xml
文件中引用它,就像您对标签所做的那样:
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/package_name"
android:icon="@drawable/icon"
android:label="@string/app_name"/>
关于android - 在 XML 中使用包名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24356595/