Question

[Solved] Error: Invoke-customs are only supported starting with Android O (–min-api 26)

I have recently started learning how to program Android devices via Android Studio. My first app was running fine until I upgraded to Android Studio 3.4 this morning.

I’m getting the following compilation errors:

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:UsersTechnical.gradlecaches ransforms-2files-2.14f3f8638c6a9f961dae488a0387efb6bjarsclasses.jar

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.

Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete

Caused by: com.android.tools.r8.utils.AbortException: Error: Invoke-customs are only supported starting with Android O (–min-api 26)

Is there a way of reverting back to my previous version of Android Studio?

If not what has changed in the new version that is causing a failure in creating the dex file?

I have tried adding android.enableD8=true in gradle.properties as suggested here but no luck.


EDIT #1:

Have also tied adding multiDexEnabled true to the default configuration in the app build.gradle file but the same compilation errors persist.

That build file in full…

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "qdivision.org.qrtracker"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.github.felHR85:UsbSerial:6.0.5'
}
Enquirer: DrBwts

||

Solution #1:

Try to add below to your app/build.gradle to make your Android project compilation be compatible with Java 8.

android {
    ....
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    ....
}
Respondent: shizhen

Solution #2:

I had to remove useProguard true from the buildTypes configuration.

According to the documentation minifyEnabled true is enough to obfuscate your code with R8.

Example:

android {
    buildTypes {
        debug {
            versionNameSuffix "-dev"
            minifyEnabled true // <- remove this line when using instant run
            useProguard true // <- remove this line
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), "proguard-rules.pro"
        }

        release {
            shrinkResources true
            minifyEnabled true
            useProguard true // <- remove this line
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), "proguard-rules.pro"
        }
    }
}
Respondent: McFarlane

Solution #3:

What is relevant in this stacktrace is this line:

Caused by: com.android.tools.r8.utils.AbortException: Error: Invoke-customs are only supported starting with Android O (--min-api 26)

As there is not kotlin library in your dependencies, I assume you’re working with java. I would try answers in this issue

Respondent: Kuba Paw?owski

Solution #4:

in your Android Studio go to build.gradle(Module:App)
then add this compileOptions{} block into android{} block

android{
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}
Respondent: nayem

Solution #5:

If you are using Google Cloud library, try to decrease the version to 1.90

Respondent: Enayat Afridi

Solution #6:

Add the following to make your app to be compiled by java8 compiler.

android {

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

And disable instant-run found at

Preferences->Build,Execution,Deployment->Debugger->Instant Run

Respondent: Hagos Alema

Solution #7:

I have added to all modules these code:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

But error was still there.
In my case some of my modules used classpath ‘me.tatarka:gradle-retrolambda’ and it gave the conflict with this:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

So I have to migtrated from Retrolambda by this link:
https://developer.android.com/studio/write/java8-support#migrate_from_retrolambda

Respondent: Denis Fedak

Solution #8:

Please add this line in build.gradle file.

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

    }
}
Respondent: MEGHA DOBARIYA

Solution #9:

I had the same problem. Mine was caused by ... org.apache.commons:commons-lang .... I do not have the complete error message at the moment. This error only occurred during a Rebuild or Clean Build.

I Resolved by changing the org.apache.commons:commons-text:1.8 in my build.gradle to org.apache.commons:commons-text:1.6.

Note – There was a suggestion here to disable “Instant Run” in Android Studio. This feature was not available in my Android Studio. Version –

Android Studio 3.5.1
Build #AI-191.8026.42.35.5900203, built on September 26, 2019
Windows 10 10.0 
Respondent: Nikhil Girraj

Solution #10:

for kotlin you should also add kotlinOptions:

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

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
}

Solution #11:

for me solution with Java 8 started work only after I have removed all ting related to retrolambda.

Respondent: ViT-Vetal-

Solution #12:

For anyone else hitting this, I encountered this problem after adding a dependency on this Jackson library:

implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.1")

The “compileOptions” solution above fixed the issue for me

Respondent: davidfrancis

Solution #13:

for me following command in BUILD.GRADLE removed the error.

defaultConfig {
      applicationId "com.example.myapptestheader"
      minSdkVersion 21
      targetSdkVersion 29
      versionCode 1
      versionName "1.0"
      testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
   
      multiDexEnabled true
}

I just added

multiDexEnabled true

Solution #14:

This still works in 2021 please try it.

android {
    compileSdkVersion 30

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    defaultConfig {
        applicationId "com.example.android.bakingapp"
        minSdkVersion 15
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
Respondent: Abdulazeez Salihu

Solution #15:

For my case, It was also showing after adding the following lines –

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

So I fixed my problem just simply update my minSdkVersion from 19 to 21 and then finally it worked !!!

Respondent: Gk Mohammad Emon

Solution #16:

try this:

    defaultConfig {
    ...
    multiDexEnabled true
    }
Respondent: nes

Solution #17:

If you are trying to run apk directly from android studio, please try to avoid enabling

minifyEnabled true

Comment the following line.

//            minifyEnabled true
//            shrinkResources true

But you can use above line while building apk.

Respondent: vbp

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy