Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class descriptor 'Landroid/support/customtabs/ICustomTabsCallback/;' cannot be represented in dex format

I updated my android studio to version 3.3 canary 13 (latest as of this writing). I was prompted to update my project's gradle version and I updated it to version 3.3.0-alpha13

classpath 'com.android.tools.build:gradle:3.3.0-alpha13'

Now when i tried to run my project, it failed with an error

Error: Class descriptor 'Landroid/support/customtabs/ICustomTabsCallback/;' cannot be represented in dex format.

I tried to invalidate cache, clean and rebuild the project but nothing worked. Below is my app's build.gradle

dependencies {

implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha3', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'

}
like image 848
Edijae Crusar Avatar asked Oct 04 '18 05:10

Edijae Crusar


2 Answers

I decided to try ./gradlew build --stacktrace command and saw that ICustomTabsCallback class is being used by androidx.browser:browser:1.0.0-rc01 library.

> Transform browser.aar (androidx.browser:browser:1.0.0-rc01) with DexingTransform
AGPBI: {"kind":"error","text":"Class descriptor \u0027Landroid/support/customtabs/ICustomTabsCallback/;\u0027 cannot be represented in dex format.","sources":[{}],"tool":"D8"}

> Task :app:mergeExtDexDebug FAILED
AGPBI: {"kind":"error","text":"Class descriptor \u0027Landroid/support/customtabs/ICustomTabsCallback/;\u0027 cannot be represented in dex format.","sources":[{}],"tool":"D8"}

FAILURE: Build failed with an exception.

I then used ./gradlew app:dependencies command to see if there is conflict in dependencies and i found the error.

 +--- androidx.appcompat:appcompat:1.0.0-rc01 -> 1.0.0 (*)
|    \--- androidx.browser:browser:1.0.0-rc01
|         +--- androidx.core:core:1.0.0-rc01 -> 1.0.0 (*)
|         +--- androidx.annotation:annotation:1.0.0-rc01 -> 1.0.0
|         +--- androidx.interpolator:interpolator:1.0.0-rc01 -> 1.0.0 (*)
|         +--- androidx.collection:collection:1.0.0-rc01 -> 1.0.0 (*)
|         \--- androidx.legacy:legacy-support-core-ui:1.0.0-rc01 -> 1.0.0 (*)

The above extract shows some of dependencies for debugCompileClasspath configuration. We can see that androidx.appcompat:appcompat contains androidx.browser:browser as a transitive dependency.

androidx.appcompat:appcompat:1.0.0-rc01 -> 1.0.0 means that version 1.0.0 will be used instead of version 1.0.0-rc01 but this is not the case for androidx.browser:browser. version 1.0.0-rc01 will be used instead of version 1.0.0

To solve this error, i just removed the transitive dependencies by adding the below block of code in my app's build.gradle

configurations {
    compile.exclude group: 'androidx.browser', module: 'browser'
}

So my app's build.gradle will look like this

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'

android {
    //....
}

configurations {
    compile.exclude group: 'androidx.browser', module: 'browser'
}

dependencies {
// ....
}

After that, i just synced,cleaned and rebuild my project.

UPDATE

If the answer din't solve your problem, The other option is to use android studio stable version (3.2.1 as per this writing) and gradle 3.2.1 classpath 'com.android.tools.build:gradle:3.2.1'

like image 147
Edijae Crusar Avatar answered Sep 29 '22 20:09

Edijae Crusar


If anyone has had this problem with getting AndroidX to work with the Jetifier then you have a couple of options.

If you are able to update your Gradle and plugin version then you should do; this is a bug that was addressed 3.3.0 and above. You can see what combination of gradle/plugin versions you need here; https://developer.android.com/studio/releases/gradle-plugin.

In my case I was tied to Gradle 4.6 and it's highest plugin version of 3.2.1 (i'm using Unity 2017.4 LTS). In which can I applied the workaround found here by adding the following to my build.gradle file;

buildscript {    
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta02'
    }
}

Credit to @TheHebrewHammer in the comments above for pointing this one out.

like image 34
JimmyDeemo Avatar answered Sep 29 '22 20:09

JimmyDeemo