当前位置: 首页 > 知识库问答 >
问题:

Ionic的本机“Push”插件导致错误

田博远
2023-03-14

我正在尝试在我的ionic应用程序中实现推送通知。为此,我想使用本机插件Push:

https://ionicframework.com/docs/native/push/

在安装这个插件之前,我可以在我的Android设备上启动我的应用程序,使用:

ionic cordova run android
ionic cordova plugin add phonegap-plugin-push
npm install --save @ionic-native/push

我不能再运行我的设备上的应用程序,因为构建失败,因为一堆错误。

BUILD FAILED

Total time: 22.02 secs
Error: cmd: Command failed with exit code 1 Error output:
D:\Data\njonkman\Desktop\kostendeclaratie_mobile - Copy\platforms\android\AndroidManifest.xml:28:13-35 Error:
        Attribute meta-data#android.support.VERSION@value value=(25.4.0) from [com.android.support:appcompat-v7:25.4.0] AndroidManifest.xml:28:13-35
        is also present at [com.android.support:support-v13:26.1.0] AndroidManifest.xml:28:13-35 value=(26.1.0).
        Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:26:9-28:38 to override.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processDebugManifest'.
> Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(25.4.0) from [com.android.support:appcompat-v7:25.4.0] AndroidManifest.xml:28
:13-35
        is also present at [com.android.support:support-v13:26.1.0] AndroidManifest.xml:28:13-35 value=(26.1.0).
        Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:26:9-28:38 to override.

这个错误有一个建议:将'tools:replace=“android:value”‘添加到AndroidManifest中的eleemet中。我这样做了,在重新构建之后,我得到了这个错误:

BUILD FAILED

Total time: 2.171 secs
> Exception while parsing the supplied manifest file D:\Data\njonkman\Desktop\kostendeclaratie_mobile - Copy\platforms\android\AndroidManifest.xml

* 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:
[Fatal Error] :13:146: The prefix "tools" for attribute "tools:replace" associated with an element type "meta-data" is not bound.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Exception while parsing the supplied manifest file D:\Data\njonkman\Desktop\kostendeclaratie_mobile - Copy\platforms\android\AndroidManifest.xml

我发现的另一个“解决方案”是添加这段代码:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.1'
            }
        }
    }
}
BUILD FAILED
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

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

Total time: 12.765 secs
Error: cmd: Command failed with exit code 1 Error output:
D:\Data\njonkman\Desktop\kostendeclaratie_mobile - Copy\platforms\android\src\com\adobe\phonegap\push\FCMService.java:393: error: constructor Builder in class Bu
ilder cannot be applied to given types;
        mBuilder = new NotificationCompat.Builder(context, channelID);
                   ^
  required: Context
  found: Context,String
  reason: actual and formal argument lists differ in length
D:\Data\njonkman\Desktop\kostendeclaratie_mobile - Copy\platforms\android\src\com\adobe\phonegap\push\FCMService.java:403: error: constructor Builder in class Bu
ilder cannot be applied to given types;
        mBuilder = new NotificationCompat.Builder(context, channelID);
                   ^
  required: Context
  found: Context,String
  reason: actual and formal argument lists differ in length
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
cordova.system.library.1=com.google.android.gms:play-services-auth:11.0.4
cordova.system.library.2=com.google.android.gms:play-services-identity:11.0.4

添加到project.propertieshtml" target="_blank">文件,但又出现了另一个错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bint
ray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 11.0.1.

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

BUILD FAILED

Total time: 3.547 secs
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bint
ray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 11.0.1.

所以我也尝试使用11.0.1(而不是同时安装的11.0.4):

但它给了我这个错误:

BUILD FAILED

Total time: 14.349 secs
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:
D:\Data\njonkman\Desktop\kostendeclaratie_mobile - Copy\platforms\android\src\com\adobe\phonegap\push\FCMService.java:393: error: constructor Builder in class Bu
ilder cannot be applied to given types;
        mBuilder = new NotificationCompat.Builder(context, channelID);
                   ^
  required: Context
  found: Context,String
  reason: actual and formal argument lists differ in length
D:\Data\njonkman\Desktop\kostendeclaratie_mobile - Copy\platforms\android\src\com\adobe\phonegap\push\FCMService.java:403: error: constructor Builder in class Bu
ilder cannot be applied to given types;
        mBuilder = new NotificationCompat.Builder(context, channelID);
                   ^
  required: Context
  found: Context,String
  reason: actual and formal argument lists differ in length
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
ionic cordova plugin remove phonegap-plugin-push

编辑

所以我创建了一个新的Ionic应用程序,其样板如下:

ionic start myApp tabs

我这样安装phonegap插件:

ionic cordova plugin add phonegap-plugin-push
ionic cordova run android
cli packages: (C:\Users\njonkman\AppData\Roaming\npm\node_modules)

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 8.0.0

local packages:

    @ionic/app-scripts : 3.1.6
    Cordova Platforms  : android 6.3.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Node : v6.11.3
    npm  : 4.6.1
    OS   : Windows 10

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro
npm install -g cordova 
npm install -g ionic

