android-jetifier: "Could not resolve all artifacts"; "Failed to transform artifact" on new project
Asked Answered
I

3

14

I have a relatively new project that I'm trying to build. Gradle syncs fine, but whenever I try to build, I get an error like this:

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

I only started this project a week ago, and have been using the stable branch of Android Studio and using Gradle plugin 3.5. So, anyone have any ideas how to fix this?

What I've tried:

  • Disabling Jetifier in gradle.properties left me with errors about old and new databinding dependencies.
  • Rolling back to Gradle plugin 3.4.2 gave the same error as above.
  • Adding android.jetifier.blacklist = pass to gradle.properties left me with the same errors as above.
  • Adding android.databinding.enableV2=true to gradle.properties left me with the same errors as above.
  • Running the "Migrate to AndroidX" refactor in Android Studio actually left me with this weird refactor preview: Why am I refactoring the library that I'm trying to refactor to?
  • Removing apply plugin: 'kotlin-kapt' from my app-level build.gradle left me with the same errors as above.
  • Cleaning and rebuilding doesn't work.
  • Invalidating and restarting doesn't work.

EDIT 1: Gradle dependencies, for the curious... I don't think I'm using anything particularly weird here.

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'
}

Edit 2: Copy-pasted my Gradle dependencies into a new empty project and got the same errors. Could it be one of these dependencies?

Edit 3: Commenting out various libraries from my build.gradle (Moshi, Retrofit, Timber, Glide) also had no effect. So, I probably should submit a bug report to Google. Until then, what's the workaround?

Edit 4: With suggestions from the comments, I tried deleting my .gradle folder and rolling back to an earlier version of the Material design library. Both had no effect, but the latter added something interesting to the build log:

> 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"}
Isabelleisac answered 15/9, 2019 at 14:0 Comment(8)
are you using butterknife?Burrstone
@ZaferCelaloglu Nope. Never even heard of it.Isabelleisac
try deleting .gradle folder and rebuilding project (take a bakup of .gradle folder as well )Kissner
@AdeelTurk See edit. I tried that with the new empty project, and got the same result.Isabelleisac
can you try changing matreial version from alpha 10 to 07 -> 1.1.0-alpha07Kissner
@AdeelTurk See new edit.Isabelleisac
Do you have Java 8 enabled in Gradle? Desugaring ought to fix it, and that should fix your latest error.Berthold
@Berthold Tried adding the appropriate compileOptions and kotlinOptions to my build.gradle as per this: developer.android.com/studio/write/java8-support No change. But it was something I hadn't tried.Isabelleisac
I
14

You are not supposed to put the androidx.navigation:navigation-safe-args-gradle-plugin in your app level build.gradle. That needed to be removed.

Isabelleisac answered 22/9, 2019 at 0:54 Comment(1)
link This may help!Cultivate
H
1

Invoke-customs are only supported starting with Android O (--min-api 26).

This means, you'd need at least:

compileSdkVersion 26
targetSdkVersion 26
Housum answered 24/9, 2019 at 13:43 Comment(0)
F
-1

In my case i updated android studio, automatically it updated my gradle version and the build faled, returning the old version solved the problema.

Faculty answered 5/11, 2019 at 11:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.