How To Fix In Android The Error "Could Not Find Com.android.tools.build:gradle:3.4.1"?
I have updated the version of Android Studio at the 3.4.1.
Immediately the version of Android Gradle Plugin Version and Gradle Version weren't the last so I have changed with 3.4.1 and 5.1.1 (File > Project structure > Project).
Now, I'm trying to create an apk but I have the error "Could not find com.android.tools.build:gradle:3.4.1".
The project is created with cordova and first I have updated cordova at the version 9.0.0.
I also have noticed that I don't have Build > Generated Signed Apk but only Build > Build Bundle.
After a long search, I have tried to:
1. change task wrapper with
wrapper {gradleVersion = '2.14.1'}
add google() in
repositories { mavenCentral() jcenter() google() }
Verify that the link "distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip" is correct
Verify that there is the function mavenCentral()
In File > Settings > Build, Execution... > Build Tools > Gradle "Use default gradle wrapper" is checked and "Offline work" not checked
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
What can I do to fix the problem? And what can I do to have the function Generated Signed Apk?
Answer
You have to add the google()
maven repo in the buildscript
block
buildscript {
repositories {
google() // <-- add this
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
It is not related to your issue but for the other dependencies you should add the same repo also in the allprojects
block
allprojects {
repositories {
google()// <-- add this.
jcenter()
}
}
Pay attention to wrapper
task with gradle 5.x.
Defining a custom wrapper
or init
task is deprecated with gradle 4.8 and removed in gradle 5.x. Attempting to replace a built-in task will produce an error similar to the following:
Cannot add task 'wrapper' as a task with that name already exists.
To avoid this issue, instead of this:
task wrapper(type:Wrapper) {
//configuration
}
Do this:
wrapper {
//configuration
}
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View