5

My codebase makes use of some Java 8 syntax like lambdas and has been working fine for the longest time.

Recently, my instrumented tests in a module stopped working with the infamous message:

AGPBI: {"kind":"error","text":"Invoke-customs are only supported starting with Android O (--min-api 26)","sources":[{}],"tool":"D8"}

This is a known problem (there are many questions referencing it), but I have Java 1.8 in my compileOptions:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

This problem ONLY shows up in the instrumented tests (i.e. androidTest). It's fine with unit tests and with the app itself. I already commented out all tests from the instrumented tests, but the problem persists.

My unit tests and Android tests have the same dependencies. I converted to AndroidX tests, but the issue persists.

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'
}

I'm using the latest compile and target versions (I also tried 26 and 27) and also build tools. The min SDK version is 14, and should be.

compileSdkVersion 28
buildToolsVersion '29.0.0 rc3'
defaultConfig {
    minSdkVersion 14
    targetSdkVersion 28
}
EboMike
  • 76,846
  • 14
  • 164
  • 167
  • It's a little odd that your `buildToolsVersion` doesn't match your `compileSdkVersion` or `targetSdkVersion`... any chance that's the culprit? – Ben P. May 13 '19 at 14:41
  • @BenP. Not really, I'm using the beta version of Android Studio. I tried older build tools as well though (version ~28), with the same result. – EboMike May 13 '19 at 15:11
  • So I narrowed it down to the build tools of the application itself - 3.4.0 works fine, 3.5.0-beta01 not so much. Apparently a bug in Android Studio 3.5. – EboMike May 14 '19 at 04:37
  • @EboMike have you ever find a solution for this? – savepopulation Jan 05 '20 at 12:24

3 Answers3

1

This is a bug in Android Studio 3.5 beta. I filed a bug with the Android Studio team, and this will be fixed with the Android Studio 3.5 beta 03 build tools.

EboMike
  • 76,846
  • 14
  • 164
  • 167
1

I had the same problem. When Project and Clean Project run again. the problem with me was in his org.apache.commons: commons-text:library. Change implementation 'org.apache.commons: commons-text: 1.8' To implementation 'org.apache.commons: commons-text: 1.6'

-2

Update your root build.gradle to use latest android sdk(you can use 26 or 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"
    }
Ranjan Kumar
  • 1,164
  • 7
  • 12