Zerok
Zerok

Reputation: 1513

Can't build an Android Cordova project (Ionic 5)

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.

Upvotes: 2

Views: 1155

Answers (2)

scor4er
scor4er

Reputation: 1579

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.

Upvotes: 2

Pedro Marthon
Pedro Marthon

Reputation: 101

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 
}

Upvotes: 1

Related Questions