Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is android studio assembling our dyanimc feature module test apk?

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

like image 841
tir38 Avatar asked Jul 18 '19 19:07

tir38


People also ask

What is dynamic feature module in Android Studio?

Dynamic feature modules allow you to separate certain features and resources from the base module of your app and include them in your app bundle. Through Dynamic Delivery, users can later download and install those components on demand after they've already installed the base APK of your app.

What is module Android studio?

Modules. A module is a collection of source files and build settings that allow you to divide your project into discrete units of functionality. Your project can have one or many modules, and one module may use another module as a dependency. You can independently build, test, and debug each module.

What is play feature?

Play Feature Delivery uses advanced capabilities of app bundles, allowing certain features of your app to be delivered conditionally or downloaded on demand. To do that, first you need to separate these features from your base app into feature modules.


1 Answers

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

implementation project(':app')
androidTestImplementation project(':app')
like image 82
lilienberg Avatar answered Nov 13 '22 05:11

lilienberg