stephanenicolas / toothpick

A scope tree based Dependency Injection (DI) library for Java / Kotlin / Android.
Apache License 2.0
1.12k stars 115 forks source link

Dependencies of smoothie-lifecycle #371

Closed osipxd closed 4 years ago

osipxd commented 5 years ago

Hello! Why smoothie-lifecycle depends on androidx.legacy:legacy-support-v4:1.0.0? I've not found any usages of it. And why it depends on androidx.lifecycle:lifecycle-common-java8 but not on androidx.lifecycle:lifecycle-common (wihout java8)? Same question about smoothie-lifecycle-viewmodel module.

stephanenicolas commented 5 years ago

You're probably right about the first part of the comment, the dependency on legacy support. We need to check that.

For the second part, it's the recommended practice for java 8 support : https://developer.android.com/jetpack/androidx/releases/lifecycle

osipxd commented 5 years ago

Because of -java8 I see following error:

> Transform artifact lifecycle-common-java8.jar (androidx.lifecycle:lifecycle-common-java8:2.2.0-alpha02) with DexingTransform
AGPBI: {"kind":"error","text":"Default interface methods are only supported starting with Android N (--min-api 24): void androidx.lifecycle.DefaultLifecycleObserver.onCreate(androidx.lifecycle.LifecycleOwner)","sources":[{}],"tool":"D8"}

   > Failed to transform artifact 'lifecycle-common-java8.jar (androidx.lifecycle:lifecycle-common-java8:2.2.0-alpha02)' to match attributes {artifactType=android-dex, dexing-is-debuggable=true, dexing-min-sdk=19, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for DexingTransform: /Users/o.fatkulin/.gradle/caches/modules-2/files-2.1/androidx.lifecycle/lifecycle-common-java8/2.2.0-alpha02/cd3478503da69b1a7e0319bd2d1389943db9b364/lifecycle-common-java8-2.2.0-alpha02.jar.
         > Error while dexing.

And looks like this specific to Java 8 API (onCreate) not used in smoothie-lifecycle too. Maybe you can depend on lifecycle-common?

As a workaround I've added next lines to build.gradle script:

dependencies {
    implementation(deps.toothpick.lifecycle) {
        exclude group: 'androidx.legacy'
    }
}

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.name == 'lifecycle-common-java8') {
            details.useTarget group: details.requested.group, name: 'lifecycle-common', version: details.requested.version
            details.because 'We can not use Java 8 because of min API level 19'
        }
    }
}
stephanenicolas commented 5 years ago

Do you feel like doing a PR. Ideally we would also have a way to test that it works both for users using java 8 & 9.

Le jeu. 19 sept. 2019 à 08:28, Osip Fatkullin notifications@github.com a écrit :

Because of -java8 I see following error:

Transform artifact lifecycle-common-java8.jar (androidx.lifecycle:lifecycle-common-java8:2.2.0-alpha02) with DexingTransform AGPBI: {"kind":"error","text":"Default interface methods are only supported starting with Android N (--min-api 24): void androidx.lifecycle.DefaultLifecycleObserver.onCreate(androidx.lifecycle.LifecycleOwner)","sources":[{}],"tool":"D8"}

And looks like this specific to Java 8 API (onCreate) not used in smoothie-lifecycle too. Maybe you can depend on lifecycle-common?

As a workaround I've added next lines to build.gradle script:

dependencies { implementation(deps.toothpick.lifecycle) { exclude group: 'androidx.legacy' }

modules {
    module('androidx.lifecycle:lifecycle-common-java8') {
        replacedBy('androidx.lifecycle:lifecycle-common', 'we use min api 19, and can not use java 8')
    }
}

}

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/stephanenicolas/toothpick/issues/371?email_source=notifications&email_token=AAN7PXMORRSQUZZN4NM2TELQKOLBXA5CNFSM4IX6DRB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7D4BIY#issuecomment-533184675, or mute the thread https://github.com/notifications/unsubscribe-auth/AAN7PXMFTUDX67HGHAMBRLDQKOLBXANCNFSM4IX6DRBQ .

osipxd commented 5 years ago

Ok, I'll create PR. And will try to test it on several java versions.

osipxd commented 5 years ago

There is Gradle linter that can automatically detect such cases and fix them. Maybe I'll add it to the project? https://github.com/nebula-plugins/gradle-lint-plugin

osipxd commented 5 years ago

Oh... It not works with api and implementation configurations https://github.com/nebula-plugins/gradle-lint-plugin/issues/126