小编And*_*sik的帖子

在真实设备上测试时,uses-library com.android.nfc_extras会破坏api 26及以上版本的AndroidTest

我突然想通了这个宣言:

    <uses-library
        android:name="com.android.nfc_extras"
        android:required="false"/>
Run Code Online (Sandbox Code Playgroud)

<application>我的内部范围AndroidManifest.xml使仪器测试失败:

java.lang.NoSuchMethodError: No static method allOf(Lorg/hamcrest/Matcher;Lorg/hamcrest/Matcher;)Lorg/hamcrest/Matcher; in class Lorg/hamcrest/core/AllOf; or its super classes (declaration of 'org.hamcrest.core.AllOf' appears in /system/framework/com.android.nfc_extras.jar)
at org.hamcrest.Matchers.allOf(Matchers.java:33)
at android.support.test.espresso.Espresso.<clinit>(Espresso.java:187)
at android.support.test.espresso.Espresso.onView(Espresso.java:75)
at com.example.abusik.espressotest.InstrumentedTest.changeText_sameActivity(InstrumentedTest.kt:34)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
Run Code Online (Sandbox Code Playgroud)

我现在想出的是:

  • 为您创建了一个演示存储库,以便能够快速重现问题;
  • 只有API> = 26 的真实设备才会受到影响(例如三星SM-G935F,华为P20 lite);
  • 测试通过我尝试的任何API的仿真器;
  • 测试通过API <26的实际设备;
  • 看起来缺少类(以及他所有的静态方法)都包含在AndroidTest apk中,但在运行时Android尝试从com.android.nfc_extras.jar中获取此类.
  • 此行为可能取决于手机的NFC功能;
  • 对我来说,它看起来不像MultiDex或混淆问题 - 演示存储库没有混淆和单一dex.

Apk分析截图


我想知道是否有人遇到这个问题,为什么会发生这种情况,我怎样才能保持我的AndroidTests工作并仍然使用这个库?


我的InstrumentedTest.kt档案:

package com.example.abusik.espressotest

import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.action.ViewActions.*
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.matcher.ViewMatchers.withId
import …
Run Code Online (Sandbox Code Playgroud)

android nfc kotlin android-testing android-studio

7
推荐指数
1
解决办法
210
查看次数

将参数传递给具有多个上限的泛型函数

无法传递参数来Combiner().combine()起作用.

Android Studio无法识别arg扩展Foo和实现Bar.我究竟做错了什么?

abstract class Foo {
    val f: Int = 1
}

interface Bar {
    val b: String get() = "a"
}

class Combiner {
    fun <T> combine(arg: T): Pair<Int, String> where T : Foo, T : Bar {
        return arg.f to arg.b
    }
}

class Program {
    fun main() {
        val list: List<Foo> = arrayListOf()
        list.forEach {
            if (it is Bar) {
                Combiner().combine(it) //inferred type Any is not a subtype …
Run Code Online (Sandbox Code Playgroud)

generics polymorphism casting kotlin

6
推荐指数
1
解决办法
250
查看次数