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

Ionic的原生“推”插件导致错误

蓬琦
2023-03-14

我正试图在我的离子应用程序中实现推送通知。为此,我想使用原生插件推:

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.
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.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.

我还尝试添加了这个:

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.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.

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
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/)。在安装这个插件后,我得到了与OP中提到的相同的错误。谷歌之后(?)我发现了这个话题:

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

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

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

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

 类似资料:
  • 我正在尝试在我的ionic应用程序中实现推送通知。为此,我想使用本机插件Push: https://ionicframework.com/docs/native/push/ 在安装这个插件之前,我可以在我的Android设备上启动我的应用程序,使用: 我不能再运行我的设备上的应用程序,因为构建失败,因为一堆错误。 这个错误有一个建议:将'tools:replace=“android:value”‘

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

  • 我试图构建一些先前存在的Java代码,其中包括谷歌协议缓冲区在其传输层。我正在使用的插件在pom文件中包含了以下元素: 我已经安装了protobuf 2.4.1版,protoc可以通过命令行获得,我在pom中包含的protobuf-java版本也是来自com.google.protobuf组的2.4.1版本。正如我前面提到的,我必须使用这个技术堆栈,因为我正在使用现有的代码库,但是尽管有一个新版本

  • 我有麻烦-使用ionic创建一个android构建。它最初运行良好。我尝试将android目标平台更改为19-这是4.4.2 kitkat。 这是错误消息-显然cordova文件插件有问题。当我将平台sdk目标更改为19时。 任何帮助将不胜感激。 /myapp/platforms/android/src/org/apache/cordova/file/LocalFilesystem.java:41

  • 我正在按照http://spring.io/guides/gs/consource-web-service/#scratch中提供的分步说明学习如何使用Gradle和Spring-WS使用SOAP web服务。我已经创建了上面URL中指定的文件夹结构(即:c:/src/main/java/hello)并将build.gradle、weatherclient.java、weatherconfigur

  • 一个简单的网页请求总是报错:favicon.ico文件不存在。 我在apache的根目录中放置了一个图片文件 favicon.ico,故障消失。 我找了一些资料: 因为现在的浏览器都或第三方程序都会默认请求favicon.ico图标,如果没有就会报404错误。 请问,为何浏览器或第三方要请求这个东东?不请求不行吗?