Skip to content
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

Update version of lifecycle-viewmodel dependency that LeakCanary compiles against #2483

Open
mauriciogg opened this issue Mar 8, 2023 · 5 comments
Milestone

Comments

@mauriciogg
Copy link

mauriciogg commented Mar 8, 2023

Description

Hello,

We are encountering an issue related to #2314 that manifest itself as a build issue rather than a runtime issue when building with Bazel as opposed to Gradle so 2108693 does not fix the issue.
Under bazel there is an extra check to ensure that desugaring wont result in runtime issues like the one fixed in 2108693. This is a tricky one to fix on the build system since com.squareup.leakcanary:leakcanary-object-watcher-android-androidx does not declare any dependency on androidx (i understand this is the correct behavior). Because of this, we have to possible solutions: 1) manually craft the target for leakcanary we use in bazel to depend on the androidx library or 2) disable the checks alltogether. Both are undesirable for different reasons.
Wouldnt adding a default implementation for create(modelClass, extras that simply calls create(modelClass) here fix the issue both at build time and runtime?
Can #2314 be reopened?

Steps to Reproduce

Building an android_binary target in bazel that depends on
androidx.lifecycle:lifecycle-viewmodel (version >= 2.5.1) / @mvn//:androidx_lifecycle_lifecycle_viewmodel
com.squareup.leakcanary:leakcanary_android_core / @mvn//:com_squareup_leakcanary_leakcanary_android_core

will result in the following failure:
singlejar_local: androidx/lifecycle/ViewModelProvider$Factory needed on the classpath for desugaring leakcanary/internal/ViewModelClearedWatcher$Companion$install$provider$1. Please add the missing dependency to the target containing the latter.

Expected behavior: [What you expect to happen]
Build succeeds

Version Information

  • LeakCanary version: 2.10
  • Android OS version: <24
  • Gradle version: n/a
@pyricau
Copy link
Member

pyricau commented Mar 20, 2023

@mauriciogg Can you open a PR? Would be much easier if you come up with the fix for your specific issue that you know works

@mauriciogg
Copy link
Author

@mauriciogg Can you open a PR? Would be much easier if you come up with the fix for your specific issue that you know works
@pyricau looks like this is more effort than initially anticipated, in order to fix this the viewmodel dependency needs to be updated in order to bring androidx.lifecycle.viewmodel.CreationExtras and that triggers a bunch of other issues. We have a workaround so its not high priority for us. I can close this or leave it open and address once the viewmodel version is updated.

@pyricau
Copy link
Member

pyricau commented Mar 22, 2023

the viewmodel dependency needs to be updated and that triggers a bunch of other issues.

What issues?

Does the generated bytecode end up not being compatible with older versions of the lifecycle library?

@mauriciogg
Copy link
Author

the viewmodel dependency needs to be updated and that triggers a bunch of other issues.

What issues?

Does the generated bytecode end up not being compatible with older versions of the lifecycle library?

Different version of the kotlin compiler used to compile the lib:

I'm updating androidX-fragment from 1.0.0 to 1.5.1 here which is the first version to depend on lifecycle-viewmodel which includes the class androidx.lifecycle.viewmodel.CreationExtras needed to override the new create method. This results in the following error:

> Task :leakcanary-object-watcher-android-androidx:compileDebugKotlin FAILED
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    /Users/mgalindo/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.6.0/baf82c475e9372c25407f3d132439e4aa803b8b8/kotlin-stdlib-jdk8-1.6.0.jar (version 1.6)
    /Users/mgalindo/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.6.0/da6bdc87391322974a43ccc00a25536ae74dad51/kotlin-stdlib-jdk7-1.6.0.jar (version 1.6)
    /Users/mgalindo/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4.21/4a668382d7c38688d3490afde93b6a113ed46698/kotlin-stdlib-1.4.21.jar (version 1.4)
    /Users/mgalindo/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.4.21/7f48a062aa4b53215998780f7c245a4276828e1d/kotlin-stdlib-common-1.4.21.jar (version 1.4)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
e: Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
e: /Users/mgalindo/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.6.0/da6bdc87391322974a43ccc00a25536ae74dad51/kotlin-stdlib-jdk7-1.6.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.1.
e: /Users/mgalindo/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.6.0/baf82c475e9372c25407f3d132439e4aa803b8b8/kotlin-stdlib-jdk8-1.6.0.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.1.
e: /Users/mgalindo/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-android/1.6.1/4e61fcdcc508cbaa37c4a284a50205d7c7767e37/kotlinx-coroutines-android-1.6.1.jar!/META-INF/kotlinx-coroutines-android.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.1.
e: /Users/mgalindo/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core-jvm/1.6.1/97fd74ccf54a863d221956ffcd21835e168e2aaa/kotlinx-coroutines-core-jvm-1.6.1.jar!/META-INF/kotlinx-coroutines-core.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.1.

I'm not super familiar with gradle so I might not be doing the right thing though.

@pyricau
Copy link
Member

pyricau commented Mar 23, 2023

ah so looks like we'd need to bump the kotlin version of LeakCanary first, which implies new major release. That's something I do want to do but it'll take time.

@pyricau pyricau added this to the 3.0 milestone May 18, 2023
@pyricau pyricau changed the title leakcanary + androidx.lifecycle-viewmodel broken in Bazel Update version of lifecycle-viewmodel dependency that LeakCanary compiles against May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants