【问题标题】:Only on androidTest: Invoke-customs are only supported starting with Android O仅在 androidTest 上:仅从 Android O 开始支持 Invoke-customs
【发布时间】:2019-09-29 23:09:37
【问题描述】:

我的代码库使用了一些 Java 8 语法,例如 lambdas,并且在很长一段时间内一直运行良好。

最近,我在一个模块中的插桩测试停止处理臭名昭著的消息:

AGPBI: {"kind":"error","text":"仅支持调用自定义 从 Android O (--min-api 26)","sources":[{}],"tool":"D8"}

开始

这是一个已知问题(有 many questions 引用它),但我的 compileOptions 中有 Java 1.8:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

这个问题只出现在仪器测试(即 androidTest)中。单元测试和应用程序本身都很好。我已经注释掉了插桩测试中的所有测试,但问题仍然存在。

我的单元测试和 Android 测试具有相同的依赖关系。我转换为 AndroidX 测试,但问题仍然存在。

dependencies {
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-gcm:16.1.0'

    androidTestImplementation 'org.mockito:mockito-core:2.27.0'
    androidTestImplementation 'androidx.test:core:1.1.0'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test:rules:1.1.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.ext:truth:1.1.0'
    androidTestImplementation 'com.google.truth:truth:0.42'

    testImplementation 'org.mockito:mockito-core:2.27.0'    
    testImplementation 'androidx.test:core:1.1.0'
    testImplementation 'androidx.test:runner:1.1.1'
    testImplementation 'androidx.test:rules:1.1.1'    
    testImplementation 'androidx.test.ext:junit:1.1.0'
    testImplementation 'androidx.test.ext:truth:1.1.0'
    testImplementation 'com.google.truth:truth:0.42'
}

我正在使用最新的编译和目标版本(我也尝试过 26 和 27)以及构建工具。最低 SDK 版本是 14,应该是。

compileSdkVersion 28
buildToolsVersion '29.0.0 rc3'
defaultConfig {
    minSdkVersion 14
    targetSdkVersion 28
}

【问题讨论】:

  • 您的buildToolsVersion 与您的compileSdkVersiontargetSdkVersion 不匹配,这有点奇怪……这可能是罪魁祸首吗?
  • @BenP。不是真的,我使用的是 Android Studio 的测试版。不过,我也尝试了较旧的构建工具(版本 ~28),结果相同。
  • 所以我将其缩小到应用程序本身的构建工具 - 3.4.0 工作正常,3.5.0-beta01 没那么多。显然是 Android Studio 3.5 中的一个错误。
  • @EboMike 你有没有找到解决方案?

标签: java android android-gradle-plugin android-testing


【解决方案1】:

这是 Android Studio 3.5 测试版中的一个错误。我提交了bug with the Android Studio team,这将通过 Android Studio 3.5 beta 03 构建工具修复。

【讨论】:

  • 我认为它还没有修复。
  • 我仍然对 AS 3.5.3 和构建工具 29.0.2 有问题
  • 我在 Android Studio 4.0.1 中遇到了问题
  • 我仍然有 AS 4.1.2 的问题
【解决方案2】:

我遇到了同样的问题。当 Project 和 Clean Project 再次运行时。我的问题在于他的 org.apache.commons: commons-text:library。 改变 实施 'org.apache.commons: commons-text: 1.8' 到 实现 'org.apache.commons: commons-text: 1.6'

【讨论】:

    【解决方案3】:

    更新您的根 build.gradle 以使用最新的 android sdk(您可以使用 26 或 28)。

    android {
        compileSdkVersion 28
        flavorDimensions "default"
        defaultConfig {
            applicationId "com.example.myapplication"
            minSdkVersion 25
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    

    【讨论】:

    • 我使用的是最新的 SDK,但我的 minSdkVersion 是(并且应该是)14。
    猜你喜欢
    • 2020-06-25
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 2019-12-05
    • 2020-03-11
    • 1970-01-01
    相关资源
    最近更新 更多