在ionic3中找不到符号导入com.google.firebase.iid.FirebaseInstanceIdService错误

the*_*der 6 firebase ionic-framework ionic3 angular

我不知道为什么每次尝试创建应用程序构建时都会遇到此错误。我尝试了许多解决方案,但无法解决此问题。我不知道是否有任何插件引起问题或我的问题代码,firebase或firebase连接。我已删除节点模块并运行npm install并删除并重新添加了android平台,但仍然出现此错误。

import com.google.firebase.iid.FirebaseInstanceIdService;
                              ^
  symbol:   class FirebaseInstanceIdService
  location: package com.google.firebase.iid
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginInstanceIDService.java:9: error: cannot find symbol
public class FirebasePluginInstanceIDService extends FirebaseInstanceIdService {
                                                     ^
  symbol: class FirebaseInstanceIdService
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:508: 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
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:525: 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
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:579: 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)
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginInstanceIDService.java:18: error: method does not override or implement a method from a supertype
    @Override
    ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\io\card\cordova\sdk\CardIOCordovaPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors
:app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
27 actionable tasks: 1 executed, 26 up-to-date
> 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.

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

BUILD FAILED in 54s
cmd: Command failed with exit code 1 Error output:
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginInstanceIDService.java:6: error: cannot find symbol
import com.google.firebase.iid.FirebaseInstanceIdService;
                              ^
  symbol:   class FirebaseInstanceIdService
  location: package com.google.firebase.iid
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginInstanceIDService.java:9: error: cannot find symbol
public class FirebasePluginInstanceIDService extends FirebaseInstanceIdService {
                                                     ^
  symbol: class FirebaseInstanceIdService
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:508: 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
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:525: 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
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:579: 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)
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginInstanceIDService.java:18: error: method does not override or implement a method from a supertype
    @Override
    ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\io\card\cordova\sdk\CardIOCordovaPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 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.

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

BUILD FAILED in 54s
[ERROR] An error occurred while running subprocess cordova.

        cordova build android exited with exit code 1.
Run Code Online (Sandbox Code Playgroud)

小智 10

这是由于Firebase在4月5日进行了更新。在这里https://firebase.google.com/support/release-notes/android#update_-_april_02_2019 96,我找到了上一个工作版本,并project.properties相应地进行了如下调整:

cordova.system.library.4=com.google.firebase:firebase-core:16.0.8

cordova.system.library.5=com.google.firebase:firebase-messaging:17.5.0

cordova.system.library.6=com.google.firebase:firebase-config:16.4.1

cordova.system.library.7=com.google.firebase:firebase-perf:16.2.4
Run Code Online (Sandbox Code Playgroud)

在这里,所有依赖项都锁定为特定版本(更新-2019年4月2日),而不是+,这将为您提供最新版本,从而中断了构建过程。

现在我可以成功构建了!希望能帮助到你!

project.properties可以在platform / android / project.properties上找到


Kai*_*han 10

是的,它已贬值。修复非常简单,只需移动代码即可。

onTokenRefresh()你的FirebaseInstanceIdService子类

onNewToken()您的FirebaseMessagingService子类别中

折旧信息:https : //firebase.google.com/support/release-notes/android#update_-_april_02_2019

我建议您使用旧版本的Firebase进行此小的代码更改。在您使用时,也可能迁移到AndroidX [ https://developer.android.com/jetpack/androidx/migrate]是一个好主意。


Mah*_*our 6

如果在React Native框架中出现这个问题,有两种解决方案:

解决方案1 (推荐)

在以下文件中更改 firebase 版本: android\app\build.gradle

...
//implementation 'com.google.firebase:firebase-core'
//implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
...
Run Code Online (Sandbox Code Playgroud)

并在android\gradle.properties文件底部添加

firebaseCoreVersion=16.0.8
firebaseMessagingVersion=17.6.0
Run Code Online (Sandbox Code Playgroud)

解决方案2:

\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java如下完成更改文件。

package com.evollu.react.fcm;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
import com.google.firebase.iid.FirebaseInstanceId;
//import com.google.firebase.iid.FirebaseInstanceIdService; //Commented FirebaseInstanceIdService
import com.google.firebase.messaging.FirebaseMessagingService;  //ADD FirebaseMessagingService

public class InstanceIdService extends FirebaseMessagingService {

    private static final String TAG = "InstanceIdService";

    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. This call is initiated by the
     * InstanceID provider.
     */
    // [START refresh_token]
    @Override
    public void onNewToken(String token) { //Added onNewToken method
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        // Broadcast refreshed token
        Intent i = new Intent("com.evollu.react.fcm.FCMRefreshToken");
        Bundle bundle = new Bundle();
        bundle.putString("token", refreshedToken);
        i.putExtras(bundle);

        final Intent message = i;

        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            public void run() {
                // Construct and load our normal React JS code bundle
                ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
                ReactContext context = mReactInstanceManager.getCurrentReactContext();
                // If it's constructed, send a notification
                if (context != null) {
                    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                } else {
                    // Otherwise wait for construction, then send the notification
                    mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
                        public void onReactContextInitialized(ReactContext context) {
                            LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                        }
                    });
                    if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                        // Construct it in the background
                        mReactInstanceManager.createReactContextInBackground();
                    }
                }
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)


Jua*_*cio 5

经过服务器测试后,我的解决方案是通过cordova-plugin-firebasex更改cordova-plugin-firebase。 https://github.com/dpa99c/cordova-plugin-firebase#migrating-from-cordova-plugin-firebase

rm -Rf platforms/android
cordova plugin rm cordova-plugin-firebase
rm -Rf plugins/ node_modules/
npm install
cordova plugin add cordova-plugin-firebasex
cordova platform add android
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助。

https://github.com/dpa99c/cordova-plugin-firebase#androidx

此插件已迁移为使用AndroidX(Jetpack),后者是Android支持库的后继版本。这是通过在cordova-plugin-androidx上添加依赖项来实现的,该依赖项可在Cordova项目的Android平台中启用AndroidX。

这是因为2019年6月17日的Firebase和Play Services库的主要版本已迁移到AndroidX。

因此,如果您的项目包含依赖于旧版Android支持库的任何插件,则应将cordova-plugin-androidx-adapter添加到您的项目中。此插件会将所有插件代码从Android支持库动态迁移到AndroidX等效版本。


小智 5

出现此问题是由于主要 Firebase 版本支持 AndroidX

解决方案:

  1. 删除 android 平台(我遵循了这一步。但应该有我可能不知道的解决方法)- cordova platform rm android

  2. 删除旧的 firebase 插件 - cordova plugin rm cordova-plugin-firebase

  3. 添加新的 Firebase 插件 - cordova plugin add cordova-plugin-firebasex

  4. 再次添加平台 - cordova platform add android

现在您的构建将成功。


ola*_*ide 1

好的。这是一个梯度错误。这是由于 4 月份的 firebase 更新FirebaseInstanceIdService已被弃用,很多人都面临这个问题。

查看 FirebaseInstanceIdService 的参考文档

该类已被弃用。

支持重写 FirebaseMessagingService 中的 onNewToken。一旦实施,就可以安全地删除该服务。