【问题标题】:Class descriptor 'Landroid/support/customtabs/ICustomTabsCallback/;' cannot be represented in dex format类描述符 'Landroid/support/customtabs/ICustomTabsCallback/;'不能用dex格式表示
【发布时间】:2019-03-09 10:10:51
【问题描述】:

我将我的 android studio 更新到版本 3.3 canary 13(截至撰写本文时的最新版本)。系统提示我更新项目的 gradle 版本,我将其更新为版本 3.3.0-alpha13

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

现在当我尝试运行我的项目时,它失败并出现错误

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

我试图使缓存无效,清理并重建项目,但没有任何效果。下面是我应用的 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'

}

【问题讨论】:

  • 请仔细检查 androidx import 。这可能是导致问题的原因
  • @TejasPandya 我设法解决了这个问题。见下方答案

标签: android android-studio android-gradle-plugin build.gradle


【解决方案1】:

我决定尝试./gradlew build --stacktrace 命令,发现ICustomTabsCallback 类正在被androidx.browser:browser:1.0.0-rc01 库使用。

> 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.

然后我使用./gradlew app:dependencies命令查看是否存在依赖冲突,我发现了错误。

 +--- 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 (*)

上面的摘录显示了debugCompileClasspath 配置的一些依赖关系。我们可以看到androidx.appcompat:appcompat 包含androidx.browser:browser 作为传递依赖。

androidx.appcompat:appcompat:1.0.0-rc01 -> 1.0.0 表示将使用版本1.0.0 而不是版本1.0.0-rc01,但androidx.browser:browser 不是这种情况。将使用版本 1.0.0-rc01 代替版本 1.0.0

为了解决这个错误,我只是通过在我的应用程序的build.gradle 中添加以下代码块来删除传递依赖项

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

所以我的应用程序的 build.gradle 将如下所示

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 {
// ....
}

在那之后,我刚刚同步、清理并重建了我的项目。

更新

如果答案不能解决您的问题,另一种选择是使用 android studio 稳定版(本文写作时为 3.2.1)和 gradle 3.2.1 classpath 'com.android.tools.build:gradle:3.2.1'

【讨论】:

  • 这不是一个有效的解决方案,如果您实际使用的是 customtabs。
  • @Marius 我没有使用自定义标签。如您所见,它在库androidx.browser:browser 中,它是androidx.appcompat:appcompat 库的传递依赖项
  • @AdamHurwitz 我的应用程序也连接到网络,我可以进行后端调用。我没有遇到过这样的错误。也许它与其他事情有关,但我很高兴你找到了解决问题的方法。
  • @AdamHurwitz 我将首先尝试其他解决方案。如果它不起作用并让新的 SO 生气,我会告诉你的。
  • 就像@AdamHurwitz 所说,这不是一个有效的答案,因为您正在删除可能会破坏您所依赖的库的传递依赖。这是 AGP 3.3.0-alpha13 的错误,请参阅 issuetracker.google.com/issues/117145286
【解决方案2】:

如果有人在让 AndroidX 与 Jetifier 一起工作时遇到过这个问题,那么您有几个选择。

如果您能够更新 Gradle 和插件版本,那么您应该这样做;这是在 3.3.0 及更高版本中解决的错误。你可以在这里看到你需要的 gradle/plugin 版本的组合; https://developer.android.com/studio/releases/gradle-plugin.

就我而言,我与 Gradle 4.6 相关联,它是 3.2.1 的最高插件版本(我使用的是 Unity 2017.4 LTS)。通过将以下内容添加到我的 build.gradle 文件中,我可以在其中应用找到 here 的解决方法;

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

感谢上面 cmets 中的@TheHebrewHammer 指出这一点。

【讨论】:

    【解决方案3】:

    尝试更改 styles.xml 中的主题,使其扩展 MaterialComponents 主题之一。

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    

    其他选项:

    Theme.MaterialComponents
    Theme.MaterialComponents.NoActionBar
    Theme.MaterialComponents.Light
    Theme.MaterialComponents.Light.NoActionBar
    Theme.MaterialComponents.Light.DarkActionBar
    

    更多信息: https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-10
      • 2015-12-06
      • 2014-01-26
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多