我正在尝试在现有项目中使用DataBinding。根据文档,我在app module的build.gradle中添加了以下行,并编译了项目。
dataBinding {
enabled = true
}
我收到以下错误:
Could not resolve all dependencies for configuration ':app:devDebugCompileClasspath'.
找不到com.android.databinding:baseLibrary:3.0.0-alpha3。 在以下位置搜索: 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/google/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/google/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/android/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/android/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar https://jcenter.bintray.com/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom https://jcenter.bintray.com/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar https://jitpack.io/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom https://jitpack.io/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar https://maven.fabric.io/public/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom https://maven.fabric.io/public/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar 要求: 项目:app 找不到com.android.databinding:baseLibrary:3.0.0-alpha3。 在以下位置搜索: 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/google/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/google/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/android/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom 文件:/ C:/Users/incnayak/AppData/Local/Android/sdk/extras/android/m2repository/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar https://jcenter.bintray.com/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom https://jcenter.bintray.com/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar https://jitpack.io/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom https://jitpack.io/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar https://maven.fabric.io/public/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.pom https://maven.fabric.io/public/com/android/databinding/baseLibrary/3.0.0-alpha3/baseLibrary-3.0.0-alpha3.jar 要求: 项目:app> com.android.databinding:库:1.3.1 项目:app> com.android.databinding:适配器:1.3.1
有人可以帮我解决这个问题吗?我正在使用Android Studio 3.0 Canary 3。
我的项目级别gradle
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4'
classpath 'com.google.firebase:firebase-plugins:1.1.0'
classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
}
App level gradle
buildscript {
dependencies {
//noinspection GradleDynamicVersion
classpath 'io.fabric.tools:gradle:1.+'
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'io.fabric'
apply from: "../constants.gradle"
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion project.ext.compileSdk
buildToolsVersion "${project.ext.buildtools}"
signingConfigs {
config {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
// Data Binding Library
dataBinding {
enabled = true
}
defaultConfig {
applicationId "com.chanse.cee2048"
minSdkVersion project.ext.minSdk
targetSdkVersion project.ext.targetSdk
versionCode versionCodeNo
versionName versionNameMajor + "." + versionNameMinor + "." + versionNamePatch + "." + versionNameBuild
vectorDrawables.useSupportLibrary = true
versionNameSuffix ' (Beta)'
signingConfig signingConfigs.config
}
buildTypes {
release {
// debuggable true
// shrinkResources true
signingConfig signingConfigs.config
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.config
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
flavorDimensions "chanse"
productFlavors {
dev {
applicationIdSuffix '.debug'
minSdkVersion project.ext.minSdkDebug
// Build only for english and xxhdpi density
resConfigs ("en", "xxhdpi")
// Have a different application name for dev version
resValue "string", "app_name", "Chanse Games Dev"
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion project.ext.minSdk
// Have a different application name for dev version
resValue "string", "app_name", "Chanse Games"
}
}
return void
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.android.support:appcompat-v7:${project.ext.support_library_version}"
compile "com.android.support:cardview-v7:${project.ext.support_library_version}"
compile "com.android.support:recyclerview-v7:${project.ext.support_library_version}"
compile "com.android.support:design:${project.ext.support_library_version}"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.databinding:library:1.3.1'
implementation 'com.android.databinding:adapters:1.3.1'
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1.2-4'
apply plugin: 'com.google.gms.google-services'
}
答案 0 :(得分:8)
将这些行添加到模块级build.gradle作为依赖项; Android Studio 3.0改变了它之前通过SDK管理器下载的库的方式 - https://developer.android.com/studio/build/dependencies.html#google-maven
implementation 'com.android.databinding:library:1.3.1'
implementation 'com.android.databinding:adapters:1.3.1'
您可能不需要第二行,具体取决于您使用数据绑定的方式。
您也可以使用旧版implementation
代替compile
。使用implementation
将避免构建警告;它是Android Gradle插件默认使用的新Gradle Java库插件的一部分。
如果您还没有,还需要添加类似以下内容(通常在您的模块级build.gradle
中) - 这会添加Google针对Android依赖项的新Maven存储库:
repositories {
maven {
url 'https://maven.google.com'
}
}