将 google-play-services 添加到 android 依赖项
Adding google-play-services to android dependencies
我想在我的应用程序中有一个包含条码扫描器的 activity,为此我需要能够使用 BarcodeDetector。为了能够使用它,我需要实现 dependecy 'compile '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
}
有人可以帮我解决这个问题吗?
您所包含的库似乎引用了其他一些库的不同版本。这就是幕后的问题。
在您的示例中,您包含了整套播放服务。根据你所说的,看起来你可能只需要 "vision" 包。请尝试以下配置:
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'
这些是变化:
- 通过提供特定版本号(今天最后一个可用的稳定版本)删除了某些库中的“+”符号
- 我没有使用整个捆绑版本的 Play Services,而是只添加了 play-services-vision,这应该足够了。如果您还需要其他包,您可以找到完整列表 here
编辑:
您还需要在项目的 gradle 中添加 google()
才能访问最新的库,如下所示:
allprojects {
repositories {
google()
jcenter()
}
}
我想在我的应用程序中有一个包含条码扫描器的 activity,为此我需要能够使用 BarcodeDetector。为了能够使用它,我需要实现 dependecy 'compile '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
}
有人可以帮我解决这个问题吗?
您所包含的库似乎引用了其他一些库的不同版本。这就是幕后的问题。
在您的示例中,您包含了整套播放服务。根据你所说的,看起来你可能只需要 "vision" 包。请尝试以下配置:
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'
这些是变化:
- 通过提供特定版本号(今天最后一个可用的稳定版本)删除了某些库中的“+”符号
- 我没有使用整个捆绑版本的 Play Services,而是只添加了 play-services-vision,这应该足够了。如果您还需要其他包,您可以找到完整列表 here
编辑:
您还需要在项目的 gradle 中添加 google()
才能访问最新的库,如下所示:
allprojects {
repositories {
google()
jcenter()
}
}