'Ionic build fails at "Could not resolve com.google.android.gms:play-services-ads-identifier:[15.0.0, 16.0.99]"

So building was always fine until it wasn't. Nothing new was added, nothing was removed, no packages installed, nothing. Everything was working fine until the build issues happened. This is the full error report

> Configure project :app
Error 'Plugin-Version' of 'unspecified' for 'com.android.build.gradle.AppPlugin@4aae70b2' is not a valid version number

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve com.google.android.gms:play-services-ads-identifier:[15.0.0, 16.0.99].
     Required by:
         project :app > com.onesignal:OneSignal:3.16.0
      > Failed to list versions for com.google.android.gms:play-services-ads-identifier.
         > Could not list versions using M2 pattern 'https://jcenter.bintray.com/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])'.
            > Could not get resource 'https://jcenter.bintray.com/com/google/android/gms/play-services-ads-identifier/'.
               > Could not GET 'https://jcenter.bintray.com/com/google/android/gms/play-services-ads-identifier/'.
                  > org.apache.http.client.ClientProtocolException (no error message)
      > Failed to list versions for com.google.android.gms:play-services-ads-identifier.
         > Could not list versions using M2 pattern 'https://jcenter.bintray.com/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])'.
            > Could not get resource 'https://jcenter.bintray.com/com/google/android/gms/play-services-ads-identifier/'.
               > Could not GET 'https://jcenter.bintray.com/com/google/android/gms/play-services-ads-identifier/'.
                  > org.apache.http.client.ClientProtocolException (no error message)
   > Could not resolve com.google.android.gms:play-services-basement:[15.0.1,16.0.0).
     Required by:
         project :app > com.google.android.gms:play-services-location:15.0.1
         project :app > com.google.android.gms:play-services-places-placereport:15.0.1
      > Failed to list versions for com.google.android.gms:play-services-basement.
         > Could not list versions using M2 pattern 'https://jcenter.bintray.com/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])'.
            > Could not get resource 'https://jcenter.bintray.com/com/google/android/gms/play-services-basement/'.
               > Could not GET 'https://jcenter.bintray.com/com/google/android/gms/play-services-basement/'.
                  > org.apache.http.client.ClientProtocolException (no error message)
      > Failed to list versions for com.google.android.gms:play-services-basement.
         > Could not list versions using M2 pattern 'https://jcenter.bintray.com/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])'.
            > Could not get resource 'https://jcenter.bintray.com/com/google/android/gms/play-services-basement/'.
               > Could not GET 'https://jcenter.bintray.com/com/google/android/gms/play-services-basement/'.
                  > org.apache.http.client.ClientProtocolException (no error message)
   > Could not resolve com.google.android.gms:play-services-tasks:[15.0.1,16.0.0).
     Required by:
         project :app > com.google.android.gms:play-services-location:15.0.1
      > Failed to list versions for com.google.android.gms:play-services-tasks.
         > Could not list versions using M2 pattern 'https://jcenter.bintray.com/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])'.
            > Could not get resource 'https://jcenter.bintray.com/com/google/android/gms/play-services-tasks/'.
               > Could not GET 'https://jcenter.bintray.com/com/google/android/gms/play-services-tasks/'.
                  > org.apache.http.client.ClientProtocolException (no error message)
      > Failed to list versions for com.google.android.gms:play-services-tasks.
         > Could not list versions using M2 pattern 'https://jcenter.bintray.com/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])'.
            > Could not get resource 'https://jcenter.bintray.com/com/google/android/gms/play-services-tasks/'.
               > Could not GET 'https://jcenter.bintray.com/com/google/android/gms/play-services-tasks/'.
                  > org.apache.http.client.ClientProtocolException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Any ideas on what could be causing this? I tried the following but nothing resolved the issue:

  • Re-installing npm package after uninstalling them + reinitializing platforms and plugins
  • Updating gradle from 7.2 to 7.4.2
  • Removing OneSignal plugin


Solution 1:[1]

I have managed to resolve this issue after hours-long sessions of trial and error, here's what I did in short:

  1. (Optional) downgraded to npm 6 to avoid incompatible package-lock.json errors.
  2. Upgrade to the latest Gradle version (7.4.2 as of writing this answer).
  3. Install Android SDK build tools version 30.0.3.
  4. Remove Android platform, delete installed packages and old builds
  5. Reinstall npm packages, read Android platform, and finally build your project.

Here's a more in-depth step-by-step of the above:

  1. First I had the terminal spammed with endless npm resolve issues left and right, I used to run npm install --force to ensure everything passed intently, but now I downgraded npm globally from version 8 to 6 because the project's package-lock.json was generated using an older version of npm, so there were some incompatibilities between the lockFileVersion being changed from 1 to 2.

  2. Secondly, I updated my Gradle version from 7.1.1 to 7.4.2 (the latest as of writing this answer) and then updated the environment variable path pointing to the bin folder to point to the correct Gradle version (7.4.2).

  3. Thirdly, I installed the necessary Android build tools version, previously version 30.0.2 worked fine for the project, but now it wouldn't finish building without complaining about the outdated version, so I went ahead and installed version 30.0.3, you can easily getting from this link, or you can browse the full catalog of available builds here.

  4. Finally, I android from the viable platforms and deleted all previously generated builds, old package-lock.json file, installed packages, plugins, and generated platforms directory.

    ionic cordova platform rm android
    
    npm rm -rf package-lock.json node_modules www plugins platforms
    

    Then reinstalled node modules

    npm install
    

    Re-add the android platform

    ionic cordova platform add android
    

    And concluded by building the project

    ionic cordova build android
    

This is optional, but if your build complained about the whiltelist plugin, simply do the following:

1.

ionic cordova plugin rm cordova-plugin-whitelist

cordova plugin add https://github.com/apache/cordova-plugin-file-transfer.git
  1. Then re-build your project

Solution 2:[2]

try replace

jcenter()

with this:

mavenCentral()

and see this issue JCenter deprecation; impact on Gradle and Android

Solution 3:[3]

just remove your platform android@ old version and add platform android@9, then can make it.

Solution 4:[4]

I just updated the version of cordova-android to 9.0.0 in package.json.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 shuabing
Solution 3 ZHANGQIANG MA
Solution 4