错误:找不到符号类DataBindingComponent。

6

我下载了一个安卓项目,但是出现了以下错误:

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

示例导入:

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

使用示例:

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:

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://dev59.com/sek5XIcBkEYKwwoY7eME - IntelliJ Amiya
@IntelliJAmiya 尝试了那些解决方案,但是 'kapt' 这个动词对我来说会抛出一个错误。 - Talha Talip Açıkgöz
使用annotationProcessor - IntelliJ Amiya
https://dev59.com/dlUL5IYBdhLWcg3w-cPr#49649349 - IntelliJ Amiya
你一直在遇到同样的错误,仍在努力解决它。 - Nauman Ash
显示剩余3条评论
2个回答

16

这个回答帮助了我解决类似的问题:https://dev59.com/dlUL5IYBdhLWcg3w-cPr#52550118

  1. gradle.properties 中添加以下内容:android.enableExperimentalFeatureDatabinding=trueandroid.databinding.enableV2=false
  2. 同步项目
  3. 选择菜单 Build -> Clean Project
  4. 选择菜单 Build -> Rebuild Project

重新构建后,应该可以看到实际的编译失败原因。


工作正如你所描述的那样。结果发现,Room中的@insert dao方法没有参数(甚至没有被调用)是问题的原因。 - Eugenio Lopez

0
在我的情况下,问题的原因是我将一个 ViewModel 从它原来的 "目录" 包移动到一个新创建的目录中,以清理我的项目。我还有一些其他的错误。
我多次点击了 "Make Project" 来定位导入问题,直到它们全部清理干净,但这并没有找到相关 XML 文件中剩余的错误,我是使用 Windows GREP 找到的。
我打开相关的 XML 文件,并发现该变量仍然引用原始路径(请注意,"<" 和 ">" 没有显示,因为我不知道如何转义它们):
variable name="viewModel" type="original.project.path.name"
我将其更改为:
variable name="viewModel" type="new.project.path.name"
这解决了我的这个问题的版本。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接