'Why I get Execution failed for task ':app:kaptDebugKotlin' if I use Moshi?
Hy
I created an app which uses dagger, room, Moshi, Retrofit etc...
It works correctly until I add this line to my Model class : @JsonClass(generateAdapter = true)
After that I get this error:
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
java.lang.reflect.InvocationTargetException (no error message)
I don't know what is the problem, beacuse my another app is uses Moshi, and it works good.
I added all of the Moshi dependencies, and plugins
My gradle settings:
buildTypes {
all {
buildConfigField 'String', 'API_URL', "\"$apiurl\""
lintOptions {
abortOnError true
//ignoreWarnings true
fatal 'MissingTranslation', 'ExtraTranslation'
}
}
debug {
//applicationIdSuffix ".debug"
ext.enableCrashlytics = false
ext.alwaysUpdateBuildId = false
multiDexEnabled true
}
staged {
signingConfig signingConfigs.debug
//applicationIdSuffix ".staged"
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', getDefaultProguardFile('proguard-android-optimize.txt')
matchingFallbacks = ['debug']
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro', getDefaultProguardFile('proguard-android-optimize.txt')
}
}
ApiModule:
@Provides
@Singleton
fun provideMoshi(): Moshi {
return Moshi.Builder()
.add(DateConverter())
.add(BigDecimalConverer())
.add(KotlinJsonAdapterFactory())
.build()
}
@Provides
@Singleton
fun provideAuthApi(@Named("base_url") url: String, moshi: Moshi): AuthApi {
var builder = OkHttpClient.Builder()
builder = BuildTypeInitializations.setupInterceptor(builder)
return Retrofit.Builder()
.baseUrl(url)
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.addConverterFactory(MoshiConverterFactory.create(moshi))
.client(builder.build())
.build()
.create(AuthApi::class.java)
}
Solution 1:[1]
Finally, I resolved. I used 1.8.x version of moshi, and when I updated to 1.11.0 the erros is gone
Solution 2:[2]
I had the same issue as you but, for me, the solution was adding implementation "com.squareup.moshi:moshi-adapters:$1.12.0"
to build.gradle
file
Solution 3:[3]
I had a similar problem where InvocationTargetException
was being thrown by kapt
when processing Room entities, saying something about a nonexisting type. After a long investigation I found out the library which contained the entities also used Moshi and tagged one entity with @Json
annotations, but since the app which used this library did not import Moshi kapt couldn't resolve the type which caused the error. The solution was importing Moshi in the lib via "api" instead of "implementation" or importing Moshi in the client app via "implementation".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andreas1234 |
Solution 2 | Daniel S. |
Solution 3 | Miloš Černilovský |