0

我想在我的 ionic 3 应用程序中实现 firebase 推送通知。我添加了 ionic natice fcm 插件。但是当我使用以下命令构建应用程序时

ionic cordova build android

但它给了我一个错误如下:

ionic cordova build android
Running app-scripts build: --iscordovaserve --externalIpRequired --nobrowser

[12:22:34]  build dev started ...
[12:22:34]  clean started ...
[12:22:34]  clean finished in 31 ms
[12:22:34]  copy started ...
[12:22:34]  transpile started ...
[12:22:52]  transpile finished in 17.82 s
[12:22:52]  preprocess started ...
[12:22:52]  deeplinks started ...
[12:22:52]  deeplinks finished in 250 ms
[12:22:52]  preprocess finished in 297 ms
[12:22:52]  webpack started ...
[12:22:55]  copy finished in 20.24 s
[12:23:15]  webpack finished in 22.49 s
[12:23:15]  sass started ...
[12:23:19]  sass finished in 4.08 s
[12:23:19]  postprocess started ...
[12:23:19]  postprocess finished in 32 ms
[12:23:19]  lint started ...
[12:23:19]  build dev finished in 44.83 s
> cordova build android
✖ Running command - failed!

[ERROR] Cordova encountered an error.
        You may get more insight by running the Cordova command above directly.

[ERROR] An error occurred while running cordova build android (exit code 1):

        (truncated) ... aLib:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
        :CordovaLib:compileDebugJavaWithJavac UP-TO-DATE
        :CordovaLib:processDebugJavaRes UP-TO-DATE
        :CordovaLib:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
        :CordovaLib:transformClassesAndResourcesWithSyncLibJarsForDebug UP-TO-DATE
        :CordovaLib:mergeDebugJniLibFolders UP-TO-DATE
        :CordovaLib:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
        :CordovaLib:transformNative_libsWithSyncJniLibsForDebug UP-TO-DATE
        :CordovaLib:bundleDebug UP-TO-DATE
        :prepareAndroidCordovaLibUnspecifiedDebugLibrary UP-TO-DATE
        :preReleaseBuild UP-TO-DATE
        :CordovaLib:preReleaseBuild UP-TO-DATE
        :CordovaLib:checkReleaseManifest
        :CordovaLib:prepareReleaseDependencies
        :CordovaLib:compileReleaseAidl UP-TO-DATE
        :CordovaLib:compileReleaseNdk UP-TO-DATE
        :CordovaLib:copyReleaseLint UP-TO-DATE
        :CordovaLib:mergeReleaseShaders UP-TO-DATE
        :CordovaLib:compileReleaseShaders UP-TO-DATE
        :CordovaLib:generateReleaseAssets UP-TO-DATE
        :CordovaLib:mergeReleaseAssets UP-TO-DATE
        :CordovaLib:mergeReleaseProguardFiles UP-TO-DATE
        :CordovaLib:packageReleaseRenderscript UP-TO-DATE
        :CordovaLib:compileReleaseRenderscript UP-TO-DATE
        :CordovaLib:generateReleaseResValues UP-TO-DATE
        :CordovaLib:generateReleaseResources UP-TO-DATE
        :CordovaLib:packageReleaseResources UP-TO-DATE
        :CordovaLib:processReleaseManifest UP-TO-DATE
        :CordovaLib:generateReleaseBuildConfig UP-TO-DATE
        :CordovaLib:processReleaseResources UP-TO-DATE
        :CordovaLib:generateReleaseSources UP-TO-DATE
        :CordovaLib:incrementalReleaseJavaCompilationSafeguard UP-TO-DATE
        :CordovaLib:compileReleaseJavaWithJavac UP-TO-DATE
        :CordovaLib:processReleaseJavaRes UP-TO-DATE
        :CordovaLib:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
        :CordovaLib:transformClassesAndResourcesWithSyncLibJarsForRelease UP-TO-DATE
        :CordovaLib:mergeReleaseJniLibFolders UP-TO-DATE
        :CordovaLib:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE
        :CordovaLib:transformNative_libsWithSyncJniLibsForRelease UP-TO-DATE
        :CordovaLib:bundleRelease UP-TO-DATE
        :prepareComAndroidSupportSupportCompat2600Alpha1Library UP-TO-DATE
        :prepareComAndroidSupportSupportCoreUi2600Alpha1Library UP-TO-DATE
        :prepareComAndroidSupportSupportCoreUtils2600Alpha1Library UP-TO-DATE
        :prepareComAndroidSupportSupportFragment2600Alpha1Library UP-TO-DATE
        :prepareComAndroidSupportSupportMediaCompat2600Alpha1Library UP-TO-DATE
        :prepareComAndroidSupportSupportV42600Alpha1Library UP-TO-DATE
        :prepareComGoogleAndroidGmsPlayServicesAds900Library UP-TO-DATE
        :prepareComGoogleAndroidGmsPlayServicesAdsLite900Library UP-TO-DATE
        :prepareComGoogleAndroidGmsPlayServicesBase900Library UP-TO-DATE
        :prepareComGoogleAndroidGmsPlayServicesBasement1102Library UP-TO-DATE
        :prepareComGoogleAndroidGmsPlayServicesTasks1102Library UP-TO-DATE
        :prepareComGoogleFirebaseFirebaseAnalytics1102Library UP-TO-DATE
        :prepareComGoogleFirebaseFirebaseAnalyticsImpl1102Library UP-TO-DATE
        :prepareComGoogleFirebaseFirebaseCommon1102Library UP-TO-DATE
        :prepareComGoogleFirebaseFirebaseCore1102Library UP-TO-DATE
        :prepareComGoogleFirebaseFirebaseIid1102Library UP-TO-DATE
        :prepareComGoogleFirebaseFirebaseMessaging1102Library UP-TO-DATE
        :prepareDebugDependencies
        :compileDebugAidl
        :compileDebugRenderscript
        :generateDebugBuildConfig UP-TO-DATE
        :generateDebugResValues UP-TO-DATE
        :processDebugGoogleServices
        Parsing json file: D:\Projects\Code\Other\DailySheet\DailySheetMobileApp\platforms\android\google-services.json
        :generateDebugResources
        :mergeDebugResources
        :processDebugManifest UP-TO-DATE
        :processDebugResources
        :generateDebugSources
        :incrementalDebugJavaCompilationSafeguard UP-TO-DATE
        :compileDebugJavaWithJavac UP-TO-DATE
        :compileDebugNdk UP-TO-DATE
        :compileDebugSources UP-TO-DATE
        :mergeDebugShaders UP-TO-DATE
        :compileDebugShaders
        :generateDebugAssets
        :mergeDebugAssets UP-TO-DATE
        :transformClassesWithDexForDebug FAILED

        BUILD FAILED

        Total time: 1 mins 48.75 secs

        FAILURE: Build failed with an exception.

        * What went wrong:
        Execution failed for task ':transformClassesWithDexForDebug'.
        > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException:
        java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define
        Lcom/google/android/gms/internal/zzee;

        * Try:
        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
        Error: cmd: Command failed with exit code 1 Error output:
        FAILURE: Build failed with an exception.

        * What went wrong:
        Execution failed for task ':transformClassesWithDexForDebug'.
        > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException:
        java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define
        Lcom/google/android/gms/internal/zzee;

        * Try:
        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

