Ionic Build Android - build.gradle文件不断添加重复的编译行并导致构建失败

问题描述 投票:1回答:1

在我的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="[email protected]" href="http://iamstevie.me">
        Stevie Starosciak
  </author>
    <content src="index.html" />
    <access origin="*" />
    <access origin="cdvfile://*" />
    <access origin="file://*" />
    <allow-navigation href="*" />
    <allow-navigation href="*" />
    <allow-navigation href="http://192.168.200.104:8100" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
        <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
        <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
        <splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <icon height="57" src="resources/ios/icon/icon.png" width="57" />
        <icon height="114" src="resources/ios/icon/[email protected]" width="114" />
        <icon height="40" src="resources/ios/icon/icon-40.png" width="40" />
        <icon height="80" src="resources/ios/icon/[email protected]" width="80" />
        <icon height="120" src="resources/ios/icon/[email protected]" width="120" />
        <icon height="50" src="resources/ios/icon/icon-50.png" width="50" />
        <icon height="100" src="resources/ios/icon/[email protected]" width="100" />
        <icon height="60" src="resources/ios/icon/icon-60.png" width="60" />
        <icon height="120" src="resources/ios/icon/[email protected]" width="120" />
        <icon height="180" src="resources/ios/icon/[email protected]" width="180" />
        <icon height="72" src="resources/ios/icon/icon-72.png" width="72" />
        <icon height="144" src="resources/ios/icon/[email protected]" width="144" />
        <icon height="76" src="resources/ios/icon/icon-76.png" width="76" />
        <icon height="152" src="resources/ios/icon/[email protected]" width="152" />
        <icon height="167" src="resources/ios/icon/[email protected]" width="167" />
        <icon height="29" src="resources/ios/icon/icon-small.png" width="29" />
        <icon height="58" src="resources/ios/icon/[email protected]" width="58" />
        <icon height="87" src="resources/ios/icon/[email protected]" width="87" />
        <splash height="1136" src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" />
        <splash height="1334" src="resources/ios/splash/Default-667h.png" width="750" />
        <splash height="2208" src="resources/ios/splash/Default-736h.png" width="1242" />
        <splash height="2048" src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" />
        <splash height="2732" src="resources/ios/splash/Default-Portrait@~ipadpro.png" width="2048" />
        <splash height="1024" src="resources/ios/splash/Default-Portrait~ipad.png" width="768" />
        <splash height="960" src="resources/ios/splash/Default@2x~iphone.png" width="640" />
        <splash height="480" src="resources/ios/splash/Default~iphone.png" width="320" />
    </platform>
    <preference name="webviewbounce" value="false" />
    <preference name="UIWebViewBounce" value="false" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="android-minSdkVersion" value="16" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="StatusBarStyle" value="default" />
    <preference name="SplashScreen" value="screen" />
    <preference name="orientation" value="portrait" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="ShowSplashScreen" value="true" />
    <preference name="SplashScreenDelay" value="30000" />
    <preference name="AutoHideSplashScreen" value="false" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="AndroidPersistentFileLocation" value="Internal" />
    <preference name="FadeSplashScreen" value="false" />
    <feature name="StatusBar">
        <param name="ios-package" onload="true" value="CDVStatusBar" />
    </feature>
    <feature name="CDVWKWebViewEngine">
        <param name="ios-package" value="CDVWKWebViewEngine" />
    </feature>
    <icon src="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=" " />
        <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value=" " />
    </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="22+" />
        <variable name="XWALK_LITEVERSION" value="xwalk_core_library_canary:17+" />
        <variable name="XWALK_COMMANDLINE" value="--disable-pull-to-refresh-effect" />
        <variable name="XWALK_MODE" value="embedded" />
        <variable name="XWALK_MULTIPLEAPK" value="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="1233601713359527" />
        <variable name="APP_NAME" value="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=" " />
    </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

有谁知道这里发生了什么?

android cordova firebase ionic-framework ionic3
1个回答
0
投票

似乎FCM gradle试图应用插件,这可能已经在你的build.gradle文件中应用了。

请按照以下说明操作。

In FCM Gradle, comment the last line (below) that contains Googleservicesplugin

“\平台\机器人\科尔多瓦 - 插件-FCM \ your_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
© www.soinside.com 2019 - 2024. All rights reserved.