Skip to content
This repository has been archived by the owner on Oct 31, 2022. It is now read-only.

Incompatibility with Dagger Hilt's enableAggregatingTask #180

Open
AlfredAndroidTedmob opened this issue Nov 9, 2021 · 3 comments
Open

Comments

@AlfredAndroidTedmob
Copy link

AlfredAndroidTedmob commented Nov 9, 2021

Project Setup

build.gradle (some information changed or removed because this is our company's code)

buildscript {
    ext {
        kotlin_version = '1.5.31'
        navigationVersion = '2.3.5'
        daggerVersion = '2.40'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.3'
        classpath 'com.google.gms:google-services:4.3.10'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.firebase:firebase-crashlytics-gradle:2.8.0"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
        classpath "com.google.dagger:hilt-android-gradle-plugin:$daggerVersion"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

tasks.register("delete", Delete) {
    delete rootProject.buildDir
}

app/build.gradle (some information changed or removed because this is our company's code)

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://plugins.gradle.org/m2/' }
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.13.4'
    }
}

repositories {
    mavenCentral()
}

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: 'kotlin-parcelize'

ext.buildToolsVersion = '31.0.0'

android {
    compileSdkVersion 31
    buildToolsVersion project.ext.buildToolsVersion

    defaultConfig {
        applicationId "[redacted]"
        minSdkVersion 21
        targetSdkVersion 31
        versionCode 1
        versionName '1.0.0'
        multiDexEnabled true
    }

    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions "scope"

    productFlavors {
        prod {
            dimension "scope"
        }
    }

    packagingOptions {
        exclude 'LICENSE.txt'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    buildFeatures {
        viewBinding true
    }

    bundle {
        language {
            enableSplit = false
        }
    }

    hilt {
        enableAggregatingTask = true //fixme have to set this to false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2"

    implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
    implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"

    implementation platform("com.google.firebase:firebase-bom:28.0.0")
    implementation "com.google.firebase:firebase-analytics-ktx"
    implementation "com.google.firebase:firebase-crashlytics-ktx"

    //ui
    implementation "androidx.appcompat:appcompat:1.4.0-rc01"
    implementation "androidx.recyclerview:recyclerview:1.2.1"
    implementation "com.google.android.material:material:1.4.0"
    implementation "androidx.constraintlayout:constraintlayout:2.1.1"
    implementation "androidx.preference:preference-ktx:1.1.1"
    implementation "androidx.cardview:cardview:1.0.0"
    implementation "androidx.core:core-splashscreen:1.0.0-alpha02"

    def lifecycleVersion = "2.4.0"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-common:$lifecycleVersion"

    implementation "androidx.dynamicanimation:dynamicanimation-ktx:1.0.0-alpha03"

    // remote
    def okHttpVersion = '4.9.2'
    implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
    implementation "com.squareup.okhttp3:okhttp-urlconnection:$okHttpVersion"
    implementation "com.squareup.okhttp3:logging-interceptor:$okHttpVersion"
    def retrofitVersion = '2.9.0'
    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"

    implementation "io.coil-kt:coil:1.4.0"

    // rx
    implementation "io.reactivex.rxjava3:rxandroid:3.0.0"
    implementation "io.reactivex.rxjava3:rxjava:3.1.1"
    implementation "com.f2prateek.rx.preferences2:rx-preferences:2.0.1"
    implementation "com.jakewharton.rxbinding4:rxbinding-core:4.0.0"
    implementation "com.jakewharton.rxbinding4:rxbinding-material:4.0.0"

    // di
    implementation "com.google.dagger:hilt-android:$daggerVersion"
    kapt "com.google.dagger:hilt-compiler:$daggerVersion"

    // util
    implementation "com.jakewharton.timber:timber:4.7.1"
    implementation "io.michaelrocks:libphonenumber-android:8.12.31"

    // push
    implementation 'com.onesignal:OneSignal:4.6.0'

    //testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
}

Full Error

dagger-2.40-syncing-issue

Short version

On gradle sync, the compiler is failing and returning an error about a missing build variant:

org.gradle.api.UnknownDomainObjectException: KotlinJvmAndroidCompilation with name 'prodReleaseUnitTest' not found

What happened

I have raised the issue on Dagger's github project (Dagger issue #2990), and I was pointed out to remove plugins one by one, and turning off the OneSignal gradle plugin (and adding the necessary play-services-base) resulted in a successful gradle sync.
I was also pointed out to the following issue: Dagger issue #2744, where "resolving dependencies during task execution" might be the problem.

I will copy the other important parts of the discussion here (sorry, I was not able to add everything inside the quote):

I think the problem is:
org.gradle.api.UnknownDomainObjectException: KotlinJvmAndroidCompilation with name 'prodReleaseUnitTest' not found

gradle version 7.0.3 (Android Studio 2020.3.1 Patch 3)

buildTypes: debug and release.

flavorDimensions "scope"

productFlavors {
    prod {
        dimension "scope"
    }
}

There are no test folders in the project (also, the test dependencies were removed).

The same error occurs when syncing using prodDebug or prodRelease.

Working scenarios:

1- Using version 2.39.1 or below

2- Adding this to the build.gradle file in the android config: hilt { enableAggregatingTask = false }

Please find the proposed solution by @danysantiago for the oss-licenses-plugin here: Issue #2774 solution. It may be related to when the dependencies are being checked.

@kroegerama
Copy link

Thanks for opening this issue. This was really hard to find; had to gradually remove the Gradle plugins and of course it was OneSignal.

@jkasten2 do you have an ETA for a fix?

@janbolat
Copy link

janbolat commented Feb 6, 2022

Any updates?

@mobinyardim
Copy link

Same problem!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants