skip to Main Content

I have been trying to implement a mobile application which was supposed to use Dagger Hilt, Glide and Kapt. However, when I tried to implement it, i got this error

error message:

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction

java.lang.reflect.InvocationTargetException (no error message)

i tried to change hilt version to latest version but still i face the same issues

build.gradle (project)

buildscript {
    ext.kotlin_version = '1.9.0'

    repositories {
        maven { url "https://repo1.maven.org/maven2" }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

plugins {
id 'com.android.application' version '8.1.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
   id 'com.android.library' version '8.1.2' apply false
    id 'com.google.dagger.hilt.android' version '2.51.1' apply false


    id 'com.google.gms.google-services' version '4.3.15' apply false
//    id 'com.google.firebase.crashlytics' version '2.9.8' apply false
}


task clean(type: Delete) {
    delete rootProject.buildDir
}

setting.gradle

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()

        flatDir {
            dirs 'libs'   // aar
        }
    }
}


dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()

        flatDir {
            dirs 'libs'   // aar
        }
        maven { url 'https://jitpack.io' }
        maven { url "https://repo1.maven.org/maven2" }
    }
}

build.gradle (app)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-parcelize'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'com.google.dagger.hilt.android'
    id 'com.google.gms.google-services'
//    id 'com.google.firebase.crashlytics'
}

android {
    namespace 'com.print.app'
    compileSdk 34

    defaultConfig {
        applicationId "com.print.app"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

  

    def setOutputFileName = { prefix ->
        applicationVariants.all { variant ->
            variant.outputs.all {
                outputFileName = "${prefix}-${variant.buildType.name.capitalize()}-${variant.mergedFlavor.versionName}.apk"
            }
        }
    }

    buildTypes {

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            buildConfigField "String", "BASE_URL", LIVE_URL
            signingConfig signingConfigs.release
            
        }

        debug {
            buildConfigField "String", "BASE_URL", DEVELOPMENT_URL
            signingConfig signingConfigs.debug
        }


    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }
    buildFeatures {
        viewBinding true
        dataBinding true
        buildConfig  true
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['src/main/jniLibs']
            aidl.srcDirs = ['src/main/aidl']
        }
    }

    
}

 

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.core:core-ktx:1.10.1'
    implementation 'androidx.activity:activity-ktx:1.7.2'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
    implementation 'com.google.code.gson:gson:2.10.1'
    implementation project(path: ':network')
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'


    // Hilt
    implementation "com.google.dagger:hilt-android:2.51.1"
    kapt "com.google.dagger:hilt-compiler:2.51.1"

    //Preferences DataStore
    implementation("androidx.datastore:datastore-preferences:1.1.0")

    // Lifecycle
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
     implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'

    //ssp and sdp lib
    implementation 'com.intuit.ssp:ssp-android:1.1.0'
    implementation 'com.intuit.sdp:sdp-android:1.1.0'

    //coroutines lib
    def coroutines = "1.6.4"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines"

//    //glide lib
//    def glide = "4.16.0"
//    implementation "com.github.bumptech.glide:glide:$glide"
//    kapt "com.github.bumptech.glide:compiler:$glide"

    // Using Exoplayer lib so we can manage cache easily.
    implementation "com.google.android.exoplayer:exoplayer:2.18.7"

//    //Firebase dependencies
//    implementation platform('com.google.firebase:firebase-bom:32.2.0')
//    implementation 'com.google.firebase:firebase-analytics-ktx'
//    implementation "com.google.firebase:firebase-crashlytics-ktx"
//    implementation("com.google.firebase:firebase-firestore")


    implementation 'androidx.fragment:fragment-ktx:1.6.2'

//    kapt 'org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.2'
    kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.2"
}

kapt {
    correctErrorTypes true
}

enter image description here

terminal message error

Could not resolve all files for configuration ‘:classpath’.
Could not resolve com.android.tools.build:gradle:8.1.2.
Required by:
project : > com.android.application:com.android.application.gradle.plugin:8.1.2
project : > com.android.library:com.android.library.gradle.plugin:8.1.2
> No matching variant of com.android.tools.build:gradle:8.1.2 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute ‘org.gradle.plugin.api-version’ with value ‘8.0’ but:
– Variant ‘apiElements’ capability com.android.tools.build:gradle:8.1.2 declares a library, packaged as a jar, and its dependencies declared externally:
– Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
– Other compatible attribute:
– Doesn’t say anything about org.gradle.plugin.api-version (required ‘8.0’)
– Variant ‘javadocElements’ capability com.android.tools.build:gradle:8.1.2 declares a component for use during runtime, and its dependencies declared externally:
– Incompatible because this component declares documentation and the consumer needed a library
– Other compatible attributes:
– Doesn’t say anything about its target Java version (required compatibility with Java 8)
– Doesn’t say anything about its elements (required them packaged as a jar)
– Doesn’t say anything about org.gradle.plugin.api-version (required ‘8.0’)
– Variant ‘runtimeElements’ capability com.android.tools.build:gradle:8.1.2 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
– Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
– Other compatible attribute:
– Doesn’t say anything about org.gradle.plugin.api-version (required ‘8.0’)
– Variant ‘sourcesElements’ capability com.android.tools.build:gradle:8.1.2 declares a component for use during runtime, and its dependencies declared externally:
– Incompatible because this component declares documentation and the consumer needed a library
– Other compatible attributes:
– Doesn’t say anything about its target Java version (required compatibility with Java 8)
– Doesn’t say anything about its elements (required them packaged as a jar)
– Doesn’t say anything about org.gradle.plugin.api-version (required ‘8.0’)
enter image description here

2

Answers


  1. 1. You need to change which JDK Gradle used for running. From JDK 8 to JDK 11.

    Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8.

    As the error message suggests.

    Check this image for more information.


    2. Also this

    compileOptions {
       sourceCompatibility JavaVersion.VERSION_17
       targetCompatibility JavaVersion.VERSION_17
    }
    

    to

    compileOptions {
       sourceCompatibility JavaVersion.VERSION_11
       targetCompatibility JavaVersion.VERSION_11
    }
    

    or via IDE like this

    Login or Signup to reply.
  2. The error message tells you you need be running the build on Java 11 or later to use this version of the Android plugin.

    Make sure you have such a version of the JDK installed, and point Android Studio towards it (this question has details), or set your JAVA_HOME environment variable to its location if you are running Gradle from the command line.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search