android - 在 XML 中使用包名

标签 android xml gradle android-studio android-gradle-plugin

我正在使用 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/

相关文章:

java - Android LinearLayout 获取屏幕上的 View /行

xml - 如何删除节点的属性 (MSXML)

java - Android Studio - Gradle 1.5 --core-library 选项

android - 将 ionic 框架添加到现有的 android studio 应用程序

android - 如何查找 whatsapp 的通知 ID

Android 设备兼容性 - 停止安装

webview 输入字段中的 Android 电子邮件友好键盘

xml - Adobe XFL Flash 交换格式的文档在哪里?

java - 如何将 xml 属性值映射到属性文件中的键?

android - 如何将源集添加到android项目