gradle上的cordova-plugin-googlemap后出错
Posted
技术标签:
【中文标题】gradle上的cordova-plugin-googlemap后出错【英文标题】:Error after cordova-plugin-googlemap on gradle 【发布时间】:2018-12-12 07:24:42 【问题描述】:我最近做了一个正在运行的 cordova 项目,这个插件已经在工作了:
call-number 0.0.2 "Cordova Call Number Plugin"
com.cordova.teamViewerSDK 0.1.0 "Team Viewer SDK"
cordova-plugin-camera 2.4.1 "Camera"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-device 1.1.6 "Device"
cordova-plugin-dialogs 1.3.3 "Notification"
cordova-plugin-file 4.0.0 "File"
cordova-plugin-file-transfer 1.6.3 "File Transfer"
cordova-plugin-geolocation 2.4.3 "Geolocation"
cordova-plugin-inappbrowser 1.7.2 "InAppBrowser"
cordova-plugin-network-information 1.3.3 "Network Information"
cordova-plugin-request-location-accuracy 2.2.2 "Request Location Accuracy"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-themeablebrowser 0.2.17 "ThemeableBrowser"
cordova-plugin-whitelist 1.3.2 "Whitelist"
cordova-plugin-x-socialsharing 5.1.8 "SocialSharing"
cordova-plugin-x-toast 2.6.0 "Toast"
cordova-universal-links-plugin 1.2.1 "Universal Links Plugin"
cordova.plugins.diagnostic 3.9.2 "Diagnostic" es6-promise-plugin 4.1.0 "Promise"
kunder-cordova-plugin-webview 2.5.1 "Cordova Second Webview"
phonegap-plugin-push 2.1.3 "PushPlugin"
现在我正在尝试安装 cordova-plugin-google maps,安装后我在 android Studio 上收到此错误:
Project with path ':ScreenSharingSDK' could not be found in project ':app'.
这就是 app build.gradle 的样子:
dependencies
implementation fileTree(include: '*.jar', dir: 'libs')
// SUB-PROJECT DEPENDENCIES START
implementation(project(path: ":CordovaLib"))
compile "com.android.support:support-v4:24.1.1+"
compile "com.google.android.gms:play-services-location:11.6.2"
compile "com.android.support:support-v4:26.+"
compile "com.android.support:appcompat-v7:26.+"
compile "com.android.support:support-v13:26.+"
compile "me.leolin:ShortcutBadger:1.1.17@aar"
compile "com.google.firebase:firebase-messaging:11.6.2"
compile "com.google.android.gms:play-services-maps:15.0.1"
compile "com.google.android.gms:play-services-location:15.0.1"
compile "com.android.support:support-core-utils:26.1.0"
// SUB-PROJECT DEPENDENCIES END
compile('com.crashlytics.sdk.android:crashlytics:2.9.0@aar')
transitive = true;
implementation files('src/main/libs/ksoap2-android-assembly-2.6.5-jar-with-dependencies.jar')
implementation files('src/main/libs/mtscra.jar')
implementation project(':ScreenSharingSDK')
我评论了 implementation project(':ScreenSharingSDK') ,以确保 google maps 插件正常工作,但随后出现此错误:
Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 11.6.2.
这就是我的 project.properties 的样子:
target=android-26
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.system.library.1=com.android.support:support-v4:24.1.1+
cordova.system.library.2=com.google.android.gms:play-services-location:11.6.2
cordova.system.library.3=com.android.support:support-v4:24.1.1+
cordova.system.library.4=com.android.support:support-v4:26.+
cordova.system.library.5=com.android.support:appcompat-v7:26.+
cordova.gradle.include.1=phonegap-plugin-push/pp-push.gradle
cordova.system.library.6=com.android.support:support-v13:26.+
cordova.system.library.7=me.leolin:ShortcutBadger:1.1.17@aar
cordova.system.library.8=com.google.firebase:firebase-messaging:11.6.2
cordova.gradle.include.2=com.cordova.teamViewerSDK/pp-build.gradle
cordova.gradle.include.3=cordova-plugin-badge/perpetualpay-badge.gradle
cordova.system.library.9=com.android.support:support-v4:26.+
cordova.gradle.include.4=cordova-plugin-local-notification/perpetualpay- localnotification.gradle
cordova.gradle.include.5=cordova-plugin-googlemaps/perpetualpay-tbxml-android.gradle
cordova.system.library.10=com.google.android.gms:play-services-maps:15.0.1
cordova.system.library.11=com.google.android.gms:play-services-location:15.0.1
cordova.system.library.12=com.android.support:support-core-utils:26.1.0
然后我按照这个逻辑could not build/run after google-maps plugin installed,没有成功。
我认为 cordova cli 会处理 gradle 细节,我怎样才能让这个插件在我当前的环境中工作?
npm Version: 5.6.0
Cordova Version: 8.0.0
Gradle version: 4.4
【问题讨论】:
听起来好像是在platforms/android中寻找ScreenSharingSDK,不存在。我怀疑它来自谷歌地图插件,听起来它来自实际使用屏幕共享 sdks 的 Team Viewer SDK 是的,我刚刚检查过,问题几乎肯定来自Team Viewer SDK
。如果您查看plugin.xml
文件,您会看到<resource-file src="lib/android/ScreenSharingSDK.aar" target="lib/android/ScreenSharingSDK.aar" />
听起来好像它丢失了。
谢谢BShaps,安装cordova-plugin-googlemaps后出于某种原因,我失去了对ScreenSharingSDK的引用,我更新了我的google play服务,安装了gogole-maps,最后重新安装了ScreenSharingSDK。
太棒了,很高兴听到你把它修好了!这是 googlemaps 插件非常奇怪的行为,我想知道为什么会这样。
github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/…
【参考方案1】:
所以我终于解决了这个问题,由于某种原因,在安装 cordova-plugin-googlemaps 之后,所有对 cordova-team-viewer 的引用都丢失了。
为了安装cordova-plugin-googlemaps,我按照以下步骤操作:
-
在 Android Studio SDK 级别升级 Google Play Services。
更新 Google Play 服务 .gradle 文件。
platforms/android/app/build.gradle类路径'com.google.gms:google-services:4.0.1'
编译“com.google.android.gms:play-services-location:15.0.1”
编译“com.android.support:support-core-utils:26.1.0”
platforms/android/build.gradle谷歌()
类路径'com.android.tools.build:gradle:3.1.3'
platforms/android/CordovaLib/build.gradle谷歌()
类路径'com.android.tools.build:gradle:3.1.3'
platforms/android/project.propertiescordova.system.library.2=com.google.android.gms:play-services-location:15.0.1
cordova.system.library.8=com.google.firebase:firebase-messaging:15.0.2
platforms/android/app/src/main/AndroidManifest.xml安装谷歌地图插件,定义PLAY_SERVICES_VERSION
cordova 插件添加 cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="your key" --variable API_KEY_FOR_ios="your key" --variable PLAY_SERVICES_VERSION="15.0.1"重新安装 cordova-team-viewer 插件
cordova 插件删除 com.cordova.teamViewerSDK cordova 插件添加 com.cordova.teamViewerSDK【讨论】:
以上是关于gradle上的cordova-plugin-googlemap后出错的主要内容,如果未能解决你的问题,请参考以下文章
Android Studio上的gradle项目同步失败错误
Gradle 3.3 版不支持 BuildActionExecuter 上的 forTask() 方法
“ gradle appRun”上的Groovy NullPointerException
Android Studio 3.5.0 上的 Gradle 错误“variant.getMergeResources()”