RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.81k stars 405 forks source link

Compatibility with Gradle 5 regarding dependencies #370

Open avianey opened 5 years ago

avianey commented 5 years ago

Latest Stable Android Studio release (3.4 so far) and tooling (com.android.tools.build:gradle:3.4.0) uses gradle 5.1.1 which breaks maven dependency management :

When using the 2.7.0 version of fotoappart using above configuration like this (in JAVA)

Fotoapparat
    .with(getContext())
    .into((CameraView) view)
    .previewScaleType(ScaleType.CenterCrop)
    .photoResolution(ResolutionSelectorsKt.highestResolution())
    .lensPosition(LensPositionSelectorsKt.back())
    .focusMode(SelectorsKt.firstAvailable(
            FocusModeSelectorsKt.continuousFocusPicture(),
            FocusModeSelectorsKt.autoFocus(),
            FocusModeSelectorsKt.fixed()
    ))
    .flash(SelectorsKt.firstAvailable(
            FlashSelectorsKt.autoRedEye(),
            FlashSelectorsKt.autoFlash(),
            FlashSelectorsKt.torch()
    ))
    .frameProcessor(frameProcessor)
    .logger(LoggersKt.logcat())

Compilation fails :

error: cannot access Function1
class file for kotlin.jvm.functions.Function1 not found

Because runtime dependencies are no more imported by gradle 5... ...and you fotoappart-2.7.0.pom file uses runtime scope.

    <dependency>
      <groupId>androidx.annotation</groupId>
      <artifactId>annotation</artifactId>
      <version>1.0.0</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>androidx.exifinterface</groupId>
      <artifactId>exifinterface</artifactId>
      <version>1.0.0</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib</artifactId>
      <version>1.3.0</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlinx</groupId>
      <artifactId>kotlinx-coroutines-core</artifactId>
      <version>1.0.0</version>
      <scope>runtime</scope>
    </dependency>

What did you expect?

Dependencies are imported when project uses :

implementation 'io.fotoapparat:fotoapparat:2.7.0'

For this, using gradle 5, the pom needs to use compile scope now instead of runtime. And needs to be re generated (using an up to date library that understand implementation scope)

Context:

avianey commented 5 years ago

Quick / Dirty fix is to manually include dependencies :

implementation 'io.fotoapparat:fotoapparat:2.7.0'
// add missing dependencies
implementation "androidx.annotation:annotation:1.0.2"
implementation "androidx.exifinterface:exifinterface:1.0.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.30"
vhontar commented 5 years ago

Hi, I have another problem after adding this quick /dirty fix above: :app:checkDevelopDebugDuplicateClasses

Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.IResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)

my dependencies: implementation "com.android.support:appcompat-v7:${supportLibraryVersion}" implementation "com.android.support:cardview-v7:${supportLibraryVersion}" implementation "com.android.support:recyclerview-v7:${supportLibraryVersion}" implementation "com.android.support:support-v4:${supportLibraryVersion}" implementation "com.android.support:design:${supportLibraryVersion}" implementation "com.android.support:customtabs:${supportLibraryVersion}" implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3'

Do you have any idea about what to do next?

vhontar commented 5 years ago

Duplicate classes appear after adding implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.30" before, there are problems which was described above.

avianey commented 5 years ago

Your problem is not related... Might come from somewhere else, log indicates that you mix "androidx" with "android.support" which is not good You should switch to androidx now What is your dependency graph ?

vhontar commented 5 years ago

ok, thank you

sduqlsc commented 5 years ago

same problem here, i fixed it through AS menu- tools->kotlin->configure kotiln in Project..

Hope there would be version written in Java and Android Support Library