cannot find symbol import com.google.firebase.iid.FirebaseInstanceIdService error in ionic3

前端 未结 6 1755
礼貌的吻别
礼貌的吻别 2021-01-01 17:26

I Have no idea why I am getting this error whenever I try to create my app\'s build.I have tried many solutions but I was unable to solve this.i don\'t know if any plugins

相关标签:
6条回答
  • 2021-01-01 17:59

    This is due to the Firebase updates on April 05. Here https://firebase.google.com/support/release-notes/android#update_-_april_02_2019 96, I found the last working versions and adjusted my project.properties accordingly like so:

    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
    

    Here all dependencies are locked to the specific version (Update - April 02, 2019) instead of +, which would get you the latest version thus breaking the build process.

    Now I can build successfully! Hope it helps!

    project.properties can be found on platforms/android/project.properties

    0 讨论(0)
  • 2021-01-01 17:59

    After serveral tests, my solution was change cordova-plugin-firebase by cordova-plugin-firebasex. 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
    

    I hope this helps.

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

    This plugin has been migrated to use AndroidX (Jetpack) which is the successor to the Android Support Library. This is implemented by adding a dependency on cordova-plugin-androidx which enables AndroidX in the Android platform of a Cordova project.

    This is because the major release of the Firebase and Play Services libraries on 17 June 2019 were migrated to AndroidX.

    Therefore if your project includes any plugins which are dependent on the legacy Android Support Library, you should add cordova-plugin-androidx-adapter to your project. This plugin will dynamically migrate any plugin code from the Android Support Library to AndroidX equivalents.

    0 讨论(0)
  • 2021-01-01 18:01

    Ok. This is a gradle error. This is due to the firebase updates in April, FirebaseInstanceIdService is deprecated, and many people are facing the problem.

    Check the reference documentation for FirebaseInstanceIdService

    This class was deprecated.

    In favour of overriding onNewToken in FirebaseMessagingService. Once that has been implemented, this service can be safely removed.

    0 讨论(0)
  • 2021-01-01 18:12

    If this problem happens in React Native frameworks.There are two solutions:

    solution 1 (recommended):

    change firebase version in below files: 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'
    ...
    

    And in android\gradle.properties at the bottom of file add

    firebaseCoreVersion=16.0.8
    firebaseMessagingVersion=17.6.0
    

    solution 2:

    Change \node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java file as complete below.

    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();
                        }
                    }
                }
            });
        }
    }
    
    0 讨论(0)
  • 2021-01-01 18:14

    This issue occurs due to major firebase release to support AndroidX

    Solution:

    1. Remove android platform(I followed this step. but there should be workaround which I might not know) - cordova platform rm android

    2. Remove old firebase plugin - cordova plugin rm cordova-plugin-firebase

    3. Add new firebase plugin - cordova plugin add cordova-plugin-firebasex

    4. Again add platform - cordova platform add android

    Now your build will succeed.

    0 讨论(0)
  • 2021-01-01 18:16

    Yes, it's depreciated. The fix it quite simple, just move the code...

    From onTokenRefresh() in your FirebaseInstanceIdService subclass

    To onNewToken() in your FirebaseMessagingService subclass

    Info on depreciation: https://firebase.google.com/support/release-notes/android#update_-_april_02_2019

    I would recommend making this small code change over using old versions of firebase. Probably a good idea to also migrate to AndroidX [https://developer.android.com/jetpack/androidx/migrate] while you're at it.

    0 讨论(0)
提交回复
热议问题