660

before i'm use build version gradle 26 but after change buildtoolsversion to 27 like as this image

I am using android studio 4.2.2 recently i update all my dependency and

      sourceCompatibility JavaVersion.VERSION_1_10
      targetCompatibility JavaVersion.VERSION_1_10

to

compileOptions {
           sourceCompatibility kotlin_version
           targetCompatibility kotlin_version
         }

after update i am getting this error please help

error : error build gradle screenshot

6
  • 84
    Do not attach screenshots/images with code/error messages. Post the actual (relevant) code + error message.
    – Robert
    Commented Apr 18, 2018 at 8:56
  • 1
    I started to get similar issues when i converted inline callbacks to lambda functions. Intellj was asking it. But compiler does not like it. Commented May 23, 2018 at 22:28
  • 6
    It is a shame that the OP did not come back and mark an answer as correct, even though there is one. Actually, all three are, depending on whether you are using java 7, 8, or 10. Bottom line is, you need to inform the build what language level you are using. And yes, the screen caps are pretty much unreadable on the page. Commented Sep 18, 2018 at 20:19
  • 1
    That did not work for me. But adding it to a module's build.gradle did work. See Galley's Dec. 19 comment. Project is github.com/jrasor/ftc_5197all2019; module is TeamCode.
    – John Rasor
    Commented Feb 27, 2019 at 21:13
  • 2

5 Answers 5

2393

After hours of struggling, I solved it by including the following within app/build.gradle:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

https://github.com/mapbox/mapbox-gl-native/issues/11378

12
  • 4
    This even seems to be the case when the gradle build says that it failed in a nother module. If module A has the declaration but B does not, sometimes for me it failed in A. After I added it to B it doesn't fail anymore
    – avalancha
    Commented Aug 9, 2018 at 10:42
  • 164
    Android Studio devs need to change this error description. This Error: Invoke-customs are only supported starting with Android O (--min-api 26) tells nothing. Thank you so much for sharing your findings. You saved others time.
    – Zeeshan
    Commented Mar 28, 2019 at 21:25
  • 3
    After i add apachi commons lang library to project i faced this error.Then after add above code fixed my error.Thanks.
    – Saeid Z
    Commented Jun 9, 2019 at 15:42
  • 1
    Wait!! How can this be made default in Android Studio. I don't want to use this in every project I create. Commented May 24, 2020 at 13:34
  • 1
    Thanks for this. But does anyone know why this happens?
    – Branddd
    Commented Nov 16, 2020 at 9:47
53

If compileOptions doesn't work, try this

Disable 'Instant Run'.

Android Studio -> File -> Settings -> Build, Execution, Deployment -> Instant Run -> Disable checkbox

5
  • 7
    This and only this worked for me. Very annoying as this seems like a bug in Android Studio. Instant run is a needed feature - anyone know how to resolve this error and make use of instant run?
    – AlexVPerl
    Commented Mar 27, 2019 at 6:28
  • 3
    Instant Run is a grand headache. I can't count how much time I have lost due to this not so useful to saving time tool. I've always ended up disabling it on all my projects. I don't think is as much needed. Commented Apr 23, 2019 at 9:19
  • 3
    Had this same problem after updating to Android Studio 3.4 and Gradle 5.1. Disabling Instant Run did the trick! Thanks
    – Henrique
    Commented Apr 24, 2019 at 15:59
  • 8
    This option is not available in my Android Studio. Details - (Android Studio 3.5.1 Build #AI-191.8026.42.35.5900203, built on September 26, 2019 JRE: 1.8.0_202-release-1483-b03 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0) Commented Apr 18, 2020 at 18:57
  • which version of ANdroid studio is this?
    – gumuruh
    Commented Apr 27, 2023 at 8:06
30

In my case the error was still there, because my system used upgraded Java. If you are using Java 10, modify the compileOptions:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_10
    targetCompatibility JavaVersion.VERSION_1_10

}
2
  • 16
    wait.. we can target Java 10 for Android development?
    – kassim
    Commented Feb 8, 2019 at 9:26
  • 6
    yes @kassim ctrl click the version to see other versions
    – Lucem
    Commented Mar 19, 2019 at 15:06
24

If you have Java 7 so include the below following snippet within your app-level build.gradle :

compileOptions {

    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7

}
3
  • 4
    It is also necessary to set the minSdkVersion and targetSdkVersion according to the min api reported in the error message. build.gradle : defaultConfig { applicationId "com.mypack.myapp" minSdkVersion 26 targetSdkVersion 29 versionCode 1 versionName "1.0" ... } Commented Jul 17, 2020 at 17:06
  • Used same solution for Java 8, changed to: VERSION_1_8.
    – Elletlar
    Commented Nov 23, 2020 at 18:59
  • compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } go to build.gradle and add this file
    – Aqif
    Commented Jul 30, 2021 at 7:54
2

Try downgrading one or more of your libraries (Gradle dependencies). The most recent versions usually have less backwards-compatibility support.

For example:

build.gradle

dependencies {
    // Version 2.5.1 was released on 27 July 2022
    // This will produce the error:
    // "Invoke-customs are only supported starting with android 0 --min-api 26"
    // if you're using minSdkVersion 21 (Android 5.0)
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
}

If you downgrade this particular library to version 2.2.0, it will fix the error:

build.gradle

dependencies {
    // Version 2.2.0 was released on 22 Jan 2020
    // This will fix the error:
    // "Invoke-customs are only supported starting with android 0 --min-api 26"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
}

You can see the available versions and release dates here: https://maven.google.com/

1
  • Yes, for me changing JavaVersion did not help. I had to downgrade google-services version from 4.4.0 to 4.3.15
    – userVadim
    Commented Nov 23, 2023 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.