firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.28k stars 578 forks source link

Getting "class file for com.google.common.util.concurrent.ListenableFuture not found" in Worker class. #5467

Closed ravibpatel closed 10 months ago

ravibpatel commented 1 year ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

cannot access ListenableFuture public class MyWorker extends Worker { ^ class file for com.google.common.util.concurrent.ListenableFuture not found

Steps to reproduce:

I am using Work Manager and have Worker class. After upgrading to version 21.4.0 of Firebase Analytics, I am getting this issue. I am using the following dependencies.

Relevant Code:

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
    implementation "androidx.work:work-runtime:2.8.1"
    implementation platform('com.google.firebase:firebase-bom:32.4.0')
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
google-oss-bot commented 1 year ago

I found a few problems with this issue:

kenneth-leong-gt commented 1 year ago

i am also getting this issue

argzdev commented 1 year ago

Hi @ravibpatel, thanks for reaching out. This is an odd issue, there must've been a missed dependency during the migration for the analytics library. That said, I was also able to reproduce the same behavior. I'll notify our engineers and see what we can do here. Thanks!

mihaicristianpetrescu commented 1 year ago

Same issue as well only that I'm using AS 2022.3.1 Patch 2.

const val firebaseBOM = "com.google.firebase:firebase-bom:32.4.0"

const val firebaseConfig = "com.google.firebase:firebase-config"
const val firebaseMessaging = "com.google.firebase:firebase-messaging"
const val firebaseDynamicLinks = "com.google.firebase:firebase-dynamic-links"
const val firebaseCrashlyticsKtx = "com.google.firebase:firebase-crashlytics"
const val firebasePerformance = "com.google.firebase:firebase-perf"
const val firebaseAnalytics = "com.google.firebase:firebase-analytics:21.3.0"
lbarrettanderson commented 1 year ago

Hi all, you can try the following as a temporary solution until it's fixed on our side. Please reply back if it works for you

Add a dependency on guava

implementation 'com.google.guava:guava:31.1-android'
mihaicristianpetrescu commented 1 year ago

Was already using Guava but an older version and it wasn't used in the specific dependency file of the submodule that was throwing the compilation error, updated to the latest one and it seems the issue went away - still inconsistent that we need another dependency to work with a BOM that should be an all-in-one solution.

const val guava = "com.google.guava:guava:32.1.3-android"

hnljp commented 1 year ago

Remember if there are dependencies using guava and other dependencies using listenablefuture, then it is important to use the empty listenablefuture dependency, as guava is already contains the listenablefuture functions. implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'

kenneth-leong-gt commented 1 year ago

seems that this is fixed in firebase bom 21.5.0 which pulls in firebase-analytics 21.5.0

miduch commented 12 months ago

same issue with com.google.firebase:firebase-bom v32.6.0

ZackOPP commented 11 months ago

Any update regarding this issue? I'm also facing this in v32.6.0

miduch commented 11 months ago

same issue with com.google.firebase:firebase-bom v32.7.0

argzdev commented 11 months ago

Hey folks, I've tested this, and so far it should be working on the latest version of BoM 32.7.0 or com.google.firebase:firebase-analytics version 21.5.0. If not, could you share dependencies or a minimal repro? There could be a conflicting dependency that we haven't checked. Thanks!

ZackOPP commented 11 months ago

Hi @argzdev My module getting this error is using the Firebase messaging version that comes from BoM 32.7.0 (i.e.: com.google.firebase:firebase-messaging:23.4.0).

I'm also using workmanager 2.8.1 with a Worker class same as mentioned in the issue. I tried with the latest version too (2.9.0), but no luck.

I'm getting this error when running either of these tasks:

./gradlew myModule:compileDebugKotlin
./gradlew myModule:compileReleaseKotlin

... and it points to this call:

WorkManager.getInstance(context)
steffandroid commented 11 months ago

I'm experiencing this issue not with WorkManager but with CameraX, specifically the call to ProcessCameraProvider.getInstance() from androidx.camera:camera-lifecycle:1.3.0. I think I see the problem:

Checking the dependency graph shows that CameraX pulls in the standalone com.google.guava:listenablefuture:1.0 rather than the whole Guava library. WorkManager 2.9.0 does the same.

com.google.firebase:firebase-analytics:21.4.0 adds a new dependency on the whole Guava library (reported separately in https://github.com/firebase/firebase-android-sdk/issues/5446), which itself has a dependency on com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava. This means that any modules which use CameraX/WorkManager but not Firebase Analytics now transitively depend on an empty version of the standalone ListenableFuture library.

com.google.firebase:firebase-analytics:21.5.0 also continues to depend on Guava.

argzdev commented 11 months ago

Hey @ZackOPP, not sure if I'm missing anything. In my case, your scenario seems to work alright. Could you provide a minimal reproducible example so we can investigate your issue further?

With running the commands or running the app

./gradlew myModule:compileDebugKotlin
./gradlew myModule:compileReleaseKotlin

build.gradle:

    implementation("androidx.work:work-runtime-ktx:2.9.0")
    implementation("com.google.firebase:firebase-analytics:21.5.0")
    implementation("com.google.firebase:firebase-messaging:23.4.0")

With these dependencies, it seems to work alright. Perhaps you could try cleaning and rebuilding your app? Thanks!

argzdev commented 11 months ago

Hi @steffandroid, when adding the following code snippet:

    implementation("androidx.work:work-runtime-ktx:2.9.0")
    implementation("com.google.firebase:firebase-analytics:21.5.0")
    implementation("com.google.firebase:firebase-messaging:23.4.0")

    implementation("androidx.camera:camera-core:1.3.0")
    implementation("androidx.camera:camera-camera2:1.3.0")
    implementation("androidx.camera:camera-lifecycle:1.3.0")
    implementation("androidx.camera:camera-video:1.3.0")
    implementation("androidx.camera:camera-view:1.3.0")
    implementation("androidx.camera:camera-extensions:1.3.0")

I did notice that the dependency tree shows that the camera library is relying on com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava:

Screenshot 2023-12-11 at 8 41 06 PM

This means that any modules which use CameraX/WorkManager but not Firebase Analytics now transitively depend on an empty version of the standalone ListenableFuture library.

Yes, I think that's what's happening. However, from my understanding, it should have a different error(?) Are you also experiencing the same issue: "class file for com.google.common.util.concurrent.ListenableFuture not found". ?

In my case, after adding the dependencies for the CameraX library and with the code snippets below. I was unable to encounter any issue when calling the ProcessCameraProvider:

fun startCamera(context: Context){
    val cameraProvider = ProcessCameraProvider.getInstance(context)
}

Could you provide more information such as steps to reproduce this behavior, or perhaps a minimal reproducible example? Thanks!

steffandroid commented 11 months ago

@argzdev I had to add an explicit dependency on Guava with updating to 21.4.0 as suggested in https://github.com/firebase/firebase-android-sdk/issues/5467#issuecomment-1776011565. If I remove this, the exact compilation error I'm seeing is Cannot access class 'com.google.common.util.concurrent.ListenableFuture'. Check your module classpath for missing or conflicting dependencies.

I've tried making a minimum reproducible example and so far cannot reproduce. I shall continue investigating.

steffandroid commented 11 months ago

@argzdev I've now been able to reproduce, see https://github.com/steffandroid/FirebaseBuildErrorExample. Note that the error is no longer present after downgrading Analytics to 21.3.0.

Edit: just noticed this issue has already been reported on Google's Issue Tracker.

argzdev commented 11 months ago

Hi @steffandroid, thanks for the extra information. I was able to reproduce the same behavior but it seems to go away after adding id("com.google.gms.google-services") in the plugin block.

build.gradle of lib-analytics

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("com.google.gms.google-services")
}

project gradle

plugins {
    id("com.android.application") version "8.2.0-alpha13" apply false
    id("org.jetbrains.kotlin.android") version "1.9.21" apply false
    id("com.android.library") version "8.2.0-alpha13" apply false
    id("com.google.gms.google-services") version "4.4.0" apply false
}

Let me know if this helps, thanks!

google-oss-bot commented 10 months ago

Hey @ravibpatel. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

ravibpatel commented 10 months ago

It doesn't happen for me anymore, using the latest version, but I do use "com.google.gms.google-service" plugin as mentioned by @argzdev. Maybe that's the reason it doesn't trigger for me anymore?

argzdev commented 10 months ago

It seems to me that this issue has been resolved. I'll go ahead and close this now. Feel free to let me know if this issue is still present, and we'll investigate this further.