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'}
  1. add google() in

    repositories { mavenCentral() jcenter() google() }

  2. Verify that the link "distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip" is correct

  3. Verify that there is the function mavenCentral()

  4. 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

enter image description here

enter image description here What can I do to fix the problem? And what can I do to have the function Generated Signed Apk?

Gustavo Pagani
  • 6,583
  • 5
  • 40
  • 71
Giu
  • 295
  • 1
  • 5
  • 22

1 Answers1

1

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
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Thank you for the answer. Ok, I have added the function google() in buildscript and allprojects but now the error is "Cannot add task 'wrapper' as a task with that name already exists.". – Giu Jun 25 '19 at 09:14
  • @Giu It is a different issue. It is related to gradle 5.x. Check this answer: https://stackoverflow.com/questions/53521437/how-to-declare-gradle-version-5-0-in-build-gradle. – Gabriele Mariotti Jun 25 '19 at 09:31
  • I have modify the code but first I had a problem with "<<" near "task cdvPrintProps" so I have canceled. And now I have a new error: "ERROR: Unable to resolve dependency for ':@debug/compileClasspath': Could not resolve project :CordovaLib." – Giu Jun 25 '19 at 10:03
  • @GiuThis is some separate problem. It has nothing to do with your question. You may wish to consider asking a separate question – Gabriele Mariotti Jun 25 '19 at 10:21
  • 1
    Ok, thank you so much. I have found the solution for the last error in this answer [https://stackoverflow.com/questions/47023068/unable-to-run-ionic-app-after-update-to-android-studio-3-0](https://stackoverflow.com/questions/47023068/unable-to-run-ionic-app-after-update-to-android-studio-3-0) – Giu Jun 25 '19 at 10:33