亦余心之所善兮,虽九死其犹未悔。这篇文章主要讲述Ionic Build Android - build.gradle文件不断添加重复的编译行并导致构建失败相关的知识,希望能为你提供帮助。
在我的Ionic 3项目中,我跟着this guide看看我是否可以让我的android项目进行编译,但是无论何时我尝试运行ionic cordova build android
,我都会收到此错误:
* What went wrong:
A problem occurred configuring root project 'android'.
>
Cannot add task ':processDebugGoogleServices' as a task with that name already exists.
我不确定这是否是FCM的一个问题,但我注意到,无论何时运行build命令,此行都显示在我的
build.gradle
文件中compile "com.google.firebase:firebase-messaging:9.0.2"
- 我随时删除它,它会一直显示我的其余编译语句,如下所示:dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
debugCompile(project(path: "CordovaLib", configuration: "debug"))
releaseCompile(project(path: "CordovaLib", configuration: "release"))
compile "com.google.android.gms:play-services-base:+"
compile "com.google.android.gms:play-services-ads:+"
compile "com.android.support:support-v4:24.1.1+"
compile "com.facebook.android:facebook-android-sdk:4.+"
compile "com.google.firebase:firebase-core:+"
compile "com.google.firebase:firebase-messaging:+"
compile "com.android.support:support-v4:25.+"
compile "com.android.support:appcompat-v7:25.+"
compile "com.squareup.okhttp3:okhttp:3+"
compile "com.android.support:appcompat-v7:23.2.1"
compile "com.google.firebase:firebase-messaging:9.0.2"
// SUB-PROJECT DEPENDENCIES END
}
apply plugin: 'com.google.gms.google-services'
另外,这是我的
config.xml
供参考:<
?xml version='1.0' encoding='utf-8'?>
<
widget id="<
id-omitted>
" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<
author email="snstarosciak@gmail.com" href="http://iamstevie.me">
Stevie Starosciak
<
/author>
<
content src="https://www.songbingjia.com/android/index.html" />
<
access origin="*" />
<
access origin="cdvfile://*" />
<
access origin="file://*" />
<
allow-navigation href="https://www.songbingjia.com/android/*" />
<
allow-navigation href="https://www.songbingjia.com/android/*" />
<
allow-navigation href="http://192.168.200.104:8100" />
<
allow-intent href="http://*/*" />
<
allow-intent href="https://*/*" />
<
allow-intent href="https://www.songbingjia.com/android/tel:*" />
<
allow-intent href="https://www.songbingjia.com/android/sms:*" />
<
allow-intent href="mailto:*" />
<
allow-intent href="https://www.songbingjia.com/android/geo:*" />
<
platform name="android">
<
allow-intent href="https://www.songbingjia.com/android/market:*" />
<
icon density="ldpi" src="https://www.songbingjia.com/android/resources/android/icon/drawable-ldpi-icon.png" />
<
icon density="mdpi" src="https://www.songbingjia.com/android/resources/android/icon/drawable-mdpi-icon.png" />
<
icon density="hdpi" src="https://www.songbingjia.com/android/resources/android/icon/drawable-hdpi-icon.png" />
<
icon density="xhdpi" src="https://www.songbingjia.com/android/resources/android/icon/drawable-xhdpi-icon.png" />
<
icon density="xxhdpi" src="https://www.songbingjia.com/android/resources/android/icon/drawable-xxhdpi-icon.png" />
<
icon density="xxxhdpi" src="https://www.songbingjia.com/android/resources/android/icon/drawable-xxxhdpi-icon.png" />
<
splash density="port-ldpi" src="https://www.songbingjia.com/android/resources/android/splash/drawable-port-ldpi-screen.png" />
<
splash density="port-mdpi" src="https://www.songbingjia.com/android/resources/android/splash/drawable-port-mdpi-screen.png" />
<
splash density="port-hdpi" src="https://www.songbingjia.com/android/resources/android/splash/drawable-port-hdpi-screen.png" />
<
splash density="port-xhdpi" src="https://www.songbingjia.com/android/resources/android/splash/drawable-port-xhdpi-screen.png" />
<
splash density="port-xxhdpi" src="https://www.songbingjia.com/android/resources/android/splash/drawable-port-xxhdpi-screen.png" />
<
splash density="port-xxxhdpi" src="https://www.songbingjia.com/android/resources/android/splash/drawable-port-xxxhdpi-screen.png" />
<
/platform>
<
platform name="ios">
<
allow-intent href="https://www.songbingjia.com/android/itms:*" />
<
allow-intent href="https://www.songbingjia.com/android/itms-apps:*" />
<
icon height="57" src="https://www.songbingjia.com/android/resources/ios/icon/icon.png" width="57" />
<
icon height="114" src="https://www.songbingjia.com/android/resources/ios/icon/icon@2x.png" width="114" />
<
icon height="40" src="https://www.songbingjia.com/android/resources/ios/icon/icon-40.png" width="40" />
<
icon height="80" src="https://www.songbingjia.com/android/resources/ios/icon/icon-40@2x.png" width="80" />
<
icon height="120" src="https://www.songbingjia.com/android/resources/ios/icon/icon-40@3x.png" width="120" />
<
icon height="50" src="https://www.songbingjia.com/android/resources/ios/icon/icon-50.png" width="50" />
<
icon height="100" src="https://www.songbingjia.com/android/resources/ios/icon/icon-50@2x.png" width="100" />
<
icon height="60" src="https://www.songbingjia.com/android/resources/ios/icon/icon-60.png" width="60" />
<
icon height="120" src="https://www.songbingjia.com/android/resources/ios/icon/icon-60@2x.png" width="120" />
<
icon height="180" src="https://www.songbingjia.com/android/resources/ios/icon/icon-60@3x.png" width="180" />
<
icon height="72" src="https://www.songbingjia.com/android/resources/ios/icon/icon-72.png" width="72" />
<
icon height="144" src="https://www.songbingjia.com/android/resources/ios/icon/icon-72@2x.png" width="144" />
<
icon height="76" src="https://www.songbingjia.com/android/resources/ios/icon/icon-76.png" width="76" />
<
icon height="152" src="https://www.songbingjia.com/android/resources/ios/icon/icon-76@2x.png" width="152" />
<
icon height="167" src="https://www.songbingjia.com/android/resources/ios/icon/icon-83.5@2x.png" width="167" />
<
icon height="29" src="https://www.songbingjia.com/android/resources/ios/icon/icon-small.png" width="29" />
<
icon height="58" src="https://www.songbingjia.com/android/resources/ios/icon/icon-small@2x.png" width="58" />
<
icon height="87" src="https://www.songbingjia.com/android/resources/ios/icon/icon-small@3x.png" width="87" />
<
splash height="1136" src="https://www.songbingjia.com/android/resources/ios/splash/Default-568h@2x~iphone.png" width="640" />
<
splash height="1334" src="https://www.songbingjia.com/android/resources/ios/splash/Default-667h.png" width="750" />
<
splash height="2208" src="https://www.songbingjia.com/android/resources/ios/splash/Default-736h.png" width="1242" />
<
splash height="2048" src="https://www.songbingjia.com/android/resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" />
<
splash height="2732" src="https://www.songbingjia.com/android/resources/ios/splash/Default-Portrait@~ipadpro.png" width="2048" />
<
splash height="1024" src="https://www.songbingjia.com/android/resources/ios/splash/Default-Portrait~ipad.png" width="768" />
<
splash height="960" src="https://www.songbingjia.com/android/resources/ios/splash/Default@2x~iphone.png" width="640" />
<
splash height="480" src="https://www.songbingjia.com/android/resources/ios/splash/Default~iphone.png" width="320" />
<
/platform>
<
preference name="webviewbounce" value="https://www.songbingjia.com/android/false" />
<
preference name="UIWebViewBounce" value="https://www.songbingjia.com/android/false" />
<
preference name="DisallowOverscroll" value="https://www.songbingjia.com/android/true" />
<
preference name="android-minSdkVersion" value="https://www.songbingjia.com/android/16" />
<
preference name="BackupWebStorage" value="https://www.songbingjia.com/android/none" />
<
preference name="StatusBarStyle" value="https://www.songbingjia.com/android/default" />
<
preference name="SplashScreen" value="https://www.songbingjia.com/android/screen" />
<
preference name="orientation" value="https://www.songbingjia.com/android/portrait" />
<
preference name="SplashMaintainAspectRatio" value="https://www.songbingjia.com/android/true" />
<
preference name="FadeSplashScreenDuration" value="https://www.songbingjia.com/android/300" />
<
preference name="ShowSplashScreen" value="https://www.songbingjia.com/android/true" />
<
preference name="SplashScreenDelay" value="https://www.songbingjia.com/android/30000" />
<
preference name="AutoHideSplashScreen" value="https://www.songbingjia.com/android/false" />
<
preference name="SplashShowOnlyFirstTime" value="https://www.songbingjia.com/android/false" />
<
preference name="AndroidPersistentFileLocation" value="https://www.songbingjia.com/android/Internal" />
<
preference name="FadeSplashScreen" value="https://www.songbingjia.com/android/false" />
<
feature name="StatusBar">
<
param name="ios-package" onload="true" value="https://www.songbingjia.com/android/CDVStatusBar" />
<
/feature>
<
feature name="CDVWKWebViewEngine">
<
param name="ios-package" value="https://www.songbingjia.com/android/CDVWKWebViewEngine" />
<
/feature>
<
icon src="https://www.songbingjia.com/android/resources/android/icon/drawable-xhdpi-icon.png" />
<
engine name="android" spec="^6.2.3" />
<
engine name="ios" spec="^4.4.0" />
<
plugin name="Cordova-Plugin-FCMNotification" spec="git+https://github.com/LokeshPatel/Cordova-Plugin-FCMNotification.git" />
<
plugin name="cordova-plugin-admob-free" spec="^0.9.0" />
<
plugin name="cordova-plugin-admobpro" spec="^2.29.21" />
<
plugin name="cordova-plugin-camera" spec="^2.4.1">
<
variable name="CAMERA_USAGE_DESCRIPTION" value="https://www.songbingjia.com/android/" />
<
variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="https://www.songbingjia.com/android/" />
<
/plugin>
<
plugin name="cordova-plugin-console" spec="^1.0.7" />
<
plugin name="cordova-plugin-crosswalk-webview" spec="^2.3.0">
<
variable name="XWALK_VERSION" value="https://www.songbingjia.com/android/22+" />
<
variable name="XWALK_LITEVERSION" value="https://www.songbingjia.com/android/xwalk_core_library_canary:17+" />
<
variable name="XWALK_COMMANDLINE" value="https://www.songbingjia.com/android/--disable-pull-to-refresh-effect" />
<
variable name="XWALK_MODE" value="https://www.songbingjia.com/android/embedded" />
<
variable name="XWALK_MULTIPLEAPK" value="https://www.songbingjia.com/android/true" />
<
/plugin>
<
plugin name="cordova-plugin-device" spec="^1.1.6" />
<
plugin name="cordova-plugin-email" spec="^1.2.6" />
<
plugin name="cordova-plugin-facebook4" spec="^1.9.1">
<
variable name="APP_ID" value="https://www.songbingjia.com/android/1233601713359527" />
<
variable name="APP_NAME" value="https://www.songbingjia.com/android/Bandly" />
<
/plugin>
<
plugin name="cordova-plugin-fcm" spec="^2.1.2" />
<
plugin name="cordova-plugin-file" spec="^4.3.3" />
<
plugin name="cordova-plugin-file-transfer" spec="^1.6.3" />
<
plugin name="cordova-plugin-geolocation" spec="^2.4.3">
<
variable name="GEOLOCATION_USAGE_DESCRIPTION" value="https://www.songbingjia.com/android/" />
<
/plugin>
<
plugin name="cordova-plugin-inappbrowser" spec="^1.7.1" />
<
plugin name="cordova-plugin-network-information" spec="^1.3.3" />
<
plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
<
plugin name="cordova-plugin-statusbar" spec="^2.2.3" />
<
plugin name="cordova-plugin-velda-devicefeedback" spec="0.0.2" />
<
plugin name="cordova-plugin-whitelist" spec="^1.3.2" />
<
plugin name="cordova-plugin-wkwebview-engine" spec="git+https://github.com/driftyco/cordova-plugin-wkwebview-engine.git" />
<
plugin name="cordova.plugins.diagnostic" spec="^3.6.5" />
<
plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
<
plugin name="uk.co.workingedge.phonegap.plugin.launchnavigator" spec="^4.0.1" />
<
/widget>
这是我在
project.properties
的/platforms/android
文件# Project target.
target=android-25
android.library.reference.1=CordovaLib
cordova.system.library.1=com.google.android.gms:play-services-base:+
cordova.system.library.2=com.google.android.gms:play-services-ads:+
cordova.system.library.3=com.google.android.gms:play-services-ads:+
cordova.system.library.4=com.android.support:support-v4:24.1.1+
cordova.gradle.include.1=cordova-plugin-crosswalk-webview/app-xwalk.gradle
cordova.system.library.5=com.facebook.android:facebook-android-sdk:4.+
cordova.system.library.6=com.android.support:support-v4:25.+
cordova.system.library.7=com.android.support:appcompat-v7:25.+
cordova.system.library.8=com.squareup.okhttp3:okhttp:3+
cordova.system.library.9=com.android.support:appcompat-v7:23.2.1
cordova.system.library.10=com.google.firebase:firebase-messaging:9.0.2
cordova.system.library.11=com.google.firebase:firebase-core:+
cordova.system.library.12=com.google.firebase:firebase-messaging:+
cordova.gradle.include.2=cordova-plugin-fcm/app-FCMPlugin.gradle
【Ionic Build Android - build.gradle文件不断添加重复的编译行并导致构建失败】有谁知道这里发生了什么?
答案似乎FCM gradle试图应用插件,这可能已经在你的build.gradle文件中应用了。
请按照以下说明操作。
In FCM Gradle, comment the last line (below) that contains Googleservicesplugin
“平台机器人科尔多瓦 - 插件-FCMyour_app-FCMPlugin.gradle”
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath 'com.google.gms:google-services:3.0.0'
}
}
// apply plugin: 'com.google.gms.google-services' <
---- COMMENT THIS LINE TOO, add to Root gradle file
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
//apply plugin: com.google.gms.googleservices.GoogleServicesPlugin <
---- COMMENT THIS LINE
推荐阅读
- PhoneGap - 后退按钮上的android退出
- 将电子应用转移到cordova app
- 将OneSignal插件添加到Ionic App后生成APK时出错
- Ionic app,错误(..main.ts模块构建失败:错误:ENOENT)
- 从Android访问Windows WebService获取IP地址
- 本文教你u盘不显示怎样办
- 本文教你华硕主板bios设置图解
- 图文详细说明win7系统U盘插入后假死怎样处理
- 图文详细说明u盘不能格式化怎样办