简体   繁体   中英

Android Jetifier fails to convert data binding generated support library to AndroidX

I have an Android project that has been migrated to AndroidX. At some point, I want to add a new library. This library is using a support library with data binding.

I have enabled Android Jetifier in my gradle.properties. I am using Android Gradle build tool v.3.3.2 and Gradle v.4.10.1.

Here is my gradle.properties:

org.gradle.jvmargs=-Xmx1536m
kotlin.code.style=official
android.useAndroidX=true
android.enableJetifier=true

Here is my build.gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dataBinding {
        enabled = true
    }
}

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '28.0.0'
            }
        }

    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation <library with AndroidX and data binding>
}

I got the following error on compile time.

Task :app:compileDebugJavaWithJavac FAILED
GallerypickerBinding.java:22: error: package android.support.constraint does not exist
    private final android.support.constraint.ConstraintLayout mboundView0;

GallerypickerBinding is the generated class from data binding of the newly added library. When I checked this file, it uses androidx.databinding.ViewDataBinding from AndroidX, but in the same file, it still uses android.support.constraint.ConstraintLayout from support library.

I expect Android Jetifier to convert all support libraries including to AndroidX, but it seems like it fails to convert the ConstraintLayout generated from data binding to AndroidX.

您必须在java文件和xml文件中更改包名称。

com.android.support.constraint to androidx.constraintlayout

For Kotlin , replace this dependency:

implementation "androidx.appcompat:appcompat:1.0.0-beta01"

with these (not sure if the second one is even required, but it is quite essential):

implementation "androidx.appcompat:appcompat:1.0.2"
implementation "androidx.core:core-ktx:1.0.1"

And for that data-binding error... either clean the project - or try to add the old one com.android.support.constraint package into the dependencies once, to make it stop complaining (only for a test, it will get it's namespace rewritten). If this not helps, please add Gallerypicker.java and it's XML into the question, for further review.

@ Suraj Singh might be right about the resource - if so, his answer should be the accepted one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM