7

We have a core android application module (called app) and a single dynamic feature module (called replay). Even though this is a DFM we include it at install time. In our DFM's AndroidManifest.xml:

<dist:module
    dist:instant="false"
    dist:title="@string/title_replay">
    <dist:delivery>
        <dist:install-time />
    </dist:delivery>
    <dist:fusing dist:include="true" />
</dist:module>

We are able to build our apk with DFM included just fine from CL: $ ./gradlew app:assembleDebug

Now at test time... We don't have any instrumentation tests in our replay feature module, only our app module. So we are able to run instrumentation tests from command line just fine: $ ./gradlew app:connectedDebugAndroidTest

However we recently started trying to run instrumentation tests inside Android Studio. We again only want to run tests on app module:

enter image description here

The problem now is that we are getting a bunch of weird "Android resource linking failed" errors:

What went wrong:
Execution failed for task ':replay:processDebugAndroidTestResources'.
/Users/user/.gradle/caches/transforms-2/files-2.1/48609a786af4d1714850acbdd03ace31/jetified-beacon-ui-1.0.3/

AndroidManifest.xml:15:9-19:54: AAPT: error: resource string/hs_beacon_empty (aka com.example.feature.replay.test:string/hs_beacon_empty) not found.

We are getting these for several of our third party dependencies (facebook, leakcanary, beacon, etc.) They all seem to be libs that add values to existing xml files (strings.xml, AndroidManifest.xml)

It looks like part of the replay build process, AAPT is trying to find resources in our replay module that are actually in some other library. However why is AAPT looking in our replay feature module: com.example.android.feature.replay.test:string/hs_beacon_empty ?

I don't have a full grasp of how AAPT merges resources for dynamic modules, I have even less understanding how it does this for instrumentation test apks.

I didn't understand why this worked via CL so I looked at the top of Android Studio build logs and I see that when I run instrumentation tests

Executing tasks: [:replay:assembleDebug, :replay:assembleDebugAndroidTest, :app:assembleDebug, :app:assembleDebugAndroidTest]

So now the more basic question is why is Android Studio trying to assemble replay and replay test code when running tests for app module?


FWIW I'm running Android Studio and AGP 3.5 Beta 5

tir38
  • 9,810
  • 10
  • 64
  • 107

3 Answers3

7

I fixed it by adding app dependency also for androidTest in my dynamic feature module

implementation project(':app')
androidTestImplementation project(':app')
lilienberg
  • 1,252
  • 11
  • 18
2

I haven't found the answer to this issue, however, if you just want to run the tests for your :core, from the console you can just run gradle :app:connectedAndroidTest, and it should circumvent the DFM.

1

Since Android Studio is also processing the test resource for the dynamic module, you should implement(as test library) the respective library again in your dynamic module as following:

For example, if Android Studio could not find resources of beacon-ui library. Add androidTestImplementation "com.helpscout:beacon-ui:$beaconVersion" to your build.gradle(dynmic_module)

This might be a temporary workaround for this problem until this issue got fixed in the next release.