首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android-jetifier:“无法解决所有工件”;“未能在新项目上转换工件”。

android-jetifier:“无法解决所有工件”;“未能在新项目上转换工件”。
EN

Stack Overflow用户
提问于 2019-09-15 14:00:06
回答 3查看 23.9K关注 0票数 10

我有一个相对较新的项目,我正在努力建立。Gradle同步很好,但是每当我尝试构建时,我都会得到如下错误:

代码语言:javascript
复制
Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.
> Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.
   > Failed to transform artifact 'common.jar (com.android.tools:common:26.4.0)' to match attributes {artifactType=android-classes, org.gradle.usage=java-runtime-jars}.
      > Execution failed for JetifyTransform: C:\Users\Dave\.gradle\caches\modules-2\files-2.1\com.android.tools\common\26.4.0\539939e284fba9fe343b890a6e21c9333767c886\common-26.4.0.jar.
         > Failed to transform 'C:\Users\Dave\.gradle\caches\modules-2\files-2.1\com.android.tools\common\26.4.0\539939e284fba9fe343b890a6e21c9333767c886\common-26.4.0.jar' using Jetifier. Reason: The given artifact contains a string literal with a package reference 'android.support.design.widget' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.. (Run with --stacktrace for more details.)
   > Failed to transform artifact 'bundletool.jar (com.android.tools.build:bundletool:0.7.2)' to match attributes {artifactType=android-classes, org.gradle.usage=java-runtime-jars}.
      > Execution failed for JetifyTransform: C:\Users\Dave\.gradle\caches\modules-2\files-2.1\com.android.tools.build\bundletool\0.7.2\31f71b66edcbe41de0268e14c961a7799a03d42a\bundletool-0.7.2.jar.
         > Failed to transform 'C:\Users\Dave\.gradle\caches\modules-2\files-2.1\com.android.tools.build\bundletool\0.7.2\31f71b66edcbe41de0268e14c961a7799a03d42a\bundletool-0.7.2.jar' using Jetifier. Reason: The given artifact contains a string literal with a package reference 'android.support.design.widget' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.. (Run with --stacktrace for more details.)

我一周前才开始这个项目,一直在使用Android的稳定分支,并使用Gradle插件3.5。有谁有办法解决这个问题吗?

我尝试过的:

  • 在gradle.properties中禁用Jetifier给我留下了关于旧的和新的绑定依赖项的错误。
  • 回滚到Gradle插件3.4.2给出了与上面相同的错误。
  • android.jetifier.blacklist = pass添加到gradle.properties给我留下了与上面相同的错误。
  • android.databinding.enableV2=true添加到gradle.properties给我留下了与上面相同的错误。
  • 在AndroidX中运行“迁移到AndroidX”重构实际上给我留下了这个奇怪的重构预览:

  • apply plugin: 'kotlin-kapt'从应用程序级别的build.gradle中删除,会给我带来与上面相同的错误。
  • 打扫和重建都不管用。
  • 使之无效和重新启动是行不通的。

编辑1:级依赖关系,对于好奇的..。我不觉得我用了什么特别奇怪的东西。

代码语言:javascript
复制
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //Kotlin stuff
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"
    //Test tools
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    //UI
    implementation 'com.google.android.material:material:1.1.0-alpha10'
    implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.activity:activity:1.1.0-alpha03'
    //Lifecycle
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha04'
    //Moshi for serialization
    implementation 'com.squareup.moshi:moshi:1.8.0'
    implementation 'com.squareup.moshi:moshi-kotlin:1.8.0'
    //Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.6.1'
    implementation 'com.squareup.retrofit2:converter-moshi:2.6.1'
    //Glide
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    implementation 'com.github.bumptech.glide:okhttp3-integration:4.9.0'
    //Navigation
    implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
    implementation 'androidx.navigation:navigation-common-ktx:2.1.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'
    implementation "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0"
    //Diff utils
    implementation group: 'io.github.java-diff-utils', name: 'java-diff-utils', version: '4.0'
    //Timber for logging
    implementation 'com.jakewharton.timber:timber:4.7.1'
}

编辑2:将我的Gradle依赖项粘贴到一个新的空项目中,并得到了相同的错误。它会是这些依赖关系之一吗?

编辑3:注释了来自my build.gradle的各种库(Moshi,Retrofit,Timber,Glide)也没有任何效果。所以,我可能应该向Google提交一份bug报告。在那之前,有什么解决办法?

编辑4:有来自评论的建议,我尝试删除我的.gradle文件夹并回滚回材料设计库的早期版本。两者都没有效果,但后者在构建日志中添加了一些有趣的内容:

代码语言:javascript
复制
> Transform artifact kotlin-build-common.jar (org.jetbrains.kotlin:kotlin-build-common:1.3.20) with DexingNoClasspathTransform
AGPBI: {"kind":"error","text":"Invoke-customs are only supported starting with Android O (--min-api 26)","sources":[{}],"tool":"D8"}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-09-22 00:54:03

您不应该将androidx.navigation:navigation-safe-args-gradle-plugin放在应用程序级别的build.gradle中。需要移除。

票数 13
EN

Stack Overflow用户

发布于 2019-09-24 13:43:42

调用-海关只支持从Android开始(--min 26)。

这意味着,你至少需要:

代码语言:javascript
复制
compileSdkVersion 26
targetSdkVersion 26
票数 1
EN

Stack Overflow用户

发布于 2019-11-05 11:14:58

在我的例子中,我更新了android,它自动更新了我的gradle版本,构建失败了,返回旧版本解决了问题。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57944812

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档