7

when I run android application in real device I am getting following gradle errors

Execution failed for task ':common:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)

below my app.gradle

    plugins {
    id 'com.android.application'
    id 'kotlin-android'
}
apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: 'kotlin-kapt'

apply from: '../commons.gradle'

android {
    compileSdkVersion 30
    buildFeatures {

        dataBinding = true

        // for view binding:
        // viewBinding = true
    }

    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.androidcodingchallenge"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables{
            useSupportLibrary = true
        }

        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
}

dependencies {
    implementation project(':data')
    implementation project(':domain')
    implementation project(':presentation')
    implementation project(':remote')
    implementation project(':cache')
    implementation project(':common')
    implementation project(':device')

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation "com.google.android.material:material:$material_version"

    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    implementation 'androidx.cardview:cardview:1.0.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    //navigation component
//    implementation "androidx.navigation:navigation-fragment-ktx:2.3.2"
//    implementation "androidx.navigation:navigation-ui-ktx:2.3.2"

    // UI
    implementation "com.github.bumptech.glide:glide:$glide_version"
    kapt "com.github.bumptech.glide:compiler:$glide_version"

    // Ktx
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0"
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0'
    implementation "androidx.fragment:fragment-ktx:1.3.0"

    // Navigation
    implementation "android.arch.navigation:navigation-fragment-ktx:$version_navigation"
    implementation "android.arch.navigation:navigation-ui-ktx:$version_navigation"

    //viewpager2
    implementation "androidx.viewpager2:viewpager2:1.0.0"

    implementation 'com.thoughtbot:expandablerecyclerview:1.3'
    implementation 'com.thoughtbot:expandablecheckrecyclerview:1.4'

    //indicator
    implementation 'me.relex:circleindicator:2.1.4'
    //lottie
    implementation "com.airbnb.android:lottie:3.4.1"
    //datastore
    implementation "androidx.datastore:datastore-preferences:1.0.0-alpha06"

    implementation 'androidx.hilt:hilt-navigation-fragment:1.0.0-alpha03'

    //LeakCanary
    debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"

    //Retrofit
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'

    //multidex
    implementation 'com.android.support:multidex:1.0.3'

}

below commons.gradle

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

androidExtensions {
    experimental = true
}

android {
//    compileSdkVersion Versions.compileSdkVersion
//    buildToolsVersion Versions.buildTool
//    defaultConfig {
//        minSdkVersion Versions.minSdk
//        targetSdkVersion Versions.targetSdk
//        versionCode Releases.versionCode
//        versionName Releases.versionName
//        vectorDrawables.useSupportLibrary = true
//    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    kapt {
        javacOptions {
            // Increase the max count of errors from annotation processors.
            // Default is 100.
            option("-Xmaxerrs", 500)
        }
        // Configure kapt to correct error types for Hilt
        correctErrorTypes true
    }

    buildFeatures{
        dataBinding = true
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    lintOptions {
        abortOnError false
    }

    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

dependencies {
    //Loads packaged libraries in the libs folder
    implementation fileTree(dir: 'libs', include: ['*.jar'])

//    implementation KotlinLibraries.kotlin
//    implementation AndroidLibraries.coreKtx
//
//    implementation Libraries.hilt
//    implementation Libraries.hiltJetpack
//    kapt Libraries.hiltCompiler
//    kapt Libraries.hiltJetpackCompiler
//
//    // For instrumentation tests
//    androidTestImplementation Libraries.hiltAndroidTest
//    kaptAndroidTest Libraries.hiltAndroidTestCompiler
//
//    // For local unit tests
//    testImplementation Libraries.hiltAndroidUnitTest
//    kaptTest Libraries.hiltAndroidUnitTestCompiler
//
//    implementation TestLibraries.androidTestRunner
//    implementation TestLibraries.junit
//    implementation TestLibraries.espresso
//    implementation TestLibraries.espressoContrib

    // Concurrency
    implementation "io.reactivex.rxjava2:rxkotlin:$rxkotlin_version"
    implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"


    //Hilt
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_androidx_version"
    kapt "androidx.hilt:hilt-compiler:$hilt_androidx_version"

    // Utils
    implementation "com.jakewharton.threetenabp:threetenabp:$threetenabp_version"


}

below build.gradle file

buildscript {
    ext{
        kotlin_version = "1.4.20"
        version_navigation = "2.3.5"
        hilt_version = '2.31.2-alpha'

        version_navigation = "2.3.5"
        version_lifecycle_extensions = "2.2.0"
        lifecycle_version = "2.2.0"
        hilt_androidx_version = "1.0.0-alpha03"

        material_version = "1.3.0"

        coroutines_version = "1.4.1"

        junit_version = "4.13"

        retrofit_version = "2.9.0"
        okHttp_version = "4.9.0"
        moshi_converter_version = '2.9.0'
        moshi_version = '1.11.0'

        mockwebserver_version = "4.9.0"
        robolectric_version = "4.4"
        mockito_version = "3.5.15"
        google_truth_version = "1.0"
        coroutines_test = "1.3.1"

        room_version = "2.3.0"

        threetenabp_version = "1.2.4"
        leakcanary_version = "2.4"
        timber_version = "4.7.1"

        glide_version = "4.11.0"
        androidsvg_version = "1.4"

        rxkotlin_version = "2.4.0"
        rxandroid_version = "2.1.1"

        google_services_version = "4.3.8"
    }

    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$version_navigation"

        classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        classpath "com.google.gms:google-services:$google_services_version"
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

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

what I have tried invalide cache restart

followed this issue tracker I have tried all suggested answer overthere it did not solve my problem ,Besides that, I run gradlew clean in android studio and it is giving following errors FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

  • What went wrong: Execution failed for task ':common:kaptDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction java.lang.reflect.InvocationTargetException (no error message)

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. ==============================================================================

2: Task failed with an exception.

  • What went wrong: Execution failed for task ':common:kaptReleaseKotlin'.

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction java.lang.reflect.InvocationTargetException (no error message)

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. ==============================================================================

note that I am using Android Studio Arctic Fox

I want to know where exactly I am making mistake

1 Answer 1

2

I fixed it my problem by updating current kotlin version to latest version and moshi version to 1.12.0

3
  • 1
    what is Moshi here?
    – Yash
    Feb 26, 2022 at 15:19
  • 1
    What was your fix ? Apr 8, 2022 at 8:04
  • 1
    it doesn´t work!
    – Jorgesys
    Aug 8, 2022 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.