firebase-admin-java icon indicating copy to clipboard operation
firebase-admin-java copied to clipboard

Library size with dependencies

Open tananaev opened this issue 3 years ago • 6 comments

The library with all dependencies is really big. I only want to use Firebase push notifications. Can I exclude any dependencies to reduce the size?

tananaev avatar Jul 17 '22 17:07 tananaev

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Jul 17 '22 17:07 google-oss-bot

To add an additional point to this, in upgrading from com.google.firebase:firebase-admin 8.2.0 => 9.0.0, we have an increase in our jar size by 21.3MB. Background: Kotlin 1.7.10, server-side, not Android. @lahirumaramba I believe the only change this could've been related to is by updating the google cloud libraries bom / client api.

maxkramer avatar Jul 18 '22 12:07 maxkramer

Is it safe to exclude google-cloud-firestore like this if I'm only interested in the Firebase push notifications?

    implementation ("com.google.firebase:firebase-admin:9.0.0") {
        exclude group: 'com.google.cloud', module: 'google-cloud-firestore'
    }

tananaev avatar Aug 30 '22 16:08 tananaev

@tananaev YMMV but I've excluded it and it seemed okay:

  <dependency>
      <groupId>com.google.firebase</groupId>
      <artifactId>firebase-admin</artifactId>
      <version>${firebaseAdmin.version}</version>
      <exclusions>
          <exclusion>
              <groupId>com.google.cloud</groupId>
              <artifactId>google-cloud-firestore</artifactId>
          </exclusion>
      </exclusions>
  </dependency>

TomBeckett avatar Aug 31 '22 10:08 TomBeckett

Yeah, I also tried it earlier and it works, but just wanted to confirm that there are no corner cases that will fail with class not found exceptions 🙂

tananaev avatar Aug 31 '22 14:08 tananaev

Yup I would not say its officially supported but works 🤷‍♂️

TomBeckett avatar Aug 31 '22 14:08 TomBeckett

Hey everyone, thanks for your patience on this. We have had some previous discussions on the library size (see #273), and as you mentioned above, using Maven exclusions is the correct way to remove the unwanted dependencies for your project. Gradle supports the same feature if that is your build tool. You should be able to exclude google-cloud-storage and google-cloud-firestore (assuming you don't use any of those APIs in your project) without any issue, plus some of the netty-* dependencies as well. See below for an example:

<dependency>
      <groupId>com.google.firebase</groupId>
      <artifactId>firebase-admin</artifactId>
      <version>6.8.1</version>
      <exclusions>
        <exclusion>
          <groupId>com.google.cloud</groupId>
          <artifactId>google-cloud-firestore</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.google.cloud</groupId>
          <artifactId>google-cloud-storage</artifactId>
        </exclusion>
        <exclusion>
          <groupId>io.netty</groupId>
          <artifactId>netty-codec-http</artifactId>
        </exclusion>
        <exclusion>
          <groupId>io.netty</groupId>
          <artifactId>netty-handler</artifactId>
        </exclusion>
        <exclusion>
          <groupId>io.netty</groupId>
          <artifactId>netty-transport</artifactId>
        </exclusion>
      </exclusions>
</dependency>

lahirumaramba avatar Dec 19 '22 22:12 lahirumaramba

@lahirumaramba In 9.2.0 and 9.1.1, if I exclude google-cloud-storage it results in a java.lang.ClassNotFoundException: com.google.api.client.json.jackson2.JacksonFactory error because com.google.firebase.internal.ApiClientUtils uses it.

Could you please add an explicit dependency on com.google.api.client.json.jackson2?

Edit: it's actually com.google.http-client:google-http-client-jackson2, the api-client one is no longer available

sryze avatar Mar 16 '24 18:03 sryze