简体   繁体   English

无法构建 Android Cordova 项目(离子 5)

[英]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.我正在 Ionic 5 中制作一个应用程序(使用 Angular 作为我选择的框架),它使用 Cordova 来编译最终的混合应用程序。

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.为此,我使用了 Cordova 的插件“AdMobFree”,并将其与 ionic-native/admob-free NPM package 集成,以使用我的代码库中的插件。

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.我得到的错误似乎与 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.我尝试在我的 package.json 中声明不同版本的 Google Play 服务,但我无法解决此错误。 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.当我将它与ionic serve一起使用时,该应用程序运行良好(即使 AdMobFree 插件不起作用,因为它位于浏览器而不是移动设备上),所以我想这不是我的代码库或插件本身的问题,而是,我的 Android SDK 版本等有问题。

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:这是我的 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.编辑2:经过多次尝试和两个答案,这仍然不起作用。 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.我一遍又一遍地遇到同样的错误,提到了谷歌播放服务依赖错误,特别是com.google.android.gms:play-services-measurement-api ZEFE90A8E604A7C840E88D03A67F。

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.我不能强调我在这方面需要多少帮助。

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 .我能够重现类似的问题,创建一个空的 Ionic 应用程序并添加以下两个插件: cordova-plugin-firebase-analyticscordova-plugin-admob-free I had to register the test app at Admob & Firebase and download the Firebase config file.我必须在 Admob 和 Firebase 注册测试应用程序并下载 Firebase 配置文件。 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.这为我解决了这个问题。

This seems like some google dependencies are conflicting with each other and the ones included in the ionic framework.这似乎是一些 google 依赖项相互冲突,并且包含在 ionic 框架中。

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.此外,尝试将以下内容添加到您的 build.gradle 文件并再次构建您的应用程序以查看 gradle 是否为您提供更多详细信息。

googleServices { 
    disableVersionCheck = false 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM