我希望在我的应用程序中有一个包含条形码扫描器的活动,为此我需要能够使用BarcodeDetector。为了能够使用它,我需要实现依赖性的‘编译'com.google.android.gms:play-services:11.0.2'',’,但是当我这样做时,我会得到以下错误消息:

我不知道如何解决这个错误,我的“build.gradle (Module: app)”如下所示:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.myname.myproject"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:26.+'
compile 'com.android.support:cardview-v7:26.+'
compile 'com.google.android.gms:play-services:11.0.2'
testCompile 'junit:junit:4.12'
}我的“build.gradle (Project: MyProject)”看起来是这样的:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// 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
}有人能帮我吗?
发布于 2018-01-18 16:12:31
看起来,您所包含的库引用了其他库的不同版本。这就是幕后的问题。
在您的示例中,您将包含整个play服务包。根据你所说的,看起来你可能只需要一个“愿景”包。请尝试使用以下配置:
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.google.android.gms:play-services-vision:11.8.0'这些变化如下:
编辑:您还需要在项目的gradle中添加google()才能访问最新的库,如下所示:
allprojects {
repositories {
google()
jcenter()
}
}https://stackoverflow.com/questions/48325020
复制相似问题