user2431170
user2431170

Reputation: 161

Android Studio doesn't import androidx testing classes properly

I have been working on sample UIAutomator project. I have created new Testcases using AndroidX Testing libraries.

I am able to build, run the test cases from the command line. But when I tried to open the app from Android Studio I can see most of the classes are not imported properly. For eg.,

import androidx.test.uiautomator.UiObject2;
import org.junit.Before;

The above two imports are showing as not imported. Likewise lots of classes are showing the same error except android.content.Context, android.content.Intent, etc.,

Can someone through some light on this. I am able to execute the testcases properly from the command line but not able to execute them properly from Android Studio.

I have Restarted PC/Studio, cleared caches, still the problem exists.

below is the dependency I have added in app/build.gradle.

androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'androidx.test:core:1.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.0.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'junit:junit:4.12'

Added the below code in gradle.properties

android.useAndroidX=true
android.enableJetifier=true

I have pretty much followed the same what I have got from android-testing-master/ui/uiautomator sample code, not sure what I am missing.

Upvotes: 3

Views: 1971

Answers (1)

Pavel Startsev
Pavel Startsev

Reputation: 38

I faced same problem too (Android Studio 3.4.2), uiautomator was red:

import androidx.test.uiautomator.UiDevice

"Clean Project" and "Rebuild Project" didn't help, even invalidating caches. But choosing another Build Variant helped me.

Upvotes: 0

Related Questions