How can I use Firebase cloud message in an eclipse project?

18,483

Solution 1

The new Firebase (9xx) libraries can be found in the Google Repository. You can install this with the Eclipse Android SDK Manager. Open the SDK manager and scroll down until you find Google Repository and install the package.

The package will be installed in /extras/google/m2repository and you will find the Firebase files further down at /com/google/android/firebase.

You can rename the .aar files to .zip and extract the jar file, rename these from classes.jar and copy them to the project libs folder displayed in Eclipse (or copy outside Eclipse and then follow the instructions to import a project into Eclipse.)

Solution 2

There is a move towards Android Studio with Gradle. The Eclipse solution to Firebase CM is not forthcoming. My feeling is we will all have to move to AS with Gradle soon. There are good books on it and very simple instructions on Google dev sites. We might as well start learning the new IDE and migrate.

Solution 3

You can add this on your Android Manifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<receiver
            android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="YOUR PACKAGE NAME" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
            android:exported="false" />

And then you can get the token and try to send Message on.

Dont forget also to build FirebaseApps on your code (in my case on my MainActivity)

FirebaseOptions options = new FirebaseOptions.Builder()
    .setApiKey("YOUR FIREBASE API KEY")
    .setApplicationId("YOUR FIREBASE APP ID")
    .setGcmSenderId("YOUR FIREBASE SENDER ID")
    .build();

FirebaseApp myApp = FirebaseApp.initializeApp(getApplicationContext(), options);
        token = FirebaseInstanceId.getInstance(myApp).getToken();

Hope it will get what you looking for on Eclipse.

Solution 4

Have a look at the resources below. In short, it's about including the Firebase libraries into your project (see the GitHub project and the two videos at the end) and manually performing the steps that the plugin does for you in Android Studio / Gradle.

Solution 5

Old code is working no need to change code in firebase only change is in server code you have to use Web API Key from firebase project and Sender ID as per old code style. and you have to replace gcm url in web script - https://fcm.googleapis.com/fcm/send

No Requirement of firebase library...

Share:
18,483
b1065579
Author by

b1065579

Updated on June 30, 2022

Comments

  • b1065579
    b1065579 almost 2 years

    I have a project in eclipse. I need include firebase library. If I was using Android Studio the steps would simply be:

    enter image description here

    And its all, all library include.

    But I cant understand how include firebase cloud message to eclipse. I cant find how include it to eclipse.

  • Homombi
    Homombi over 7 years
    The main problem is that on some machines Gradle takes too long to build even in offline mode, that's why personally i don't use android studio anymore, it's almost the same, but testing the app takes way too much longer in AS than in Eclipse, Eclipse still the fastest in my opinion
  • Eames
    Eames over 7 years
    Extract every single .jar from the .aar files?
  • Achin
    Achin over 7 years
    I have used in eclipse this but i am getting FirebaseMessagingService cannot be resolved to a type, please anyone guide me ?
  • Zen
    Zen over 7 years
    Yep. Did you figure out how to import firebase on Eclipse?
  • Zen
    Zen over 7 years
    Extracting the aar files just gives me a Manifest & R.txt file. Which is the one that gives the jar file?
  • usajnf
    usajnf over 7 years
    Same instructions as in the answer above this one. The firebase-iid and firebase-messaging are needed for the basic client implementation. When you open the archive you will see classes.jar which will have to be renamed before importing to Eclipse or they will overwrite each other!
  • usajnf
    usajnf over 7 years
    I believe this is correct at the moment. The GCM client classes will still work but they are deprecated so are not maintained. FCM client classes will eventually have to be swapped into your client code.
  • usajnf
    usajnf over 7 years
    @summers some of the .aars have only resources. But the ones you need for messaging have a classes.jar file in them containing the source code for the various methods of FCM.
  • usajnf
    usajnf over 7 years
    @Eames The firebase-iid and firebase-messaging are needed for the basic client implementation.
  • Manoj Behera
    Manoj Behera over 7 years
    I have followed all above instructions and My app is working with out error..But I am not getting push message...I am sending from firebase dashboard and it is showing completed there but not receiving any push message...onTokenRefresh method never called and onMessageReceived also never called...My manifest file is ok I have not given my services outside the application root...and also given android:enabled="true" android:exported="true"...
  • Manoj Behera
    Manoj Behera over 7 years
    I have followed all above instructions and My app is working with out error..But I am not getting push message...I am sending from firebase dashboard and it is showing completed there but not receiving any push message...onTokenRefresh method never called and onMessageReceived also never called...My manifest file is ok I have not given my services outside the application root...and also given android:enabled="true" android:exported="true"
  • Roman
    Roman over 7 years
    I included the libraries common, iid and messaging in my project, create the service classes which extend from FirebaseInstanceIdService and FirebaseMessagingService and added them in my manifest. I can create an Instance of my Services, which means the super classes of my Services should be available. But now I have the problem, that I get a ClassNotFoundException when I call this method: FirebaseInstanceId.getInstance().getToken() Does anyone know what the problem could be?
  • Roman
    Roman over 7 years
    Thank you for this info. When I call the FirebaseOptions.Builder(), I get a NoClassDefFoundError with this Info: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzac" on path: DexPathList Do you know what this error could be?
  • Yuw
    Yuw over 7 years
    @Roman, have you try to put all jar u need on libs and google play libs on your dependency?
  • Roman
    Roman over 7 years
    I've already included the firebase common, iid and messaging jars. But I don't know which google play libs I need. Tried base and iid now, but I still get the same error.
  • Yuw
    Yuw over 7 years
    @Roman, can u show your android manifest and your package structure?
  • R.R.M
    R.R.M about 7 years
    I m facing the same problem. I have added all 3 classes.jar files of iid, messaging and common firebase. It is not giving error. But when i run the code it is giving ClassNotFoundException. Someone please help me with this.