简体   繁体   English

Android Jetifier无法将数据绑定生成的支持库转换为AndroidX

[英]Android Jetifier fails to convert data binding generated support library to AndroidX

I have an Android project that has been migrated to AndroidX. 我有一个已迁移到AndroidX的Android项目。 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. 我在gradle.properties中启用了Android Jetifier。 I am using Android Gradle build tool v.3.3.2 and Gradle v.4.10.1. 我使用的是Android Gradle构建工具v.3.3.2和Gradle v.4.10.1。

Here is my gradle.properties: 这是我的gradle.properties:

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

Here is my build.gradle: 这是我的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. GallerypickerBinding是从新添加的库的数据绑定生成的类。 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. 当我检查这个文件时,它使用androidx.databinding.ViewDataBinding的androidx.databinding.ViewDataBinding,但是在同一个文件中,它仍然使用来自支持库的android.support.constraint.ConstraintLayout

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. 我希望Android Jetifier能够转换所有支持库,包括AndroidX,但似乎无法将数据绑定生成的ConstraintLayout转换为AndroidX。

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

com.android.support.constraint to androidx.constraintlayout

For Kotlin , replace this dependency: 对于Kotlin ,替换此依赖项:

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). 并且对于那个数据绑定错误......要么清理项目 - 要么尝试将旧的com.android.support.constraint包添加到依赖项中一次,以使其停止抱怨(仅用于测试,它将获得它命名空间重写)。 If this not helps, please add Gallerypicker.java and it's XML into the question, for further review. 如果这没有帮助,请将Gallerypicker.java及其XML添加到问题中,以供进一步审核。

@ Suraj Singh might be right about the resource - if so, his answer should be the accepted one. @ Suraj Singh对资源的看法可能是正确的 - 如果是这样,他的回答应该是被接受的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 反向Jetifier用于带有支持库的项目中对AndroidX的依赖 - Reverse Jetifier for dependency with AndroidX in project with Support Library AndroidX Jetifier 无法/未能转换仍然使用支持库的 3rd-party 传递依赖项 - AndroidX Jetifier unable/failed to transform 3rd-party transitive dependency that still use Support Library Jetifier不会转换支持依赖项 - Jetifier does not convert support dependencies Android Studio 更新到 3.3.1 后,库的 AndroidX 转换失败,这是 Jetifier 错误吗? - AndroidX conversion failure for library after Android Studio update to 3.3.1, is this a Jetifier bug? 当库使用android组件并且应用使用androidx组件时,Jetifier无法正常工作 - Jetifier not working when library uses android component and app uses androidx component Android数据绑定依赖项与支持库冲突 - Android data binding dependency conflict with the support library 使用Jetifier工具的AndroidX迁移将支持库转换为RC版本 - AndroidX migration using Jetifier tool converts support libraries to RC versions 库应该依赖于androidx还是android.support - Should library depend on androidx or android.support 库应该使用androidx还是android.support? - Should library be using androidx or android.support? 在哪里可以看到Android数据绑定库生成的代码? - Where can I see the code generated by Android Data Binding Library?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM