Android instrumented unit test will not run on one physical device - android

I have one device that throws an exception when I try to run unit tests on a project recently converted to use the androidX support libraries. The tests have run on emulators and other physical devices.
The device it will not run on is a Pixel 2 running 9.
App crashes with this exception:
AndroidRuntime: FATAL EXCEPTION: main
AndroidRuntime: PID: 7050
AndroidRuntime: java.lang.IllegalStateException: Call to getContentProviderExternal for: android_support_test_services.speak_easy returns null!
AndroidRuntime: at androidx.test.services.speakeasy.client.ToolConnection$ToolConnectionPostIcs.doCall(ToolConnection.java:155)
AndroidRuntime: at androidx.test.services.speakeasy.client.ToolConnection.publish(ToolConnection.java:93)
AndroidRuntime: at androidx.test.services.speakeasy.client.ToolConnection.publish(ToolConnection.java:83)
AndroidRuntime: at androidx.test.services.shellexecutor.BlockingPublish.getResult(BlockingPublish.java:79)
AndroidRuntime: at androidx.test.services.shellexecutor.ShellCommandExecutorServer.start(ShellCommandExecutorServer.java:80)
AndroidRuntime: at androidx.test.services.shellexecutor.ShellMain.main(ShellMain.java:45)
AndroidRuntime: at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
AndroidRuntime: at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:340)
AndroidRuntime: Error reporting crash
AndroidRuntime: java.lang.RuntimeException: Bad file descriptor
AndroidRuntime: at android.os.BinderProxy.transactNative(Native Method)
AndroidRuntime: at android.os.BinderProxy.transact(Binder.java:1127)
AndroidRuntime: at android.app.IActivityManager$Stub$Proxy.handleApplicationCrash(IActivityManager.java:3711)
AndroidRuntime: at com.android.internal.os.RuntimeInit$KillApplicationHandler.uncaughtException(RuntimeInit.java:143)
AndroidRuntime: at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
AndroidRuntime: at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
AndroidRuntime: at java.lang.Thread.dispatchUncaughtException(Thread.java:1955)
Simplified Unit Test:
import androidx.test.rule.ActivityTestRule
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
class MyTest {
#Rule
var activityTestRule: ActivityTestRule<AuthAppActivity> = object : ActivityTestRule<AuthAppActivity>(AuthAppActivity::class.java, false, false) {
override fun afterActivityLaunched() {
}
override fun beforeActivityLaunched() {
}
}
#Test
fun runTest() {
Assert.assertTrue(true); // low standards here
}
}
And the relevant dependencies:
testImplementation('junit:junit:4.12') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testImplementation 'org.hamcrest:hamcrest-library:1.3'
androidTestImplementation "androidx.annotation:annotation:1.0.0"
androidTestImplementation "androidx.test:runner:1.1.0"
androidTestImplementation "androidx.test:rules:1.1.0"
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation "androidx.test.espresso:espresso-core:3.1.0"
androidTestImplementation "androidx.test.espresso:espresso-idling-resource:3.1.0"
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.1.0"
androidTestImplementation "androidx.test.espresso:espresso-web:3.1.0"
androidTestImplementation "androidx.test.espresso:espresso-intents:3.1.0"

The provider android_support_test_services.speak_easy is obviously missing from the device. I ran the test on the working device and see that the same provider is used and found on that device. I pulled up an older branch, prior to AndroidX, ran the a instrumented test from there and then switched back, the error was gone.
Older version installed these versions:
test-services-1.0.2.apk
orchestrator-1.0.2.apk
Newer androidx:
orchestrator-1.1.0-alpha3.apk
test-services-1.1.0-alpha3.apk

I finally fixed this after realizing I was using an old version of Test Orchestrator link I was accidentally depending on the old android.support.test version, not the androidx.test version, even though I'd updated all the other test packages to androidx.test.

Related

Keep getting error on android studio project java.lang.VerifyError: Verifier rejected class com.google.firestore.v1.Value:

