microsoft / EmbeddedSocial-Android-SDK

SDK for interacting with the Microsoft Embedded Social service from inside your Android app
MIT License
9 stars 14 forks source link

Remove Firebase config from app-level google-services.json #95

Open barbeau opened 6 years ago

barbeau commented 6 years ago

Summary:

Currently, OneBusAway Android has a file /onebusaway-android/google-services.json that the ES SDK uses, presumably for some type of Firebase service.

I'm in the process of adding another Firebase service to OBA Android. As part of that I'd need to add a google-services.json in the /onebusaway-android directory for this Firebase service (Cloud Firestore), but I can't because the one for the ES SDK already exists.

From this Firebase link, it looks like you can configure multiple Firebase projects within the same app - https://firebase.google.com/docs/configure/#use_multiple_projects_in_your_application

I'm proposing that the ES SDK /google-services.json be removed from the OBA app and replaced by passing credentials to the ES SDK via the /onebusaway-android/src/main/res/raw/embedded_social_config file, and then the ES SDK can manually init Firebase within the SDK using these credentials. From the above link, the manual init would look something like:

// Manually configure Firebase Options
FirebaseOptions options = new FirebaseOptions.Builder()
        .setApplicationId("1:27992087142:android:ce3b6448250083d1") // Required for Analytics.
        .setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") // Required for Auth.
        .setDatabaseUrl("https://myproject.firebaseio.com") // Required for RTDB.
        .build(); 

// Initialize with secondary app.
FirebaseApp.initializeApp(this /* Context */, options, "secondary");

// Retrieve secondary app.
FirebaseApp secondary = FirebaseApp.getInstance("secondary");
// Get the database for the other app.
FirebaseDatabase secondaryDatabase = FirebaseDatabase.getInstance(secondary);

This design makes sense to me for three reasons:

  1. It puts all ES SDK config in the same file (embedded_social_config)
  2. It seems a little strange to have the default google-services.json in an app belong to an SDK
  3. If an app wants to adopt the ES SDK, and they already use Firebase, with the current ES SDK design they'd need to move their default Firebase config to a secondary manual config. It's less friction to adopt if the dev doesn't need to change their Firebase config at all to adopt ES SDK.

Steps to reproduce:

Try to configure the OneBusAway Android app with a new Firebase project:

  1. Go to Firebase web console
  2. Create new project
  3. When a google-services.json file is generated by the Firebase console, follow the instructions to add it to the OBA Android project at /onebusaway-android/google-services.json

Expected behavior:

ES SDK shouldn't block me from adding a Firebase project to the OBA Android app - ideally there shouldn't be an existing /onebusaway-android/google-services.json file that's not owned by the OBA app.

Observed behavior:

/onebusaway-android/google-services.json already exists in OBA Android from the ES SDK configuration.

A workaround would be to set up a secondary OBA Firebase project with a manual configuration for the OBA Android app as discussed at: https://firebase.google.com/docs/configure/#use_multiple_projects_in_your_application

Device, Android, and Embedded Social SDK version:

    // Embedded Social SDK version
    implementation('com.acrowntest.test:sdk:0.7.1:release@aar') {
        transitive = true;
    }

App = OBA Android with master branch at https://github.com/OneBusAway/onebusaway-android/commit/8eeda8586a394d293b3ae8bb99ef5c6df7a93176

acrown-msft commented 6 years ago

Hi Sean,

The google-services.json that is present in the OneBusAway project is just a placeholder so that the ES components can build (GCM and now FCM require that a json config is present). The intent, however, is to have the hosting app replace the config provided by the SDK. Removing the existing json config should not break any existing functionality in OBA.

Push will only work for the application once you follow the steps to configure firebase messaging from the Firebase console and provide us with your FCM key so we can register it on the server side under your app key.

Perhaps we should comment inside the config file making it clear that the existing google-services.json is a placeholder. What do you think?

iutinvg commented 2 years ago

I've faced the same problem. The only feature I needed was Firestore. It was OK for me to initialise the store manually (the same approach as above). The requirement for google-services.json was annoying, so I removed com.google.gms.google-services from plugins. The Firestore still working, but the requirement for google-services.json gone. So, please use this "solution" if you want. However, I cannot know what other Firebase parts can be negatively affected by this trick.