Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conflicting Provider error when testing in multi module android project

I have an application which consists of multiple gradle modules:

App -- main app module with dependencies to all submodules
|
|-- API - library module
|    |-- Constants for authority etc.
|
|-- DB-Impl - library module
|    |-- ContentProvider for the data specified in API
|
|-- Extension - library module
|    |-- Dependency on API and test-dependency on DB-Impl

This is working fine when building and deploying the main apk. All modules are using the same sharedUserId in the manifest and can access the providers from DB-Impl.

However it gets complicated when I try to run instrumented tests for the different modules.

For example: I run the DB-Impl tests, that module gets installed separately on the device. When I then want to deploy the main app, or try to run it's tests, the apk install fails, because it also contains the providers, throwing an INSTALL_FAILED_CONFLICTING_PROVIDER error.

The same happens for the extension module. It requires the database, which is usually included in the main app apk. When simply running the tests, they would fail because the provider wouldn't be installed. So I added an androidTestCompile dependency on the DB-Impl module. Now this test apk also includes the provider definition an causes even more of the errors.

I tried adding a task dependency on the test tasks, so it would run uninstallAll, however this only uninstalls the module it is called from, so I would have to manually uninstall every module that could come with the providers.

Is there a common strategy to avoid is problem?

like image 548
MatF Avatar asked Mar 09 '17 14:03

MatF


1 Answers

i've bumped with the same issue, and found only one way to resolve it. You need to create Manifest.xml in the androidTest directory, and redeclare content provider with another authority (e.g. append ".test" suffix), also need to add additional attribute for "provider" xml element: "tools:node='replace'", with this approach you override content provider authority for your library module test apk.

like image 73
ultraon Avatar answered Oct 13 '22 12:10

ultraon