关于Java:错误:找不到符号类DataBindingComponent

error: cannot find symbol class DataBindingComponent

我下载了一个Android项目,但出现此错误:

1
Error:(42, 42) error: cannot find symbol class DataBindingComponent

样品导入:

1
2
3
import android.databinding.DataBindingComponent; // no code-time error
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;

样品用法:

1
2
3
4
5
6
7
8
9
10
11
public FragmentFantasyPointsSingleBinding(DataBindingComponent bindingComponent, View root) {
        super(bindingComponent, root, 0);
        Object[] bindings = ViewDataBinding.mapBindings(bindingComponent, root, 4, sIncludes, sViewsWithIds);
        this.animationView = (LottieAnimationView) bindings[3];
        this.mboundView0 = (FrameLayout) bindings[0];
        this.mboundView0.setTag(null);
        this.progressView = (LinearLayout) bindings[2];
        this.recyclerView = (RecyclerView) bindings[1];
        setRootTag(root);
        invalidateAll();
    }

在代码时没有错误,但是在编译时却遇到了我提到的错误。

当我尝试在Android Studio上进行定义时,我做不到。

应用程序级别build.gradle:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId"com.esports.flank"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName"1.0"
        testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile 'com.android.support:support-annotations:26.1.0'
    compile"com.android.support:appcompat-v7:26.1.0"
    compile"com.android.support:recyclerview-v7:26.1.0"
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    compile('com.twitter.sdk.android:twitter:3.3.0@aar') {
        transitive = true
    }
    compile 'com.microsoft.azure:azure-mobile-android:3.4.0@aar'
    implementation 'com.airbnb.android:lottie:2.5.5'
    compile 'com.github.ybq:Android-SpinKit:1.1.0'
    compile 'uk.co.chrisjenx:calligraphy:2.3.0'
    compile 'com.romandanylyk:pageindicatorview:1.0.1@aar'
    api 'com.google.guava:guava:26.0-android'
    compile 'com.android.support:design:26.1.0'
    implementation 'com.wajahatkarim3.EasyFlipView:EasyFlipView:2.1.0'
}

我尝试了清洁和重建项目,还没有运气。

感谢帮助。


这个答案在类似的情况下对我有帮助:https://stackoverflow.com/a/52550118/8655667

  • 添加行
    android.enableExperimentalFeatureDatabinding=trueandroid.databinding.enableV2=falsegradle.properties
  • 同步项目
  • 构建->清洁项目
  • 生成->重建项目
  • 重建后,它应该为您提供实际的编译失败原因。


    就我而言,问题的原因是我将ViewModel从其原始包"目录"移到了我创建的用于清理项目的新包中。我也有其他一些错误。

    我反复单击"制作项目"以查找导入问题,直到将其全部清除为止,但是在使用Windows GREP找到的相关XML文件中找不到其余错误。

    我打开了关联的XML文件,发现该变量仍在引用原始路径(请注意,未显示" <"和">",因为我不知道如何对其进行转义):

    变量名称=" viewModel"类型=" original.project.path.name"

    我将其更改为:

    变量名称=" viewModel"类型=" new.project.path.name"

    这解决了我这个问题的版本。