FATAL EXCEPTION: main
Process: com.example.sellit, PID: 21402
java.lang.VerifyError: Verifier rejected class com.google.firestore.v1.Value: void com.google.firestore.v1.Value.mergeGeoPointValue(com.google.type.LatLng) failed to verify: void com.google.firestore.v1.Value.mergeGeoPointValue(com.google.type.LatLng): [0x19] register v4 has type Precise Reference: com.google.type.LatLng but expected Reference: com.google.protobuf.GeneratedMessageLite
void com.google.firestore.v1.Value.mergeTimestampValue(com.google.protobuf.Timestamp) failed to verify: void com.google.firestore.v1.Value.mergeTimestampValue(com.google.protobuf.Timestamp): [0x19] register v4 has type Precise Reference: com.google.protobuf.Timestamp but expected Reference: com.google.protobuf.GeneratedMessageLite (declaration of 'com.google.firestore.v1.Value' appears in /data/app/~~f45OKSRu4zvHtUGPkqm61Q==/com.example.sellit-ypy_xq8iBTIqr4GuT8n7Ag==/base.apk!classes8.dex)
at com.google.firestore.v1.Value.getDefaultInstance(Value.java:1862)
at com.google.firestore.v1.MapValue$FieldsDefaultEntryHolder.<clinit>(MapValue.java:29)
at com.google.firestore.v1.MapValue.dynamicMethod(MapValue.java:421)
at com.google.protobuf.GeneratedMessageLite.dynamicMethod(GeneratedMessageLite.java:308)
at com.google.protobuf.GeneratedMessageLite.buildMessageInfo(GeneratedMessageLite.java:376)
at com.google.protobuf.GeneratedMessageInfoFactory.messageInfoFor(GeneratedMessageInfoFactory.java:60)
at com.google.protobuf.ManifestSchemaFactory$CompositeMessageInfoFactory.messageInfoFor(ManifestSchemaFactory.java:144)
at com.google.protobuf.ManifestSchemaFactory.createSchema(ManifestSchemaFactory.java:56)
at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:91)
at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:105)
at com.google.protobuf.GeneratedMessageLite.makeImmutable(GeneratedMessageLite.java:226)
at com.google.protobuf.GeneratedMessageLite.registerDefaultInstance(GeneratedMessageLite.java:411)
at com.google.firestore.v1.MapValue.<clinit>(MapValue.java:466)
at com.google.firestore.v1.MapValue.newBuilder(MapValue.java:228)
at com.google.firebase.firestore.UserDataReader.parseMap(UserDataReader.java:290)
at com.google.firebase.firestore.UserDataReader.parseData(UserDataReader.java:251)
at com.google.firebase.firestore.UserDataReader.convertAndParseDocumentData(UserDataReader.java:232)
at com.google.firebase.firestore.UserDataReader.parseSetData(UserDataReader.java:75)
at com.google.firebase.firestore.DocumentReference.set(DocumentReference.java:167)
at com.google.firebase.firestore.DocumentReference.set(DocumentReference.java:147)
at com.example.sellit.SignUpActivity$2.onComplete(SignUpActivity.java:79)
at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks##18.0.1:1)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
I am making an android app that uses firebase firestore for database. However I get the above error everytime I press the signup button.
I am calling this function in my signupactivity.java class
firebaseFirestore.collection(DATA_USERS).document(firebaseAuth.getUid()).set(user);
I have no idea how to fix this please help..
Ive tried:
in my build.gradle
implementation ('com.google.firebase:firebase-firestore:24.4.0'){
exclude module: 'protolite-well-known-types'
exclude module: 'protobuf-javalite'
exclude module: 'protobuf-java'
exclude module: 'protobuf-java-util'
//exclude module: "com.google.protobuf"
exclude module:'protobuf-lite'
exclude module:'proto-google-common-protos'
}
but this does not work.

Android coreLibraryDesugaringEnabled, connected test crash with NoSuchMethodError

I added coreLibraryDesugaringEnabled to our app, and it works fine for normal app runs.
compileOptions {
coreLibraryDesugaringEnabled true
}
and
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9'
However, when I run a connected test it crashes with no such method error on the Stream class:
16:03:56.426 11998 12041 E AndroidRuntime: FATAL EXCEPTION: com....
16:03:56.426 11998 12041 E AndroidRuntime: Process: ...
16:03:56.426 11998 12041 E AndroidRuntime: java.lang.NoSuchMethodError: No static method e([Ljava/lang/Object;)Lj$/util/stream/Stream; in class Lj$/util/n; or its super classes (declaration of 'j$.util.n' appears in /data/app/com....-qU6nwXthxze4O_9rcf1hGg==/base.apk!classes2.dex)
16:03:56.426 11998 12041 E AndroidRuntime: at j$.util.stream.Stream$-CC.of(:1000)
16:03:56.426 11998 12041 E AndroidRuntime: at ...
I found some vague reference that this might be because the class is referenced prior to the call to Multidex.install? I'm first referencing the class as a static initializer so it is accessed very early. Not sure if this is a red herring but thought I'd mention it.
If it helps the tests are run with AndroidJUnit4ClassRunner.
EDIT: I found a vague reference, in only one article stating that this is not supported in instrumentation tests:
Please note in Android Studio 4.0 using these library desugared types
in instrumented tests is not supported.
https://medium.com/androiddevelopers/support-for-newer-java-language-apis-bca79fc8ef65
but even the embedded video from Google on the feature doesn't say anything about that. Also not sure what the AS version would have to do with it. Perhaps they meant the AGP version.
This problem was fixed in com.android.tools:desugar_jdk_libs version 1.1.8 (at least).

Problems getting started with Chirp SDKs for Android

I have downloaded SDK for Android from
https://developers.chirp.io/downloads
After that I added *.aar library as was explain here:
https://developer.android.com/studio/projects/android-library.html#AddDependency
Hurrah. I can build the project.
Now I want to install the test App on the phone. But the application crashes like this:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.chirp.sdkdemoapp, PID: 12979
java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:2)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:5)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:8)
at io.chirp.sdkdemoapp.MainActivity.onCreate(MainActivity.java:77)
As I understand it, a problem arose with dependencies when packaging * aar
So I added in build.gradle (marked as Module) dependency for kotlin like:
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.2.61'
After that my ERROR has changed.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.chirp.sdkdemoapp, PID: 13395
java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/MediaType;
at io.chirp.b.a.<init>(Unknown Source:24)
at io.chirp.chirpsdk.a.<init>(Unknown Source:36)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:20)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:5)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:8)
at io.chirp.sdkdemoapp.MainActivity.onCreate(MainActivity.java:77)
I have wrong paths to io.chirp internal libraries.
What should I do to resolve dependency related errors?
You have to import the okhttp 3.12.x dependency required by the ChirpSDK.
However, you don't need to explicitly import the dependency if you are using the SDK from the maven repository as this will be already included:
implementation 'io.chirp:chirpsdk:3.10.0'
and add the repository in your parent maven file:
repositories {
maven {
url "https://maven.chirp.io/release"
}
}
Thanks Dinu for your answer!
Maven repository doesn't work in my case (proxy issues or something else but this is the topic of another discussion).
The problem with using offline ChirpSDK was solved by adding two dependencies:
implementation 'com.squareup.okhttp3:okhttp:3.12.6'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.50'

Android Runtime NoSuchMethodError

I recently started getting this error in certain scenarios at run time in my app...
I have already tried the following :
Add proguard rules to include com.google.common.
Mutlidex rules so that all the classes get packaged in main dex file
I have checked the apk contents to make sure the classes are present in the dex file...
Updgraded my guava android lib to latest 27.0.0-android
Updated gradle plugin and gradle version to the latest
AndroidRuntime: java.lang.NoSuchMethodError: No static method
checkArgument(ZLjava/lang/String;I)V in class
Lcom/google/common/base/Preconditions; or its super classes
(declaration of 'com.google.common.base.Preconditions' appears in
/data/app/com.myapp.dev.test-Xip2SNDMljPc2_BN0p3iRg==/base.apk!classes2.dex)
03-26 13:49:19.167 14658 14751 E AndroidRuntime: at
com.google.common.util.concurrent.RateLimiter.checkPermits(RateLimiter.java:424)
03-26 13:49:19.167 14658 14751 E AndroidRuntime: at
com.google.common.util.concurrent.RateLimiter.tryAcquire(RateLimiter.java:341)
03-26 13:49:19.167 14658 14751 E AndroidRuntime: at
com.google.common.util.concurrent.RateLimiter.tryAcquire(RateLimiter.java:325)
Not sure where to go from here now. Any ideas what else can I do ?
Try to add below proguard configuration
-keep class com.google.common.base.**

Instrumentation tests fail on virtual devices

I am using Jake Wharton's Double Espresso library for setting up Instrumentation tests in my app. The tests run fine on my phone but crash on any virtual device (I tried an emulator and Genymotion device).
The error I get is the IllegalAccessError that has been reported [previously]((Instrumentation run failed due to 'java.lang.IllegalAccessError'. Gradle + Espresso). However, what puzzles me is why it only happens on virtual devices. The setup should be fine if it's able to run on physical devices.
The stacktrace includes errors all over the place but the one reported as fatal is :
java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
at com.myApp.onCreate(MyApp.java:32)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
In any case, I tried excluding all the libraries that could have possible clashes but I still can't get it to work. Does anyone have any ideas on what the issue might be or even how to troubleshoot ?
The problem does seem to be related to daggger which is being used in the app as well. MyApp:32 points to the line where ObjectGraph is created and the following two lines are in the stacktrace.
W/dalvikvm﹕ Class resolved by unexpected DEX: Lcom/myApp/MyApp;(0xa4df7388):0x97542000 ref [Ldagger/ObjectGraph;] Ldagger/ObjectGraph;(0xa4df7388):0x97add000
W/dalvikvm﹕ (Lcom/myApp/MyApp; had used a different Ldagger/ObjectGraph; during pre-verification)
**UPDATE: ** The issue is likely related to the Dalvik VM on the virtual devices. My phone is set to ART and similar issues with Dalvik have been reported previously. It should be fixed by adding the following:
androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
exclude group: 'com.squareup.dagger'
}
as per the library page but that doesn't seem to help.
The issue was actually caused by the espresso-support library. I needed to add com.squareup.dagger as an exclusion there too while I was only adding exclusions to the other library.
androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
exclude group: 'com.squareup.dagger'
}
androidTestCompile ('com.jakewharton.espresso:espresso-support-v4:1.1-r3') {
exclude group: 'com.squareup.dagger' // this goes here too
exclude group: 'com.android.support', module: 'support-v4'
}

Categories

Resources