如何修复 android 中的错误 "Could not find com.android.tools.build:gradle:3.4.1"?
How to fix in android the error "Could not find com.android.tools.build:gradle:3.4.1"?
我已经在 3.4.1 更新了 Android Studio 的版本。
Android Gradle Plugin Version 和 Gradle Version 的版本不是最后一个,所以我已更改 3.4.1 和 5.1.1(文件 > 项目结构 > 项目)。
现在,我正在尝试创建一个 apk,但出现错误 "Could not find com.android.tools.build:gradle:3.4.1".
该项目是使用 cordova 创建的,首先我在 9.0.0.
版本更新了 cordova
我还注意到我没有 Build > Generated Signed Apk 但只有 Build > Build Bundle.
经过长时间的搜索,我尝试过:
1. 用
更改任务包装器
wrapper {gradleVersion = '2.14.1'}
在
中添加google()
存储库{
mavenCentral()
中心()
google()
}
验证 link "distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip" 是否正确
验证有函数mavenCentral()
在 File > Settings > Build, Execution... > Build Tools > Gradle "Use default gradle wrapper" 中选中 "Offline work" 未勾选
build.gradle
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
jcenter()
}
// Switch the Android Gradle plugin version requirement depending on the
// installed version of Gradle. This dependency is documented at
// http://tools.android.com/tech-docs/new-build-system/version-compatibility
// and https://issues.apache.org/jira/browse/CB-8143
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
// Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
repositories {
mavenCentral();
jcenter()
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.14.1'
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-
5.1.1-all.zip
我该怎么做才能解决这个问题?我该怎么做才能拥有 Generated Signed Apk 功能?
您必须在 buildscript
块中添加 google()
maven 存储库
buildscript {
repositories {
google() // <-- add this
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
它与您的问题无关,但对于其他依赖项,您也应该在 allprojects
块中添加相同的 repo
allprojects {
repositories {
google()// <-- add this.
jcenter()
}
}
关注wrapper
任务with gradle 5.x。
定义自定义 wrapper
或 init
任务已在 gradle 4.8 中弃用,并在 gradle 5.x 中删除。尝试替换 built-in 任务将产生类似于以下内容的错误:
Cannot add task 'wrapper' as a task with that name already exists.
为避免此问题,请改为:
task wrapper(type:Wrapper) {
//configuration
}
这样做:
wrapper {
//configuration
}
我已经在 3.4.1 更新了 Android Studio 的版本。
Android Gradle Plugin Version 和 Gradle Version 的版本不是最后一个,所以我已更改 3.4.1 和 5.1.1(文件 > 项目结构 > 项目)。
现在,我正在尝试创建一个 apk,但出现错误 "Could not find com.android.tools.build:gradle:3.4.1".
该项目是使用 cordova 创建的,首先我在 9.0.0.
版本更新了 cordova
我还注意到我没有 Build > Generated Signed Apk 但只有 Build > Build Bundle.
经过长时间的搜索,我尝试过:
1. 用
wrapper {gradleVersion = '2.14.1'}
在
中添加google()存储库{ mavenCentral() 中心() google() }
验证 link "distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip" 是否正确
验证有函数mavenCentral()
在 File > Settings > Build, Execution... > Build Tools > Gradle "Use default gradle wrapper" 中选中 "Offline work" 未勾选
build.gradle
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
jcenter()
}
// Switch the Android Gradle plugin version requirement depending on the
// installed version of Gradle. This dependency is documented at
// http://tools.android.com/tech-docs/new-build-system/version-compatibility
// and https://issues.apache.org/jira/browse/CB-8143
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
// Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
repositories {
mavenCentral();
jcenter()
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.14.1'
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-
5.1.1-all.zip
您必须在 buildscript
块中添加 google()
maven 存储库
buildscript {
repositories {
google() // <-- add this
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
它与您的问题无关,但对于其他依赖项,您也应该在 allprojects
块中添加相同的 repo
allprojects {
repositories {
google()// <-- add this.
jcenter()
}
}
关注wrapper
任务with gradle 5.x。
定义自定义 wrapper
或 init
任务已在 gradle 4.8 中弃用,并在 gradle 5.x 中删除。尝试替换 built-in 任务将产生类似于以下内容的错误:
Cannot add task 'wrapper' as a task with that name already exists.
为避免此问题,请改为:
task wrapper(type:Wrapper) {
//configuration
}
这样做:
wrapper {
//configuration
}