Android Flavors,ContentProviders,SyncAdapters和AccountManager

Pra*_*kar 5 xml android gradle android-syncadapter android-productflavors

我为我的Android应用程序定义了一些flavor和buildTypes

productFlavors {
    X {
        applicationId = "com.x.xxxx"
    }
    Y {
        applicationId = "com.y.yyyy"
    }
}

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard_rules.txt'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    }

    debug {
        applicationIdSuffix ".debug"
    }
}
Run Code Online (Sandbox Code Playgroud)

这样做可以创建不同的flavor/buildType组合.

现在为了确保ContentProviders工作而我没有收到Failure [INSTALL_FAILED_CONFLICTING_PROVIDER]错误,我已将代码中的android:authorities="${applicationId}"AUTHORITY引用更改为BuildConfig.APPLICATION_ID.

这使得ContentProvider工作正常,即当我在同一部手机上安装两种不同类型时,它不会引发错误.它让我安装它们.

下一步是错误发生的地方.我使用SyncAdapterAccountManager控制一些事情.我已修改ACCOUNT_TYPE使用了APPLICATION_ID.因为不能够使用gradle这个问题的${applicationId}非清单XML资源文件,我已经创造了每味不同的目录结构和复制syncadapter.xml,并authenticator.xml有相应的authorityaccount type字符串.

我也尝试过这个博客中描述的技术 - http://blog.jensdriller.com/android-gradle-workaround-for-missing-placeholder-support-in-resource-files/

最受欢迎的答案是在Gradle中使用构建类型来运行在一台设备上使用ContentProvider的相同应用程序但事情似乎不起作用.

有人能够最近上班吗?