而且

npm install @ionic/app-scripts@latest

但再次运行后,我得到了前面的一个错误:

BUILD FAILED in 2s
(node:19208) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:
D:\Data\njonkman\Desktop\kostendeclaratie_mobile - Copy (2)\platforms\android\app\src\main\AndroidManifest.xml:28:13-35 Error:
        Attribute meta-data#android.support.VERSION@value value=(26.1.0) from [com.android.support:support-v13:26.1.0] AndroidManifest.xml:28:13-35
        is also present at [com.android.support:appcompat-v7:25.4.0] AndroidManifest.xml:28:13-35 value=(25.4.0).
        Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:26:9-28:38 to override.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.1.0) from [com.android.support:support-v13:26.1.0] AndroidManifest.xml:28:
13-35
        is also present at [com.android.support:appcompat-v7:25.4.0] AndroidManifest.xml:28:13-35 value=(25.4.0).
        Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:26:9-28:38 to override.

此时,重新创建一个新项目,安装我需要的所有插件,测试它们是否工作,然后将我的逻辑/类添加到其中,不是更好吗?

编辑

所以我已经“弄清楚了”是什么导致了这些问题,我还不知道为什么会发生这种情况或者如何解决它。我正在使用两个插件,单独工作很好,但两个安装,导致错误。这些插件是:

  • https://ionicframework.com/docs/native/file-path/
  • https://ionicframework.com/docs/native/push/

共有1个答案

慕容烨
2023-03-14

好的,所以我已经设法解决了我的问题。我就是这么做的:

我创建了一个空白的Ionic项目(Ionic start blank)来测试插件是否可以在新创建的项目中工作。是的。之后,我一个接一个地安装了所有其他插件,看看它是否还能工作。在某个时候,我遇到了文件路径插件(https://ionicframework.com/docs/native/file-path/)。安装这个插件后,我得到了与操作中提到的相同的错误。在谷歌搜索(?)有点我发现了这个话题:

android更新到新版本gradle后出现获取清单合并失败错误

解决方案之一是将这段代码添加到build.gradle文件中:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '26.1.0'
            }
        }
    }
}

请注意,我已经尝试过similair解决方案,但版本号不同(25.3.1)。错误提到了两个版本,我选择了解决方案中最近的一个(26.1.0),但最初没有。

在空白项目上试用后,我在现有的项目上试用了它。只是为了确定我删除了平台(ionic cordova rm平台android)并重新添加了它(ionic cordova add平台android)。还请注意,我将上面的内容添加到了Platforms>Android>App中的build.gradle中,而不是在Platforms>Android中的build.gradle中。

我现在可以再次运行我的项目,没有错误。

 类似资料:
  • 我正试图在我的离子应用程序中实现推送通知。为此,我想使用原生插件推: https://ionicframework.com/docs/native/push/ 在安装这个插件之前,我可以在我的Android设备上使用以下命令启动我的应用程序: 到build.gradle文件,它修复了第一个提到的错误,但给了我另一个错误(推插件): 我还尝试添加了这个: 添加到project.properties文

  • 我正在尝试为我的移动应用程序安装一个共享按钮插件,但当我键入“npm I--save dev Share Button”时,我会收到一长串GYP错误代码。我只是一名学生,对编程非常陌生,所以如果我的问题的答案看起来很简单,我很抱歉。我试着更新Nodejs、GYP和NPM,但到目前为止没有成功。以下是我遇到的错误: C:\Users\Marketing1\Documents\App\Soundboa

  • 我正在尝试使用NPM的gulp-git模块推送到我的远程存储库。add&commit部分运行良好,但在尝试执行远程推送时遇到流错误。 TypeError:undefined不是write(C:\src\git\ig\node_module\gulp-git\node_module\through2\node_module\readable-stream\lib_stream_readable.js

  • 在android中,我使用pthread_create来创建一个本地线程,然后在回调过程中,调用FindClass来获取一个Java类。但是它不起作用。我从android jni提示中获得提示,我从Android JNI中的任何线程中找到了FindClass中的解决方案 我为我的项目修改它,如下[编辑] 程序在env退出- 如果我删除

  • 我已经构建了一个Ionic应用程序,希望将新版本上传到Google Play开发控制台中的Alpha曲目。我在配置中更改了版本。xml,如配置上的Cordova文档所述。xml 运行gulp build android时,它确实会更新AndroidManifest中的versionCode和versionName。xml,您可以在下面的代码段中看到。 在签名并运行zipalign之后,我尝试将AP

  • 问题内容: TL; DR: 将任何非内置函数添加到Array.prototype AND Function.prototype将导致IE8本机JSON解析器在解析包含数组的任何JSON时发生堆栈溢出,但仅当您还传递了reviver函数时放入JSON.parse()。 最初这是一个问题,但我回答了我自己的原始问题,所以现在我要问:有人能想到此IE8错误的解决方法,该方法不涉及消除所有修改Array.