Android Parceler library: Unable to find generated Parcelable class

3.3k views Asked by At

I'm trying to use the Parceler library in my Android Studio project. The project has two modules, one is the app itself and the other is a personal android core library containing various helpers and generic entities.

However, I've added the Parceler dependency in my core library because I need it there too, so in the library build.gradle I've added the following lines:

compile "org.parceler:parceler-api:1.0.4"
apt "org.parceler:parceler:1.0.4"

I've not specified these lines inside the app build.gradle file because the dependency from Parceler will be imported automatically.

In my app I've defined an entity that have to be Parcelable and which implementation is:

@Parcel
public class Course {
    public String name;

    public Course() { /*Required empty bean constructor*/ }

    public Course(String name) {
        this.name = name;
    }
}

But when I try to do

Course[] courses = ...retrieved from server...
Parcelable p = Parcels.wrap(courses);

The framework fires the following exception:

org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable class for [Lit.bmsoftware.lotoapp.network.entity.Course;, verify that your class is configured properly and that the Parcelable class [Lit.bmsoftware.lotoapp.network.entity.Course;$$Parcelable is generated by Parceler.

I've already read various posts for that exception but I can't find a solution for my problem.

Could anyone help me?

Thanks in advance :)

EDIT: build.gradle file

plugins {
    id "me.tatarka.retrolambda" version "3.2.4"
}

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

retrolambda {
    jvmArgs '-noverify' // Issues: using Google Play Services causes retrolambda to fail
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "it.bmsoftware.lotoapp"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    signingConfigs {
        release {
            storeFile file("*******.keystore")
            storePassword "********"
            keyAlias "*******"
            keyPassword "*******"
        }
    }
    buildTypes {
        release {
            //noinspection GroovyAssignabilityCheck
            signingConfig signingConfigs.release
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    repositories {
        mavenCentral()
        mavenLocal()
    }

    dataBinding {
        enabled = true
    }

    // Fixes bug in Data Binding library (Source folders generated at incorrect location)
    //    applicationVariants.all { variant ->
    //        def variantName = variant.name.capitalize()
    //        def inputDir    = "${buildDir}/intermediates/classes/${variant.dirName}"
    //        def sourceDir   = "${buildDir}/generated/source/dataBinding/${variant.dirName}"
    //        def copyTask    = tasks.create(name: "dataBindingFix${variantName}", type: Copy) {
    //            from inputDir
    //            into sourceDir
    //            include '**/*.java'
    //        }
    //        tasks["generate${variantName}Sources"].dependsOn copyTask
    //        variant.addJavaSourceFoldersToModel new File(sourceDir)
    //    }

    return true
}

ext {
    supportLibVersion = '23.1.1'  // variable that can be referenced to keep support libs consistent
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile project(':core')

    compile "com.android.support:support-v13:${supportLibVersion}"
    compile "com.android.support:design:${supportLibVersion}"
    //compile "com.android.support:percent:${supportLibVersion}"

    compile "com.android.support:recyclerview-v7:${supportLibVersion}"
    compile "com.android.support:cardview-v7:${supportLibVersion}"

    compile "org.parceler:parceler-api:1.0.4"
    apt "org.parceler:parceler:1.0.4"

    compile 'jp.wasabeef:recyclerview-animators:2.2.0'
}
1

There are 1 answers

1
John Ericksen On BEST ANSWER

The current release (1.0.4) does not support arrays of @Parcel annotated classes via the Parcels utility class. Instead, I'd suggest using a List:

List<Course> courses = ...retrieved from server...
Parcelable p = Parcels.wrap(courses);