Android Flavors,ContentProviders,SyncAdapters和AccountManager

时间:2015-04-22 21:10:20

标签: android xml gradle android-syncadapter android-productflavors

我为我的Android应用程序定义了一些版本和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"
    }
}

这可以创建不同的flavor / buildType组合。

现在为了确保ContentProviders有效并且我没有收到Failure [INSTALL_FAILED_CONFLICTING_PROVIDER]错误,我已将代码中的android:authorities="${applicationId}"AUTHORITY引用更改为{{1} }。

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

下一步是错误发生的地方。我使用ContentProviderSyncAdapter来控制一些事情。我修改了AccountManager以使用ACCOUNT_TYPE。由于gradle无法在非清单xml资源文件中使用APPLICATION_ID的问题,我为每种风格创建了不同的目录结构,并将${applicationId}syncadapter.xml复制到相应的authenticator.xmlauthority字符串。

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

Using build types in Gradle to run same app that uses ContentProvider on one device的最高投票答案,但事情似乎不起作用。

最近有人能够让它上班吗?

0 个答案:

没有答案