在我添加 FCM 插件之前一切正常。我的项目信息如下:

global packages:

    @ionic/cli-utils : 1.4.0
    Cordova CLI      : 6.5.0
    Ionic CLI        : 3.4.0

local packages:

    @ionic/app-scripts              : 1.3.12
    @ionic/cli-plugin-cordova       : 1.4.0
    @ionic/cli-plugin-ionic-angular : 1.3.1
    Cordova Platforms               : android 6.1.2
    Ionic Framework                 : ionic-angular 3.5.0

System:

    Node       : v7.8.0
    OS         : Windows 10
    Xcode      : not installed
    ios-deploy : not installed
    ios-sim    : not installed
    npm        : 4.2.0

我也尝试删除所有插件和平台并重新添加它。但没有解决办法!:(

4

2 回答 2

1

解决方案在这里找到:https ://forum.ionicframework.com/t/ionic-native-fcm-plugin-issue/96601/6

最后,我找到了解决方案,这是我所做的:在以下文件中将 android.gms:play-services-ads 替换为 firebase:firebase-ads:

build.gradle project.properties plugin.xml 还要检查是否在android.gms:play-services-ads:XXX之后提供了任何版本,然后将其替换为android.gms:play-services-ads:+

于 2018-05-06T20:07:47.473 回答
0

在将 Ionic 原生 FCM 插件添加到您的应用之前,您需要在 google firebase 控制台上配置您的应用,并添加到应用根文件夹中的 GoogleService-info.plist 和 google-services.json。

尝试删除插件,添加文件,然后再次重新添加插件。

于 2018-07-07T10:08:00.517 回答