我正在尝试升级Google Play服务库,以便可以使用最新的Android Gradle(3.2)和Android SDK版本(28)。问题是我所有的GMS导入都无法解决。
示例:
import com.google.android.gms.common.api.GoogleApiClient;
和
import com.google.android.gms.games.Games;
我已经研究了各种问题,这些问题在导入这些库时有问题,但没有一个是最新的,或者似乎无法解决我的问题。我试图使缓存/重新启动,清理/重建项目无效。当前,我正在导入一个google-play-services_lib
库,该库具有捆绑的GMS作为依赖项:com.google.android.gms:play-services:12.0.1
我的项目build.gradle:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://jitpack.io' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
}
apply plugin: 'com.android.application'
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
compileSdkVersion 28
defaultConfig {
applicationId "com.example.exampleapp"
minSdkVersion 14
targetSdkVersion 28
versionCode 34 // increment with every release
versionName '3.0.5' // change with every release
setProperty("archivesBaseName", "example_$versionName")
}
signingConfigs {
release {
keyAlias = "example key alias"
}
}
buildTypes {
release {
minifyEnabled true
}
}
}
dependencies {
implementation project(':google-play-services_lib')
implementation project(':appcompat_v7')
}
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
我的模块/应用程序build.gradle:
buildscript {
repositories {
google()
jCenter()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v4:22.0.0'
compile 'com.google.android.gms:play-services:12.0.1'
}
android {
compileSdkVersion 28
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
希望有一种方法可以解决这些导入错误,这似乎与支持库的构建和实际项目本身之间没有联系...
答案 0 :(得分:0)
找到了。对于从原路返回的迁移(例如目标API <= 21),摆脱使用捆绑软件/手册库,而坚持使用较新的Gradle版本:
从Android Manifest中删除指定Google Play服务版本(捆绑版本)的meta标签
删除您的google-play-services_lib
将必需的GMS依赖项添加到项目级build.gradle
,无论是手动还是在文件→项目结构→MyApp模块→依赖项选项卡中,即使没有在新的目录中显示,也要添加库。 Android Studio的库搜索。
示例: implementation 'com.google.android.gms:play-services-base:16.0.1'
我知道这很明显,但这对于将使用GMS的较旧的Android应用程序迁移到较新的版本来说可能是一个不错的帖子。至少可以让您选择要使用的GMS模块,而不是笨重的捆绑包。