[英]Can't build an Android Cordova project (Ionic 5)
我正在 Ionic 5 中制作一個應用程序(使用 Angular 作為我選擇的框架),它使用 Cordova 來編譯最終的混合應用程序。
隨着最后的開發期即將到來,我正在嘗試將一些廣告放入應用程序中。 為此,我使用了 Cordova 的插件“AdMobFree”,並將其與 ionic-native/admob-free NPM package 集成,以使用我的代碼庫中的插件。
問題是,我無法編譯任何東西。 我得到的錯誤似乎與 Google Play Services package 有關。 此錯誤開始給我以下警告:
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'
因為它只是一個警告,所以我不會給它太多的信任,但我會添加它以防萬一。 問題的很大一部分似乎在這里:
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.
我嘗試在我的 package.json 中聲明不同版本的 Google Play 服務,但我無法解決此錯誤。 當我將它與ionic serve
一起使用時,該應用程序運行良好(即使 AdMobFree 插件不起作用,因為它位於瀏覽器而不是移動設備上),所以我想這不是我的代碼庫或插件本身的問題,而是,我的 Android SDK 版本等有問題。
有人知道如何解決這個煩人的錯誤嗎?
十分感謝!
編輯:我的環境如下所示:
Windows 10
Node Version: 14.1
Ionic Version: 5.4.14
Cordova Android: ^8.1.0
這是我的 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
}
編輯2:經過多次嘗試和兩個答案,這仍然不起作用。 我一遍又一遍地遇到同樣的錯誤,提到了谷歌播放服務依賴錯誤,特別是com.google.android.gms:play-services-measurement-api
ZEFE90A8E604A7C840E88D03A67F。
這已經失控了,因為我已經嘗試了所有解決方案,但似乎沒有任何結果。 我不能強調我在這方面需要多少幫助。
我能夠重現類似的問題,創建一個空的 Ionic 應用程序並添加以下兩個插件: cordova-plugin-firebase-analytics
和cordova-plugin-admob-free
。 我必須在 Admob 和 Firebase 注冊測試應用程序並下載 Firebase 配置文件。 日志中的相同依賴項相關錯誤。 我遵循了這個 線程的建議。
這是我所做的:
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"
這為我解決了這個問題。
這似乎是一些 google 依賴項相互沖突,並且包含在 ionic 框架中。
檢查以下線程因為它可以解決您的問題。
此外,嘗試將以下內容添加到您的 build.gradle 文件並再次構建您的應用程序以查看 gradle 是否為您提供更多詳細信息。
googleServices {
disableVersionCheck = false
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.