Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:\Users\Technical.gradle\caches\transforms-2\files-2.1\4f3f8638c6a9f961dae488a0387efb6b\jars\classes.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'
}
like image 642
DrBwts Avatar asked Apr 23 '19 13:04

DrBwts


4 Answers

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
    }
    ....
}
like image 134
shizhen Avatar answered Oct 10 '22 04:10

shizhen


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"
        }
    }
}
like image 23
McFarlane Avatar answered Oct 10 '22 03:10

McFarlane


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
like image 2
droid_geek_shirish Avatar answered Oct 10 '22 04:10

droid_geek_shirish


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

like image 1
Kuba Pawłowski Avatar answered Oct 10 '22 03:10

Kuba Pawłowski