![](/img/trans.png)
[英]ERROR: Failed to resolve: com.google.android.gms:play-services-location:16.1.0
[英]Could not resolve com.google.android.gms:play-services-location:16.+
伙计们,当我尝试在真实设备上运行我的应用程序但升级到 1.22.2 后发现该错误:
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
- 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。 使用 --info 或 --debug 选项运行以获得更多日志 output。 运行 --scan 以获得完整的见解。
我的 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 • channel stable • https://github.com/flutter/flutter.git Framework • revision 1aafb3a8b9 (4 months ago) • 2020-11-13 09:59:28 -0800 Engine • revision 2c956a31c0 Tools • 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
解决方案是更新
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
该网站因维护而停机,寻找 jcenter() 替代方案或等到他们解决问题。
用Jcenter()
替换 Jcenter() 对我mavenCentral()
。
repositories {
google()
mavenCentral() // Add this
jcenter() // remove this
}
对于那些还没有用 AzizDev 的解决方案解决问题的人,试试这个解决方案:
也许您的某些依赖项已过时..因此,在终端中运行此命令以升级它们,然后运行项目
flutter pub upgrade --major-versions
我尝试了所有解决方案,但对我没有任何效果。 解决此问题的唯一方法是关闭 WIFI 并运行项目。
以下更改对我有用
//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
}
只需检查 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
我也有同样的问题。 请帮我解决它。 我已经尝试使用上述所有方法,但它没有
有同样的问题。 我尝试了开发人员说的许多解决方案。 但是,还是有问题。 现在,我删除了位置:^3.0.2。 现在工作正常。
Go to your.pub-cache/hosted/pub.dartlang.org/ go to your plugin and then go to android folder/ change version of your com.google.android.gms:play-services-location:16.+ to specific版本。 然后它将完美运行
注意:windows 中的 Your.pub/cache 文件夹路径应该不同,如果隐藏,您还需要取消隐藏.pub-cache 文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.