7

迁移到 AndroidX(重构 > 迁移到 AndroidX)后,我遇到了很多数据绑定错误。

error: cannot find symbol
      @Nullable ViewGroup root, boolean attachToRoot, @Nullable DataBindingComponent component) {
                                                                ^
  symbol:   class DataBindingComponent
  location: class ActivityInfoBinding   

我正在使用 Android Studio 3.2 Beta 2

我的依赖:

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.cardview:cardview:1.0.0-beta01'
    implementation 'com.google.android.material:material:1.0.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha1'
    implementation "com.squareup.retrofit2:retrofit:$versions.retrofit"
    implementation "com.squareup.retrofit2:converter-gson:$versions.retrofit"
    implementation 'androidx.room:room-runtime:2.0.0-beta01'
    kapt 'androidx.room:room-compiler:2.0.0-beta01'
    implementation "androidx.core:core-ktx:$versions.ktx"
    implementation 'androidx.lifecycle:lifecycle-runtime:2.0.0-beta01'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-beta01'
    kapt 'androidx.lifecycle:lifecycle-compiler:2.0.0-beta01'
    implementation "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter:$versions.binding_collection_adapter"
    implementation "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter-recyclerview:$versions.binding_collection_adapter"
    implementation "com.jakewharton.threetenabp:threetenabp:$versions.threetenabp"
    implementation "com.google.dagger:dagger:$versions.dagger"
    kapt "com.google.dagger:dagger-compiler:$versions.dagger"
    kapt "com.google.dagger:dagger-android-processor:$versions.dagger"
    implementation "com.google.dagger:dagger-android-support:$versions.dagger"
    implementation "com.airbnb.android:lottie:$versions.lottie"
    implementation "com.github.bumptech.glide:glide:$versions.glide"
    implementation "com.jakewharton.timber:timber:$versions.timber"
    implementation "com.crashlytics.sdk.android:crashlytics:$versions.crashlytics"
    implementation "com.google.firebase:firebase-core:$versions.firebase_core"

    testImplementation "junit:junit:$versions.junit"
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
} 
4

2 回答 2

1

更新到最新的 Android Studio 并重新导入项目解决了我的问题。

于 2018-08-02T09:50:36.227 回答
0

为了解决这个问题,我必须更新布局文件上的所有类名。

从:

<android.support.design.widget.CoordinatorLayout
<android.support.v7.widget.RecyclerView
...

至:

<androidx.core.widget.NestedScrollView
<androidx.coordinatorlayout.widget.CoordinatorLayout
...

之后,数据绑定错误就消失了。

我运行了迁移工具,但它没有修复布局 xml 上的类名,可悲!

于 2018-09-26T01:54:03.440 回答