问题
I'm having the issue where my Android Content Provider is not being recognized in a separate build variant from an Android library. I've followed most of the ideas in: Using build types in Gradle to run same app that uses ContentProvider on one device
I also followed: http://www.kevinrschultz.com/blog/2014/03/23/using-android-content-providers-with-multiple-package-names/
When I try running the app, the parent application tries to import a java class from the FYC library listed in src/main/AndroidManifest.xml and doesn't recognize the class because of the .qa package name?
My library FYC.gradle file looks like this:
...
android
{
...
productFlavors
{
prod {
packageName "com.company.android"
}
qa {
packageName "com.company.android.qa"
}
}
}
I commented out the content provider in main: src/main/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.android.fyc"
android:versionCode="1"
android:versionName="1.0" >
<!--<provider-->
<!--android:name=".models.listing.ListingProvider"-->
<!--android:authorities="com.company.android.fyc.models.listing.listingprovider"-->
<!--android:exported="false" />-->
</manifest>
src/prod/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.android.fyc"
android:versionCode="1"
android:versionName="1">
<application>
<provider
android:name=".models.listing.ListingProvider"
android:authorities="com.company.android.fyc.models.listing.listingprovider"
android:exported="false" />
</application>
</manifest>
src/qa/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.android.fyc"
android:versionCode="1"
android:versionName="1">
<application>
<provider
android:name=".models.listing.ListingProvider"
android:authorities="com.company.android.qa.fyc.models.listing.listingprovider"
android:exported="false" />
</application>
</manifest>
I tried another option and tried using a variable for the package name, but Gradle gave me an error that it didn't recognize $?
In AndroidManifest.xml, you can use ${packageName} like this:
<!--<provider-->
<!--android:name=".models.listing.ListingProvider"-->
<!--android:authorities="${packageName}.fyc.models.listing.listingprovider"-->
<!--android:exported="false" />-->
Does anyone have another recent work around for this issue? Thanks!
来源:https://stackoverflow.com/questions/24644274/using-build-types-in-gradle-libraries-to-run-same-app-that-uses-contentprovider