appium-espresso-driver: Resources$NotFoundException Resource is not a Drawable

Appium v1.12.0 I’m not very familiar with Appium, this is my first crack at this.

I get the following exception when I try to start an Appium session with espresso. The crash is happening in the onCreate method of all my activities (I’ve tried starting with different activities) via androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71). This crash does not happen when I change the driver to UiAutomator2, run the app on its own, or run my Espresso test suite. The crash only occurs when I run through Appium via the Espresso driver.

My config JSON:

{
  "deviceName": "P500",
  "platformName": "Android",
  "platformVersion": 21,
  "automationName": "Espresso",
  "app": "C:\\builds\\redacted-debug.apk",
  "appPackage": "com.redacted.debug",
  "udid": "123456789",
  "appActivity": "com.redacted.activity.SplashActivity",
  "noReset": true,
  "skipUnlock": true
}

Exception Stack trace:

04-26 22:29:07.231 31232 31232 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.redacted.debug/com.redacted.activity.SetupActivity}: android.content.res.Resources$NotFoundException: Resource "com.redacted.debug:dimen/cockpit_section_status_max_width" (7f070059)  is not a Drawable (color or path): TypedValue{t=0x5/d=0x25801 a=2 r=0x7f070059}
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.app.ActivityThread.access$800(ActivityThread.java:151)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.os.Handler.dispatchMessage(Handler.java:102)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.os.Looper.loop(Looper.java:135)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.app.ActivityThread.main(ActivityThread.java:5257)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at java.lang.reflect.Method.invoke(Native Method)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at java.lang.reflect.Method.invoke(Method.java:372)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
04-26 22:29:07.231 31232 31232 E AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: Resource "com.redacted.debug:dimen/cockpit_section_status_max_width" (7f070059)  is not a Drawable (color or path): TypedValue{t=0x5/d=0x25801 a=2 r=0x7f070059}
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.content.res.Resources.loadDrawableForCookie(Resources.java:2441)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.content.res.Resources.loadDrawable(Resources.java:2381)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.content.res.Resources.getDrawable(Resources.java:787)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.content.Context.getDrawable(Context.java:403)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:463)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at androidx.appcompat.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:753)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:196)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at com.redacted.activity.SetupActivity.onCreate(SetupActivity.java:125)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.app.Activity.performCreate(Activity.java:6013)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:674)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
04-26 22:29:07.231 31232 31232 E AndroidRuntime:       ... 10 more

Trying with Appium 1.13.0 gives me a different error:

[debug] [MJSONWP] Encountered internal error running command: Error: java.lang.SecurityException: Permission Denial: starting instrumentation ComponentInfo{io.appium.espressoserver.test/androidx.test.runner.AndroidJUnitRunner} from pid=13136, uid=13136 not allowed because package io.appium.espressoserver.test does not have a signature matching the target com.redacted.debug

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 9
  • Comments: 62 (10 by maintainers)

Most upvoted comments

I’ve managed to fix it for our app by changing this driver:

  • changed all SDK versions in both build.gradle and server manifest to match versions in AUT
  • disabled transitive dependencies for espresso-contrib (I guess these dependencies are main cause for this issue)
  • excluded androidx.test.espresso group from transitive dependencies of espresso-web

Overall I think Android build process is too complex to have espresso server setup as simple as it is now. I’d be much more confident in the server if it had most android dependencies compileOnly and its manifest were generated based on AUT manifest.

But crash doesn’t happen when I run Espresso tests. This only happen when I run my Appium tests with Espresso driver.

It should be possible to fix this issue with espressoBuildConfig capability (just added PR with docs on it - https://github.com/appium/appium/pull/13766) and a config like this (if an app under test uses material components):

{
  "additionalAppDependencies": [
    "com.google.android.material:material:1.0.0",
    "androidx.lifecycle:lifecycle-extensions:2.1.0"
  ]
}

lifecycle-extensions line is based on fix by @uterator and perhaps it is not needed when there is no errors related to lifecycle classes.

As for now, I am passing this data in a file to espressoBuildConfig capability, and it works as nothing had happened.

{
  "toolsVersions": {
    "gradle": "5.1.1",
    "androidGradlePlugin": "3.4.2",
    "compileSdk": 28,
    "buildTools": "28.0.3",
    "minSdk": 18,
    "targetSdk": 28,
    "kotlin": "1.3.31"
  },
  "additionalAppDependencies": [
    "androidx.lifecycle:lifecycle-extensions:2.2.0"
  ]
}
  • disabled transitive dependencies for espresso-contrib

I’ve managed to fix it for our app by changing this driver:

  • changed all SDK versions in both build.gradle and server manifest to match versions in AUT
  • disabled transitive dependencies for espresso-contrib (I guess these dependencies are main cause for this issue)
  • excluded androidx.test.espresso group from transitive dependencies of espresso-web

Overall I think Android build process is too complex to have espresso server setup as simple as it is now. I’d be much more confident in the server if it had most android dependencies compileOnly and its manifest were generated based on AUT manifest.

Two questions @TarCV ,

  1. Could you share sample build.gradle files that have these changes?
  2. Which app Im I supposed to make these changes in?

I found a fix for the lifecycle errors. In the espresso-server/app/build.gradle file, I had to add the following deps according to the docs

def lifecycle_version = "2.1.0"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"

@aldochristiaan @TarCV - After a new app release i am getting this exception now while starting espresso server session. Not sure if this is due to the changes i did for fix the above issue.

10-01 18:12:40.662 E/AndroidRuntime(14681): Process: com.gamma.passenger, PID: 14681
10-01 18:12:40.662 E/AndroidRuntime(14681): java.lang.NoSuchMethodError: No static method lifecycleEventObserver(Ljava/lang/Object;)Landroidx/lifecycle/LifecycleEventObserver; in class Landroidx/lifecycle/Lifecycling; or its super classes (declaration of 'androidx.lifecycle.Lifecycling' appears in /data/app/io.appium.espressoserver.test-1/base.apk)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at androidx.lifecycle.LifecycleRegistry$ObserverWithState.<init>(LifecycleRegistry.java:354)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:170)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at androidx.activity.ComponentActivity.<init>(ComponentActivity.java:94)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at androidx.fragment.app.FragmentActivity.<init>(FragmentActivity.java:127)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at androidx.appcompat.app.AppCompatActivity.<init>(AppCompatActivity.java:77)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at com.gamma.base.lifecycle.ExtensibleActivity.<init>(ExtensibleActivity.kt:16)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at com.gamma.base.rx.lifecycle.RxActivity.<init>(RxActivity.kt:24)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at com.gamma.utils.permissions.BasePermissionActivity.<init>(BasePermissionActivity.kt:18)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at com.gamma.pax.newface.presentation.newface.NewFace.<init>(NewFace.kt:122)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at java.lang.Class.newInstance(Native Method)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at android.app.Instrumentation.newActivity(Instrumentation.java:1100)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at androidx.test.runner.MonitoringInstrumentation.newActivity(MonitoringInstrumentation.java:761)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2570)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at android.app.ActivityThread.-wrap12(ActivityThread.java)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at android.os.Handler.dispatchMessage(Handler.java:102)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at android.os.Looper.loop(Looper.java:154)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at android.app.ActivityThread.main(ActivityThread.java:6165)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at java.lang.reflect.Method.invoke(Native Method)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
10-01 18:12:40.662 E/AndroidRuntime(14681): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)`

Were you using release version for automation ? I experienced this too and had a talk with our developer and in the end we found the root cause. Try to changeproguard rules in your local machine and build the release version APK using this configuration :

-dontwarn com.google.android.material.**
-keep class com.google.android.material.** { *; }

-dontwarn androidx.**
-keep class androidx.** { *; }
-keep interface androidx.** { *; }

-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }

-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }

I’m sure this will solve your problem … And don’t forget to push the changes to the code base 😬

Maybe we should add documentation for this too @mykola-mokhnach

@poojachoudhary13 you should replace default appium espresso server APK inside /usr/local/lib/node_modules/appium/node_modules/appium-espresso-driver/espresso-server/app/build/outputs/apk/androidTest/debug/ with newly generated APK with changes that @TarCV mentioned above …

Don’t use capability forceEspressoRebuild after you replace the APK …

here my specific error :

[Espresso] [Instrumentation] [STDOUT] android.content.res.Resources$NotFoundException: Drawable com.appname.android.staging:dimen/dimen_name_icon_size with resource ID #0x7f070059 [debug] [Espresso] [Instrumentation] [STDOUT] Caused by: android.content.res.Resources$NotFoundException: Resource “com.appname.android.staging:dimen/dimen_name_icon_size” (7f070059) is not a Drawable (color or path): TypedValue{t=0x5/d=0x3801 a=2 r=0x7f070059}

Here are the dependencies which work, no Drawable or Lifecycle errors are stopping the execution anymore

   ext.espresso_version = "3.2.0"
   ext.testlib_version = "1.2.0"
   ext.mocklib_version = "1.7.4"
   ext.lifecycle_version = "2.1.0"
   
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"

   testImplementation "org.powermock:powermock-api-mockito2:$mocklib_version"
   testImplementation "org.powermock:powermock-classloading-xstream:$mocklib_version"
   testImplementation "org.powermock:powermock-module-junit4-rule:$mocklib_version"
   testImplementation "org.powermock:powermock-module-junit4:$mocklib_version"
   testImplementation "androidx.test.espresso:espresso-contrib:$espresso_version"
   testImplementation "androidx.test.espresso:espresso-core:$espresso_version"

   testImplementation ("androidx.test.espresso:espresso-web:$espresso_version"){
        exclude group: 'androidx.test.espresso'
   }

   testImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
   testImplementation "androidx.test:core:$testlib_version"
   testImplementation "androidx.test:runner:$testlib_version"
   testImplementation "androidx.test:rules:$testlib_version"
   testImplementation 'com.google.code.gson:gson:2.8.5'
   testImplementation 'javax.ws.rs:jsr311-api:1.1.1'
   testImplementation 'junit:junit:4.12'
   testImplementation 'org.mockito:mockito-core:2.8.9'
   testImplementation 'org.nanohttpd:nanohttpd-webserver:2.3.1'
   testImplementation 'org.robolectric:robolectric:4.0.2'
   testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
   testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
   testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

   androidTestImplementation("androidx.test.espresso:espresso-contrib:$espresso_version") {
       transitive = false
   }

   androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version"
   androidTestImplementation "androidx.test.espresso:espresso-web:$espresso_version"
   androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
   androidTestImplementation "androidx.test:core:$testlib_version"
   androidTestImplementation "androidx.test:runner:$testlib_version"
   androidTestImplementation "androidx.test:rules:$testlib_version"
   androidTestImplementation 'com.google.code.gson:gson:2.8.5'
   androidTestImplementation 'javax.ws.rs:jsr311-api:1.1.1'
   androidTestImplementation 'org.nanohttpd:nanohttpd-webserver:2.3.1'
   androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
   androidTestImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
   androidTestImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

Also some resource related failures may be because Espresso driver server APK doesn’t have some application dependencies. I’m implementing the related feature as part of #496 You can check if this is the case by building Espresso driver server inside androidTest directory of your app (i.e. by building it as if it was an Espresso test for your app). Note that you’ll need to add dependencies from https://github.com/appium/appium-espresso-driver/blob/master/espresso-server/app/build.gradle#L63-L72 (and Kotlin lines too if Kotlin is not used in your app).

I can run my Espresso tests outside of Appium without issue. Is that what you mean by “rebuilding your app with Espresso”?