square / moshi

A modern JSON library for Kotlin and Java.
https://square.github.io/moshi/1.x/
Apache License 2.0
9.76k stars 760 forks source link

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

Closed ArcherEmiya05 closed 3 years ago

ArcherEmiya05 commented 3 years ago

I was just started learning Retrofit2 with Moshi but having difficulty during compilation/building.

This is the error from Build Output

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

This is what my app level gradle file looks like

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'com.google.firebase.crashlytics'
}

android {
    compileSdkVersion 30

    defaultConfig {
        applicationId "com.app.app"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {
            debuggable true
            minifyEnabled true
            shrinkResources true
            multiDexEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            multiDexEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.0-M2'

    //Required: Google Play Services Ads Identifier (If publishing to Google Play)
    implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'

    //Required: Install Referrer (If publishing to Google Play)
    implementation 'com.android.installreferrer:installreferrer:2.2'

    implementation 'com.google.firebase:firebase-config:20.0.4'
    implementation 'com.google.firebase:firebase-firestore:22.1.2'
    implementation 'com.google.firebase:firebase-analytics:18.0.2'
    implementation 'com.google.firebase:firebase-messaging:21.0.1'
    implementation 'com.google.firebase:firebase-crashlytics:17.4.1'
    implementation 'com.google.firebase:firebase-inappmessaging:19.1.5'
    implementation 'com.google.firebase:firebase-inappmessaging-display:19.1.5'

    // FirebaseUI for Firebase Auth
    implementation 'com.firebaseui:firebase-ui-auth:7.1.1'

    implementation 'com.google.firebase:firebase-auth:20.0.3'

    implementation 'com.google.android:flexbox:1.0.0'
    implementation 'com.github.mahimrocky:TagView:1.0.3'

    kapt('com.squareup.moshi:moshi-kotlin-codegen:1.11.0')
    implementation 'com.squareup.moshi:moshi-kotlin:1.11.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'

    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'

}
apply plugin: 'com.google.gms.google-services'

This is project level gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven { url "https://jitpack.io" }
        maven { url "https://google.bintray.com/flexbox-layout" }
        maven { url = "https://dl.bintray.com/kotlin/kotlin-eap" }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.0-alpha10"
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0-M2'

        classpath 'com.google.gms:google-services:4.3.5'

        // Add the Crashlytics Gradle plugin.
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven { url "https://jitpack.io" }
        maven { url "https://google.bintray.com/flexbox-layout" }
        maven { url = "https://dl.bintray.com/kotlin/kotlin-eap" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
JakeWharton commented 3 years ago

Dupe of #1324

JakeWharton commented 3 years ago

Fix is merged to master already. Just waiting on a release.

ArcherEmiya05 commented 3 years ago

Fix is merged to master already. Just waiting on a release.

Thanks for immediate answer, will just downgrade to M1 for now

gajicm93 commented 3 years ago

This is happening again to me on Kotlin 1.5.21 and 1.5.30 when I include kapt('com.squareup.moshi:moshi-kotlin-codegen:1.12.0') plugin..

ZacSweers commented 3 years ago

That's not a useful description. Please elaborate with actionable information

gajicm93 commented 3 years ago

That's not a useful description. Please elaborate with actionable information

Now I can't reproduce it anymore. I'm updating an old project with some old library versions, so it's possible that Moshi was clashing with some old library I updated in the meantime, and now it's working fine..

Sorry for the annoyance.

IlKor1610 commented 2 years ago

Upgrade the moshi version to 1.13.0

dependencies {

//Moshi
def moshiVersion = '1.13.0'
implementation "com.squareup.moshi:moshi:$moshiVersion"
implementation "com.squareup.moshi:moshi-kotlin:$moshiVersion"
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion"

}

ZacSweers commented 2 years ago

That's not a useful description. Please elaborate with actionable information