For the last little while, I am attempting to change a multi-module Android app to use the new com.android.dynamic-feature
plugin. Part of this change is moving my instrumentation tests out of the base module and have them test multiple features. The com.android.test
plugin seemed to enable me to do just that.
I had to notice though that the same test that runs fine when built from the androidTest
source set (using app:assembleDebugAndroidTest
) causes an odd error when built from the com.android.test
plugin (using app-tests:assemble
). In particular, there is a problem with AndroidX AppCompat when the test launches the Activity:
Caused by: java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat.
at androidx.appcompat.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:756)
at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:196)
at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
at biz.laenger.android.foo.app.presentation.main.MainActivity.onCreate(MainActivity.kt:28)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:674)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
... 9 more
I created this minimal sample project where the issue can be reproduced (steps in the readme).
I recognize the error above from when there is an actual issue with the theme. However, the theme is set correctly, and Activity creation works fine during "regular" instrumentation tests and when manually launching the app. The app and tests run on an API 28 device.
When configuring the :app-tests
module, I followed the instructions and ended up with this config:
apply plugin: 'com.android.test'
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
testApplicationId 'biz.laenger.android.foo.app.test'
testInstrumentationRunner 'biz.laenger.android.foo.app.FooTestApplicationRunner'
}
targetProjectPath ':app'
}
I also compared both test APKs from "regular" instrumentation tests and from com.android.test
and noticed the following:
- Manifests looks pretty much identical
- The
com.android.test
APK contains far more classes, including most/all of the:app
dependencies. This seems unnecessary.
Has anyone come across this issue or has a solution to this?