Android | NoClassDefFoundError after second compile
Closed this issue · 3 comments
I've been having issues with missing PaperParcel classes the second time I compile my project. I'm not certain if PaperParcel is the culprit but only experience the issues with PaperParcel's generated classes.
Build Environment
- PaperParcel: 2.0.0
- Gradle: 3.3
- Kotlin: 1.1.1
- Kapt: 3
- Kotlin IntelliJ plugin: 1.1.1-release-Studio2.3-1
- Android Studio: 2.3
Project Setup
The project in question has two android libraries (api and app), both utilizing PaperParcel. Below is an example for one of the models in the api module:
package com.project.api.models
import android.os.Parcel
import android.os.Parcelable
import paperparcel.PaperParcel
import java.util.*
@PaperParcel
data class User(val id: Int,
val email: String,
val firstName: String,
val lastName: String,
val initials: String,
val phone: String? = null,
val dob: String? = null,
val profilePictureUrl: String? = null) : Parcelable {
companion object {
@JvmField val CREATOR = PaperParcelUser.CREATOR
}
override fun describeContents() = 0
override fun writeToParcel(dest: Parcel, flags: Int) {
PaperParcelUser.writeToParcel(this, dest, flags)
}
}
Issue
The first time I compile the project (after a clean) I see logs indicating the generated classes were properly moved into the destination folder:
[com.android.build.gradle.internal.transforms.JarMerger] addFolder(/api/build/intermediates/classes/release/com/project/api/models, com/project/api/models/): entry com/project/api/models/PaperParcelUser.class
Compiling the project again doesn't list this step and running the app eventually crashes when a generated class is referenced:
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.project.api.models.PaperParcelUser" on path: DexPathList ..."
Attempts to Resolve
- Disabling incremental builds for android and kotlin (suggested here)
- Removing
@JvmField
from CREATOR (suggested here)
Wow, so PaperParcelUser exists because the app compiled, but it's not included in the binary? Weird. This definitely doesn't sound like a bug with this library, it sounds like a build tools bug.
Are you using instant run? What about org.gradle.parallel=true
?
Ah ok, it sounds very much like parallel is your issue. Kapt3 doesn't work with it currently. Please vote for the issue!