无法解析 com.google.android.gms:play-services-location:16.+
Posted
技术标签:
【中文标题】无法解析 com.google.android.gms:play-services-location:16.+【英文标题】:Could not resolve com.google.android.gms:play-services-location:16.+ 【发布时间】:2021-06-12 22:18:43 【问题描述】:伙计们,当我尝试在真实设备上运行我的应用程序但升级到 1.22.2 后发现错误:
尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。Required by: project :app > project :location > Failed to list versions for com.google.android.gms:play-services-location. > Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-location/maven-metadata.xml. > Could not get resource 'https://jcenter.bintray.com/com/google/android/gms/play-services-location/maven-metadata.xml'. > Could not GET 'https://jcenter.bintray.com/com/google/android/gms/play-services-location/maven-metadata.xml'. > Read timed out
我的 android\app\build.gradle:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists())
localPropertiesFile.withReader('UTF-8') reader ->
localProperties.load(reader)
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null)
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null)
flutterVersionCode = '1'
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null)
flutterVersionName = '1.0'
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists())
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android
compileSdkVersion 28
lintOptions
disable 'InvalidPackage'
defaultConfig
applicationId "io.bujupah.hestia"
minSdkVersion 17
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
signingConfigs
release
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
buildTypes
release
signingConfig signingConfigs.release
flutter
source '../..'
dependencies
implementation 'com.google.android.gms:play-services-auth:16.0.1'
testImplementation'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.17.0'
implementation 'com.android.support:multidex:1.0.3'
我的 android\build.gradle:
buildscript
repositories
google()
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:3.6.2'
allprojects
repositories
google()
jcenter()
rootProject.buildDir = '../build'
subprojects
project.buildDir = "$rootProject.buildDir/$project.name"
subprojects
project.evaluationDependsOn(':app')
task clean(type: Delete)
delete rootProject.buildDir
当我运行 flutter --version:
Flutter 1.22.4 • 通道稳定 • https://github.com/flutter/flutter.git 框架 • 修订版 1aafb3a8b9 (4 个月前)• 2020-11-13 09:59:28 -0800 引擎• 修订 2c956a31c0 工具• Dart 2.10.4
我的位置插件:
# flutter_map_marker_cluster: any
flutter_polyline_points: ^0.2.4
geolocator: ^6.1.1
geocoding: ^1.0.5
location: ^3.0.2
【问题讨论】:
您的问题解决了吗? 【参考方案1】:解决办法是更新
dependencies
com.android.tools.build:gradle:3.6.2
到
dependencies
classpath 'com.android.tools.build:gradle:4.1.0'
然后将distributionUrl更新为
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
【讨论】:
我可以确认这个答案也适用于我在 Flutter 的 Android 版本中的情况。谢谢,伙计! yeahhh...我的旧颤振项目再次上线,谢谢【参考方案2】:以下更改对我有用
//Project level build.gradle
buildscript
ext.kotlin_version = '1.3.50'
repositories
google()
mavenCentral()
dependencies
classpath 'com.android.tools.build:gradle:4.+'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
//App level build.gradle
configurations.all
resolutionStrategy
force 'com.google.android.gms:play-services-location:16.0.0'
dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.android.gms:play-services-location:16.0.0'//add this line
【讨论】:
按照上述步骤+这个:distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
这个解决方案对我有用
我认为这是最好的解决方案,因为它确保您将 Gradle 升级到最新版本而不是降级【参考方案3】:
用mavenCentral()
替换Jcenter()
对我有用。
repositories
google()
mavenCentral() // Add this
jcenter() // remove this
【讨论】:
为什么blog.gradle.org/jcenter-shutdown的一些背景信息 不能解决我的问题【参考方案4】:网站因维护而停机,寻找 jcenter() 替代方案或等到他们解决问题。
【讨论】:
【参考方案5】:对于那些没有用 AzizDev 的解决方案解决问题的人,试试这个解决方案:
也许你的一些依赖已经过时了。所以,在终端运行这个命令来升级它们,然后运行项目
flutter pub upgrade --major-versions
【讨论】:
这应该是公认的答案,因为它会自动解决问题,而不是通过手动更改 gradle 依赖项。已经在两个不同的项目中为我工作过。【参考方案6】:转到您的 .pub-cache/hosted/pub.dartlang.org/ 转到您的插件,然后转到 android 文件夹/ 更改您的 com.google.android.gms:play-services-location 的版本:16.+ 到特定版本。然后它会完美运行
注意:您的 .pub/cache 文件夹路径在 Windows 中应该不同,如果 .pub-cache 文件夹被隐藏,您还需要取消隐藏它
【讨论】:
【参考方案7】:只需检查您的 Flutter 项目中的 gradle 版本,如下所示:
/android/build.gradle:
dependencies
classpath 'com.android.tools.build:gradle:4.1.3'
...
/android/gradle/wrapper/gradle-wrapper.properties:
...
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
【讨论】:
以上是关于无法解析 com.google.android.gms:play-services-location:16.+的主要内容,如果未能解决你的问题,请参考以下文章
谷歌地图修订版。 30 日食用法:google_play_services_version