2

I'm making an app in Ionic 5 (with Angular as my framework of choice), which uses Cordova for compiling the final hybrid app.

As the final development period is coming, I'm trying to put some ads into the app. For that, I used the Cordova's plugin "AdMobFree", and integrated it with ionic-native/admob-free NPM package for using the plugin from my codebase.

Thing is, I'm not being able to compile anything. The error I'm getting seems to be related with the Google Play Services package. This error starts giving me the following warning:

WARNING in ./node_modules/parse/node_modules/crypto-js/core.js
Module not found: Error: Can't resolve 'crypto' in 'D:\Dev\bygymapp\node_modules\parse\node_modules\crypto-js'

As it is only a warning, I don't give it too much credit, but I add it in case it's related. The big chunk of the problem seems to be here:

    BUILD FAILED in 14s
D:\Dev\bygymapp\platforms\android\gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[17.0.
  0]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.

  Dependency failing: com.google.android.gms:play-services-measurement-api:17.0.0 -> com.google.android.gms:play-services-
  measurement-sdk-api@[17.0.0], but play-services-measurement-sdk-api version was 17.1.0.

  The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art
  ifact with the issue.
  -- Project 'app' depends onto com.google.android.gms:play-services-ads@11.0.4
  -- Project 'app' depends onto com.google.android.gms:play-services-measurement-sdk@17.0.0
  -- Project 'app' depends onto com.google.android.gms:play-services-ads@19.0.1
  -- Project 'app' depends onto com.google.android.gms:play-services-gass@19.0.1
  -- Project 'app' depends onto com.google.firebase:firebase-core@17.0.0
  -- Project 'app' depends onto com.google.android.gms:play-services-ads@16.0.0
  -- Project 'app' depends onto com.google.android.gms:play-services-tagmanager-api@17.0.0
  -- Project 'app' depends onto com.google.firebase:firebase-analytics@17.0.0
  -- Project 'app' depends onto com.google.android.gms:play-services-tagmanager@17.0.0
  -- Project 'app' depends onto com.google.android.gms:play-services-measurement-api@17.0.0
  -- Project 'app' depends onto com.google.android.gms:play-services-measurement-sdk-api@17.1.0
  -- Project 'app' depends onto com.google.android.gms:play-services-ads-lite@19.0.1

  For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dep
  endency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at https://
  github.com/google/play-services-plugins and disable by adding "googleServices { disableVersionCheck = false }" to your b
  uild.gradle file.

I tried declaring different versions of the Google Play Service in my package.json, but I couldn't manage to get this error off. The app works well when I use it with ionic serve (even if the AdMobFree plugin doesn't work because it's on a browser instead of a mobile device), so I guess it's not a problem of my codebase nor the plugin itself, but rather, a problem with my Android SDK versions and so.

Anybody got any idea on how to fix this annoying error?

Thank you a lot!

edit: my environment looks like this:

Windows 10
Node Version: 14.1
Ionic Version: 5.4.14
Cordova Android: ^8.1.0

This is my build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        classpath 'com.android.tools.build:gradle:3.3.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }

    //This replaces project.properties w.r.t. build settings
    project.ext {
      defaultBuildToolsVersion="28.0.3" //String
      defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
      defaultTargetSdkVersion=28 //Integer - We ALWAYS target the latest by default
      defaultCompileSdkVersion=28 //Integer - We ALWAYS compile with the latest by default
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

edit 2: After many attempts and two answers, this is still not working. I'm getting the same error over and over, with the mention to the Google Play Services dependency error, especially with the com.google.android.gms:play-services-measurement-api package.

This is getting out of hand since I already tried every solution and nothing seems to yield results. I can't stress enough how much I need help with this.

Zerok
  • 1,323
  • 1
  • 24
  • 56
  • The log clearly specify, sounds like either dependency version conflict or you missed to add something. Can't specifically say what's going on, Google it the log title - `In project app a resolved Google Play services library dependency depends on another at an exact version` – Anoop M Maddasseri May 19 '20 at 09:06
  • Sure @AnoopM, but I don't have any clue on how to fix this. Is it something wrong with the Gradle compilation, or rather with my package.json dependencies? – Zerok May 19 '20 at 09:22
  • Try finding a `build.gradle` file and post it in your question. – ahasbini May 23 '20 at 02:04
  • @ahasbini thank you! I just posted it :) – Zerok May 25 '20 at 16:05
  • The `build.gradle` file you posted is in good order. There might be more than one `build.gradle` files in folder/sub-folders, if you found more or all of them then please post them too – ahasbini May 25 '20 at 17:01
  • There seems to be an issue with the dependencies of firebase like https://stackoverflow.com/a/56028118/2949966 and https://forum.ionicframework.com/t/android-build-falid-the-library-com-google-android-gms-play-services-measurement-base-is-being-requested-by-various-other-libraries/163390 Have you seen them and tried any of their solutions mentioned? – ahasbini May 25 '20 at 17:12

2 Answers2

2

I was able to reproduce similar issue creating an empty Ionic app and adding the following two plugins: cordova-plugin-firebase-analytics & cordova-plugin-admob-free. I had to register the test app at Admob & Firebase and download the Firebase config file. The same dependencies related error in the log. I followed the suggestions from this thread.

Here's what I did:

cordova plugin rm cordova-plugin-admob-free --variable ADMOB_APP_ID="xxx"
cordova plugin add cordova-admob-sdk
cordova plugin add cordova-plugin-admob-free --variable ADMOB_APP_ID="xxx"

This has fixed the problem for me.

scor4er
  • 1,580
  • 12
  • 23
  • I tried the solution but it's not working for me. StackOverFlow marked a random answer as valid because I've been a few days out, but the actual problem is not solved yet. Anyways, thank you a lot for the try. After testing your solution, I stumbled upon the same problem. Did you do anything else to get this fixed? – Zerok Jun 01 '20 at 08:53
  • 1
    @Zerok sorry that it doesn't help. That's all I did actually. At first I tried to use `"cordova-admob-sdk": { "PLAY_SERVICES_VERSION": "15.0.1" }` for `cordova-admob-sdk` as it's said in the last post of the tread I mentioned. I played with different version numbers, but for some reason I got random errors when I set the version explicitly. – scor4er Jun 01 '20 at 13:02
  • I will keep trying, but anyway, lots of thanks, @scor4er! I will post updates if I keep failing with this. – Zerok Jun 01 '20 at 13:08
1

This seems like some google dependencies are conflicting with each other and the ones included in the ionic framework.

Check the following thread cuz it could fix your problem.

Also, try adding the following to your build.gradle file and build your app again to see if gradle gives you any more details.

googleServices { 
    disableVersionCheck = false 
}