【问题标题】:Error running "ionic cordova build android' after installin firebase package.Execution failed for task ':app:compileDebugJavaWithJavac'安装firebase包后运行“ionic cordova build android”时出错。任务':app:compileDebugJavaWithJavac'的执行失败
【发布时间】:2019-07-06 22:33:30
【问题描述】:

在我从 ionic docs 安装 firebase 包并为云消息配置配置 firebase 后,当我运行“ionic cordova build android”时出现以下错误:

D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:610: error: method getByteArray in class FirebaseRemoteConfig cannot be applied to given types;
                        : FirebaseRemoteConfig.getInstance().getByteArray(key, namespace);
                                                            ^
  required: String
  found: String,String
  reason: actual and formal argument lists differ in length
D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:629: error: method getValue in class FirebaseRemoteConfig cannot be applied to given types;
                        : FirebaseRemoteConfig.getInstance().getValue(key, namespace);
                                                            ^
  required: String
  found: String,String
  reason: actual and formal argument lists differ in length
D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:686: error: no suitable method found for setDefaults(Map<String,Object>,String)
                        FirebaseRemoteConfig.getInstance().setDefaults(defaultsToMap(defaults), namespace);
                                                          ^
    method FirebaseRemoteConfig.setDefaults(Map<String,Object>) is not applicable
      (actual and formal argument lists differ in length)
    method FirebaseRemoteConfig.setDefaults(int) is not applicable
      (actual and formal argument lists differ in length)
D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:885: error: cannot find symbol
                        myTrace.incrementCounter(counterNamed);
                               ^
  symbol:   method incrementCounter(String)
  location: variable myTrace of type Trace
D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginMessagingService.java:144: error: constructor Builder in class Builder cannot be applied to given types;
            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);
                                                             ^
  required: Context
  found: FirebasePluginMessagingService,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: D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\file\AssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app: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. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 12s
> Task :app:compileDebugJavaWithJavac FAILED
33 actionable tasks: 5 executed, 28 up-to-date
D:\Projects\Evento\Evento\platforms\android\gradlew: Command failed with exit code 1 Error output:
D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:610: error: method getByteArray in class FirebaseRemoteConfig cannot be applied to given types;
                        : FirebaseRemoteConfig.getInstance().getByteArray(key, namespace);
                                                            ^
  required: String
  found: String,String
  reason: actual and formal argument lists differ in length
D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:629: error: method getValue in class FirebaseRemoteConfig cannot be applied to given types;
                        : FirebaseRemoteConfig.getInstance().getValue(key, namespace);
                                                            ^
  required: String
  found: String,String
  reason: actual and formal argument lists differ in length
D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:686: error: no suitable method found for setDefaults(Map<String,Object>,String)
                        FirebaseRemoteConfig.getInstance().setDefaults(defaultsToMap(defaults), namespace);
                                                          ^
    method FirebaseRemoteConfig.setDefaults(Map<String,Object>) is not applicable
      (actual and formal argument lists differ in length)
    method FirebaseRemoteConfig.setDefaults(int) is not applicable
      (actual and formal argument lists differ in length)
D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:885: error: cannot find symbol
                        myTrace.incrementCounter(counterNamed);
                               ^
  symbol:   method incrementCounter(String)
  location: variable myTrace of type Trace
D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginMessagingService.java:144: error: constructor Builder in class Builder cannot be applied to given types;
            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);
                                                             ^
  required: Context
  found: FirebasePluginMessagingService,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: D:\Projects\Evento\Evento\platforms\android\app\src\main\java\org\apache\cordova\file\AssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app: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. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

我已尝试删除插件并重新安装。

我已将 cordova、ionic 和 firebase 更新到最新版本。

另外,我已经从 ionic docs 中删除了 firebase 并安装,并删除了 onTokenRefresh 并替换为 onTokenNew 到子类 FirebaseMessaingSerice,并安全删除了 FirebasePluginServiceId。

我已经删除了平台并重新安装了所有插件。

我已经更新了google-services.json,但是没有效果。

我仍然收到这些错误并且无法在 android 中运行。

我的猜测是这里有一些版本不兼容,但找不到。

这是我的版本和配置:

Ionic:

   Ionic CLI                     : 5.2.1 (C:\Users\arbi_\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.4.0
   @angular-devkit/build-angular : 0.13.9
   @angular-devkit/schematics    : 7.3.9
   @angular/cli                  : 7.3.9
   @ionic/angular-toolkit        : 1.5.1

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.0.1, (and 13 other plugins)

Utility:

   cordova-res : not installed
   native-run  : 0.2.5

System:

   NodeJS : v10.15.3 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 10

构建.Gradle

/* Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
*/

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' } // Fabrics Maven repository from cordova-plugin-firebase
    }

    dependencies {
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        classpath 'com.android.tools.build:gradle:3.3.0'

        classpath 'com.google.gms:google-services:4.2.0' // google-services dependency from cordova-plugin-firebase

        classpath 'io.fabric.tools:gradle:1.25.4' // fabric dependency from cordova-plugin-firebase
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        google() // Google's Maven repository from cordova-plugin-firebase
    }

    //This replaces project.properties w.r.t. build settings
    project.ext {
      defaultBuildToolsVersion="28.0.3" //String
      defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
      defaultTargetSdkVersion=28 //Integer - We ALWAYS target the latest by default
      defaultCompileSdkVersion=28 //Integer - We ALWAYS compile with the latest by default
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

项目属性

target=android-28
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.system.library.1=com.squareup.okhttp3:okhttp-urlconnection:3.10.0
cordova.system.library.2=com.android.support:support-v4:24.1.1+
cordova.system.library.3=com.android.support:support-annotations:27.+
cordova.system.library.4=com.squareup.okhttp3:okhttp:3.12.0
cordova.gradle.include.1=cordova-plugin-firebase/evento-build.gradle
cordova.system.library.5=com.google.android.gms:play-services-tagmanager:+
cordova.system.library.6=com.google.firebase:firebase-core:17.0.0
cordova.system.library.7=com.google.firebase:firebase-messaging:19.0.1
cordova.system.library.8=com.google.firebase:firebase-config:18.0.0
cordova.system.library.9=com.google.firebase:firebase-perf:18.0.1

【问题讨论】:

  • 第一个问题是您从哪里获得集成 Firebase 的教程,也许它已经过时了,因为我在日志中注意到了这一点:注意:某些输入文件使用或覆盖了已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息。
  • 我在 udemy 买的,但是集成阶段是从 ionic 文档中观看的,并且软件包的安装是直接从 ionic 文档中获取的
  • 你试过安装AndroidX插件吗?在这里查看我的答案stackoverflow.com/a/56694042/1928380
  • 感谢您的回复,我会试试看是否有效。谢谢。
  • 它解决了我的问题。非常感谢。你为我节省了很多时间!

标签: firebase ionic-framework firebase-cloud-messaging ionic4


【解决方案1】:

为了让其他人可以像我一样受益*,Jeremy Belolo 的回答在这里解决了提出这个问题的人(无论如何根据他的陈述 :-))和我的问题:https://stackoverflow.com/a/56694042/1928380

我复制重要部分:只需添加这些插件,即可解决问题。

ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter

* 这不是我的答案,我也不要求任何功劳。但是,我已经好几天没有打开这个项目了,因为在搜索结果中它显示了 0 个答案,而实际上隐藏在 cmets 中的答案也解决了我的问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    相关资源
    最近更新 更多