【问题标题】:Gradle couldn't find com.android.databinding:dataBinder:1.0-rc0Gradle 找不到 com.android.databinding:dataBinder:1.0-rc0
【发布时间】:2015-08-20 22:48:42
【问题描述】:

这是一个与今天无关的老问题。请参阅 Android 开发人员的说明。与四年前相比,现在将数据绑定应用于您的项目要容易得多。

我正在阅读来自https://developer.android.com/tools/data-binding/guide.html 的 Android 数据绑定指南。我已确定我运行的是 Android Studio 1.3(金丝雀版)。

按照指南,我收到此错误:

Gradle sync failed: could not find com.android.databinding:library:1.0-rc0

其他人有同样的问题吗?感谢您的帮助。

应用构建.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0-beta1'
        classpath "com.android.databinding:dataBinder:1.0-rc0"
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

模块构建.graddle

apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'

apply plugin: 'android-apt'
def AAVersion = '3.3'
def MyProject = 'com.commonsware.android.frw.filesdemo'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

repositories {
    mavenCentral()
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName "$MyProject"
    }
}

android {
    compileSdkVersion 22
    buildToolsVersion "22"

    defaultConfig {
        applicationId "$MyProject"
        minSdkVersion 17
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions{
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
    }

    dexOptions {
        preDexLibraries = false
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'

    compile "com.squareup:otto:1.3.6"
    compile "commons-io:commons-io:+"
    compile 'com.fasterxml.jackson.jr:jackson-jr-all:2.5.0'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'

    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}

【问题讨论】:

  • 你有没有想过这个问题?我所有的东西都在工作,现在不行了。我有 gradle build 1.3.0-beta4 和 com.android.databinding:library:1.0-rc0,buildt 工具版本为 23.0.0 rc3。
  • 我刚刚解决了我的问题。删除 android-apt 插件导致一切都解决了。花了两天时间研究这个。希望这可以节省一些时间。
  • 我在这里尝试了所有方法,还有什么问题??

标签: android gradle data-binding android-databinding


【解决方案1】:

请尝试将类路径更改为“com.android.tools.build:gradle:1.3.0-beta2”并将 buildToolsVersion 设置为“23 rc2”。

在此之前不要忘记通过 SDK 管理器更新 SDK 包。

您可以在此处找到有关 Android Preview SDK 的更多信息:Set Up the Preview SDK

【讨论】:

  • 弗拉基米尔,非常感谢您的帮助。我只升级了 Android Studio 版本并忽略了 SDK。升级一段时间后,错误消失并遵循您在我的配置文件中指出的更改。
  • 对我不起作用。它似乎在 SDK 中寻找这个包。我在我的 SDK 中更新了 Android 和 Google 存储库。
  • 确实有效,但有不同的问题。我在 SSL 证书后面工作,所以我还需要使用 http jcenter repo 设置 allprojects 范围。
  • 确保 SDK 管理器中的构建工具也是最新的。当我使用其他依赖注入时,我发现我的应用程序无法生成以 Binding 作为后缀的分类。我必须修改 gradle 声明才能使其正常工作,并希望可以帮助其他尝试使用 Dagger 或 AndroidAnnotations 运行它的人。 github.com/juanmendez/jm_android_dev/tree/master/…
  • @YoelGluschnaider,好的,我想在它开始工作之前确认我缺少的是我需要安装还是更新。 Android SDK 平台工具(修订版 23 rc2),以及 Android SDK 构建工具。
【解决方案2】:

添加类路径后同步您的项目

【讨论】:

    【解决方案3】:

    确保您拥有 Android Studio 1.3 或更高版本

    您的项目 build.gradle 应该如下所示:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.3.0-beta1'
            classpath "com.android.databinding:dataBinder:1.0-rc0"
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    

    你的模块 build.gradle 应该是这样的:

    apply plugin: 'com.android.application'
    apply plugin: 'com.android.databinding'
    
    android {
    
        compileSdkVersion 22
        buildToolsVersion "22.0.1"
    
        defaultConfig {
            applicationId "com.my.appId"
            minSdkVersion 15
            targetSdkVersion 22
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    
    }
    

    我在定位 M Preview 时遇到了问题,所以没有任何效果。一旦我将构建工具更改为 22.0.1,将 targetSdkVersion 更改为 22,一切正常。

    【讨论】:

      【解决方案4】:

      我有一个相同的问题,并通过删除 android-apt 插件解决了它。不知道那里有什么冲突,但有些冲突。

      【讨论】:

      • 是的,我也遇到了同样的问题,这个答案让我将我的 android-apt 更新到 1.6 版,这解决了我的构建中的问题。
      【解决方案5】:

      同步 build.gradle 文件时出现错误。

      错误:无法解决:com.android.databinding:library:1.0-rc0

      错误:无法解决:com.android.databinding:adapters:1.0-rc0

      我终于找到了解决办法。

      dependencies {
      
          // instead of the below pathes...
          //classpath "com.android.tools.build:gradle:1.3.0-beta2"
          //classpath "com.android.databinding:dataBinder:1.0-rc0"
      
          // I used the following classpathes.... It works!
          classpath "com.android.tools.build:gradle:1.3.+"
          classpath "com.android.databinding:dataBinder:1.+"
      
      }
      

      【讨论】:

      【解决方案6】:

      通过查看您的错误Gradle couldn't find com.android.databinding:dataBinder:1.0-rc0,您应该尝试这个,

      classpath "com.android.databinding:dataBinder:1.0-rc1"
      

      要使用DataBinding,请遵循所有这些步骤。

      1. 将您的Android Studio 更新为Android Studio 1.3 版本。
      2. 要将application 设置为使用data binding,请将data binding 添加到top-level build.gradle 文件的类路径中, 就在“android”的正下方。

        dependencies {
           classpath "com.android.tools.build:gradle:1.3"
           classpath "com.android.databinding:dataBinder:1.0-rc1"
        }
        
      3. 然后确保 jcenter 在您项目的存储库列表中 在顶级 build.gradle 文件中。

        allprojects {
           repositories {
               jcenter()
           }
        }
        
      4. 在每个要使用数据绑定的模块中,正确应用插件 在android插件之后。

        apply plugin: 'com.android.application'
        apply plugin: 'com.android.databinding'
        
      5. Cleanbuild 您的应用。

      完整代码

      top-levelbuild.gradle 文件,

      // Top-level build file where you can add configuration options common to all sub-projects/modules.
      
      buildscript {
          repositories {
              jcenter()
          }
          dependencies {
              classpath 'com.android.tools.build:gradle:1.3'
              classpath "com.android.databinding:dataBinder:1.0-rc1"
      
              // NOTE: Do not place your application dependencies here; they belong
              // in the individual module build.gradle files
          }
      }
      
      allprojects {
          repositories {
              jcenter()
          }
      }
      

      module-levelbuild.gradle 文件,

      apply plugin: 'com.android.application'
      apply plugin: 'com.android.databinding'
      
      android {
          compileSdkVersion 22
          buildToolsVersion "22.0.1"
      
          defaultConfig {
              applicationId "com.example.packagename"
              minSdkVersion 15
              targetSdkVersion 22
              versionCode 1
              versionName "1.0"
          }
          buildTypes {
              release {
                  minifyEnabled false
                  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
              }
          }
      }
      
      dependencies {
          compile fileTree(dir: 'libs', include: ['*.jar'])
          compile 'com.android.support:appcompat-v7:22.2.1'
      }
      

      更多详情Data Binding Guide

      完整演示Data Binding Android

      【讨论】:

        【解决方案7】:

        我遇到了同样的问题,并通过将 android sdk 工具更新到 24.3.3 解决了它。

        【讨论】:

          【解决方案8】:

          我遇到了这个问题,并通过在我的顶级 build.gradle 中的 allprojects.repositories 下添加“jcenter”来解决它(我一直在使用 mavenCentral)。

          buildscript {
              repositories {
                  jcenter()
              }
              dependencies {
                  classpath 'com.android.tools.build:gradle:1.3.0'
                  classpath 'com.android.databinding:dataBinder:1.0-rc1'
              }
          }
          
          allprojects {
              repositories {
                  mavenCentral()
                  jcenter() // <=== *** Adding this fixed it ***
              }
          }
          

          【讨论】:

            【解决方案9】:

            你应该添加

            classpath 'com.android.tools.build:gradle:1.3.0'
            classpath "com.android.databinding:dataBinder:1.0-rc0"

            build.grade 在项目目录中。 然后同步 gradle

            【讨论】:

            • 是否还需要添加数据绑定类路径?
            【解决方案10】:

            正如文档所说

            要使用数据绑定,Android Plugin for Gradle 1.5.0-alpha1 或更高版本 是必需的。

            我在 build.gradle 项目中添加了以下行:

            // Top-level build file where you can add configuration options common to all sub-projects/modules.
            
            buildscript {
                repositories {
                    jcenter()
                }
                dependencies {
                    classpath "com.android.tools.build:gradle:1.5.0-beta2"
            
                    // NOTE: Do not place your application dependencies here; they belong
                    // in the individual module build.gradle files
                }
            }
            
            allprojects {
                repositories {
                    jcenter()
                }
            }
            
            task clean(type: Delete) {
                delete rootProject.buildDir
            }
            

            然后添加:

            dataBinding {
                    enabled = true
                }
            

            到你的 build.graddle 模块应用程序是这样的:

            apply plugin: 'com.android.application'
            
            android {
                compileSdkVersion 23
                buildToolsVersion "23.0.1"
            
                defaultConfig {
                    applicationId "gujarat.databinding"
                    minSdkVersion 16
                    targetSdkVersion 23
                    versionCode 1
                    versionName "1.0"
                }
                buildTypes {
                    release {
                        minifyEnabled false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    }
                }
            
                dataBinding {
                    enabled = true
                }
            }
            
            dependencies {
                compile fileTree(dir: 'libs', include: ['*.jar'])
                testCompile 'junit:junit:4.12'
                compile 'com.android.support:appcompat-v7:23.1.1'
                compile 'com.android.support:support-v4:23.1.1'
            }
            

            【讨论】:

              【解决方案11】:

              您应该更新您的 SDK,它将解决此问题。

              【讨论】:

              • 谢谢伙计,两年后,包含 DataBinding 变得容易得多,而且它已经优雅地发展了。好久没看,现在用了就爱上了。
              【解决方案12】:

              最新的 Android Studio 和最新的 Gradle 更新

              您现在不需要添加databinding:dataBinder 依赖项。只需在 android 标签中的应用级别 build.gradle 中启用 dataBinding。

              android
              {
              ...
                  dataBinding {
                      enabled = true
                  }
              ...
              }
              

              【讨论】:

              • 感谢 Khemraj,在 DataBinding 没有像今天这样集成到 Android 库的时代,这是一个老问题,仍然只有一个数据绑定方向。坦率地说,我离开 DataBinding 很久了,直到我发现它现在支持双重绑定。我可能最终会删除这个问题。它不再适用。
              • 你为什么离开数据绑定?我没有得到你。
              • 例如,您有一个模型,并将属性分配给 EditTextView text="@{model.name}"。这就是你所能做的,并且依赖于处理editTextView中的事件变化。现在您可以双重绑定,这意味着此 text="@={model.name}" 这意味着 editTextView 可以自行更新名称,而无需您手动添加侦听器和更新名称。
              • 这样好吗?它被称为双向绑定。你觉得这有什么问题?
              • 我没有发现任何问题,完全相反。在它是单向数据绑定之前。就是这样
              猜你喜欢
              • 2017-07-18
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2021-01-28
              • 2018-08-16
              • 1970-01-01
              • 2015-11-06
              • 2015-11-24
              相关资源
              最近更新 更多