Skip to content

Use Firebase Crashlytics with FirebaseOptions #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fm-eb opened this issue Jan 11, 2019 · 9 comments
Closed

Use Firebase Crashlytics with FirebaseOptions #187

fm-eb opened this issue Jan 11, 2019 · 9 comments
Labels

Comments

@fm-eb
Copy link

fm-eb commented Jan 11, 2019

What feature would you like to see?

Allow Crashlytics to be used with several projects.
Related to #66

How would you use it?

In our app we have several projects. Each project represents one development environment (dev, staging, prod). Right now it seems to be impossible to setup Firebase so that it does not use the google-services.json, but instead uses a dynamically generated FirebaseApp via FirebaseOptions.

A little code example:

public enum ServerTier {
    prod(new FirebaseOptions.Builder()
            .setProjectId("xxx1")
            .setApplicationId("yyy1")
            .setApiKey("zzz1")
            .setStorageBucket("aaa1")),
			
    staging(new FirebaseOptions.Builder()
            .setProjectId("xxx2")
            .setApplicationId("yyy2")
            .setApiKey("zzz2")
            .setStorageBucket("aaa2")),
			
    development(new FirebaseOptions.Builder()
            .setProjectId("xxx3")
            .setApplicationId("yyy3")
            .setApiKey("zzz3")
            .setStorageBucket("aaa2"));

    @NonNull
    public final FirebaseOptions firebaseOptions;

    ServerTier(@NonNull FirebaseOptions.Builder optionsBuilder) {
        this.firebaseOptions = optionsBuilder.build();
    }
}


private FirebaseApp getFirebaseApp(@NonNull CoreConfiguration configuration) {
    CoreConfiguration.ServerTier serverTier = configuration.getServerTier();
    String firebaseAppInstanceName = serverTier.name();
    return FirebaseApp.initializeApp(context, serverTier.firebaseOptions, firebaseAppInstanceName);
}
@fm-eb
Copy link
Author

fm-eb commented Jan 18, 2019

are there any plans to implement this? or is there maybe even a way how we can achieve this already with the current version?

@mmert1988
Copy link

Having the same issue

@komaxx
Copy link

komaxx commented Feb 5, 2019

Facing the same problem.
Setting up Crashlytics just the same way we set up / configure Firebase would be super helpful.

@Kocjan
Copy link

Kocjan commented Feb 4, 2020

What about NDK libs paths which we were able to set under Fabric plugin: androidNdkOut and androidNdkLibsOut?
I am struggling to customize libs location using Firebase Crashlytics plugin.

@vkryachko
Copy link
Member

One thing you can do to work around this is to disable default app initialization and name the app "default" when initializing it.

see https://firebase.googleblog.com/2017/03/take-control-of-your-firebase-init-on.html for details

@TKBurner
Copy link

Talked to the team, they found this super interesting and will want to investigate. The think they may be able to implement better support for this, but can't provide any specific timeline quite yet.

@ashwinraghav
Copy link
Contributor

Thanks for the question and for waiting patiently.

Many Firebase SDKs products provide an overload that allows you to pass in a custom FirebaseApp getInstance(FirebaseApp).

This API will allow you inject these Firebase instances as dependencies into your application code so they continue remaining agnostic to prod,staging,dev versions of your app.

I suspect your question pertains to eagerly initialized SDKs like Analytics, Crashlytics and Firebase Performance that require no developer interaction and start working automagically once included in the app. Note that these SDKs also do not support the desired getInstance(FirebaseApp) overload.

The challenge with designing an API like getInstance(FirebaseApp) for these products is that it would have to be wired in super early in the App's lifecycle, to (say) allow Crashlytics to capture crashes that happen early on, or to (say) allow Performance to capture app start metrics early on.

In the absence of this API, you may be able to do this by disabling the default init provider and creating your own equivalent. The key here is to perform the custom initialization super early in your app's lifecycle, like in a Content Provider.

FirebaseOptions.Builder builder = new FirebaseOptions.Builder()
    .setApplicationId("1:0123456789012:android:0123456789abcdef")
    .setApiKey("your_api_key")
    .setDatabaseUrl("https://your-app.firebaseio.com")
    .setStorageBucket("your-app.appspot.com");
FirebaseApp.initializeApp(this, builder.build());

I realize is a suboptimal experience. It does get the job done for now. Feel free to propose ideas you may have to help up build an API to accommodate the nuance I described above.

@ashwinraghav
Copy link
Contributor

Closing this as a duplicate of #66 since there's been a lot more folks jumping in there. Thanks and please bring forward any API ideas you have.

@vkryachko
Copy link
Member

To support the use-case of prod,staging,dev app variants, there exists a very suitable mechanism to have different options per app flavor. The google-services plugin has this logic built-in, e.g. you can have the following google-services.json files in your app directory:

app
└── src
    ├── dev
    │   └── google-services.json
    ├── prod
    │   └── google-services.json
    └── staging
        └── google-services.json

@firebase firebase locked and limited conversation to collaborators Jun 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants