简体   繁体   English

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

[英]Native “Push” plugin for Ionic causes errors

I am trying to implement Push notifications in my ionic app. 我正在尝试在离子应用程序中实现推送通知。 For this I want to use the native plugin push: 为此,我想使用本机插件推送:

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

Before installing this plugin I can just start my app on my Android device using: 在安装此插件之前,我可以使用以下命令在Android设备上启动我的应用程序:

ionic cordova run android

The app starts up, and no errors occur. 该应用程序启动,没有错误发生。 But after installing the Cordova/PhoneGap plugin like this: 但是像这样安装Cordova / PhoneGap插件后:

ionic cordova plugin add phonegap-plugin-push

And this: 和这个:

npm install --save @ionic-native/push

I can no longer run the app on my device because the build failes because of a bunch of errors. 我无法再在设备上运行该应用程序,因为由于一堆错误导致构建失败。

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.

This error has a suggestion: adding 'tools:replace="android:value"' to the eleemet in the AndroidManifest. 该错误提示:在AndroidManifest中将'tools:replace =“ android:value”'添加到eleemet中。 I did that, after building again I get this error: 我这样做了,在再次构建之后,我得到了这个错误:

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

Another "solution" I found was to add this code piece: 我发现的另一个“解决方案”是添加以下代码段:

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'
            }
        }
    }
}

To the build.gradle file which fixes the first mentioned error but gives me another error (Push Plugin): build.gradle文件,该文件修复了第一个提到的错误,但又给了我另一个错误(推送插件):

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.

I also tried to add this: 我也尝试添加以下内容:

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

to the project.properties file, but yet another error: project.properties文件,但又出现另一个错误:

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.

So I also tried to use 11.0.1 (instead of 11.0.4 which are both installed): 所以我也尝试使用11.0.1(而不是同时安装的11.0.4):

在此处输入图片说明

But it gives me this error: 但这给了我这个错误:

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.

At this point I don't really have a clue to fix this, when I remove the plugin like this: 在这一点上,当我删除这样的插件时,我还真的没有解决此问题的线索:

ionic cordova plugin remove phonegap-plugin-push

I can just start the app again with no problems or errors. 我可以再次启动应用程序而不会出现任何问题或错误。

How can I make this plugin work? 如何使该插件正常工作?

Thanks in advance. 提前致谢。

EDIT 编辑

So I created a new Ionic app with a boilerplate like this: 因此,我使用如下样板创建了一个新的Ionic应用程序:

ionic start myApp tabs

And I installed the phonegap plugin push like this: 我安装了phonegap插件推送,如下所示:

ionic cordova plugin add phonegap-plugin-push

And when using this: 而当使用这个:

ionic cordova run android

The app just starts with no errors, so it is my other project that is causing these issues. 该应用程序启动时没有任何错误,所以正是我的其他项目导致了这些问题。 I used ionic info on the blank app which shows me this: 我在空白应用程序上使用了离子信息,该信息向我显示了这一点:

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

So I did the same for my own app and it was showing some of the fields being outdated (or at least older than what the boilerplate had installed, also cordova) and I started updating the fields like this: 因此,我对自己的应用程序执行了相同的操作,结果显示某些字段已过时(或至少比样板安装的字段还旧,也就是cordova),并且我开始像这样更新字段:

npm install -g cordova 

And

npm install -g ionic

And

npm install @ionic/app-scripts@latest

But after running it again, I get one of the previous errors: 但是在再次运行它之后,出现了先前的错误之一:

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.

At this point, wouldn't it be better to just re-create a new project, install all plugins that I need, test if they work and then add my logic/classes to it? 在这一点上,重新创建一个新项目,安装我需要的所有插件,测试它们是否工作,然后向其中添加我的逻辑/类,不是更好吗?

Thanks 谢谢

EDIT 编辑

So I have "figured out" what is cousing the problems, I don't know why this happends or how to fix it yet. 因此,我已经“弄清”了解决问题的原因,但我不知道为什么会这样或如何解决。 I am using 2 plugins that work fine alone but both installed, cause errors. 我正在使用2个插件,它们可以单独正常工作,但同时安装都导致错误。 These plugins are: 这些插件是:

Ok, so I have managed to solve my problem. 好的,所以我设法解决了我的问题。 This is what I did: 这是我所做的:

I created a blank Ionic project ( ionic start blank ) to test if the plugin would work in a newly created project. 我创建了一个空白的Ionic项目(ionic start blank),以测试该插件是否可以在新创建的项目中工作。 It did. 它做了。 After that I installed all other plugins one by one to see if it still worked. 之后,我一个接一个地安装了所有其他插件,以查看它是否仍然有效。 At some point I came across the file-path plugin ( https://ionicframework.com/docs/native/file-path/ ). 在某个时候,我遇到了文件路径插件( https://ionicframework.com/docs/native/file-path/ )。 After installing this plugin I got the same errors as mentioned in the OP. 安装此插件后,我得到了与OP中提到的相同的错误。 After Googling(?) a bit I found this topic: 在Googling(?)之后,我发现了这个主题:

android getting Manifest merger failed error after update to new version of gradle 更新到新版本的gradle后,Android出现Manifest合并失败错误

One of the solutions was adding this piece of code to the build.gradle file: 解决方案之一是将这段代码添加到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'
            }
        }
    }
}

Note that I had already tried a similair solution but with a different version number ( 25.3.1 ). 请注意,我已经尝试了similair解决方案,但是使用了不同的版本号(25.3.1)。 The error mentioned 2 versions, I picked the most recent one ( 26.1.0 ) in the solution, but I did not initially. 错误提到了2个版本,我选择了解决方案中的最新版本(26.1.0),但最初没有这样做。

After trying it out on the blank project I tried it on my existing project. 在空白项目上尝试之后,我在现有项目上尝试了它。 Just to be sure I removed the platform ( ionic cordova rm platform android ) and added it again ( ionic cordova add platform android ). 只是为了确保我删除了平台(ionic cordova rm platform android)并再次添加了该平台(ionic cordova rm platform android)。 Also note that I added the above piece to the build.gradle found in platforms>android>app and not in the build.gradle found inside platforms>android . 另外请注意,我说上面这段在平台>安卓>应用程序 ,而不是在内部平台>机器人发现的build.gradle发现的build.gradle。

I can now run my project again with no errors. 现在,我可以再次正常运行我的项目了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM