0

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'
}
Androidian
  • 1,035
  • 1
  • 16
  • 40
  • Are your libraries aars? Can you determine if any Parcelable source code is generated? – John Ericksen Feb 01 '16 at 21:03
  • I notice that parcelable source cose is generated only for classes inside the core library module, but if I add Parceler dependencies in app module too, AndroidStudio is not able to build the project anymore. – Androidian Feb 02 '16 at 08:19
  • Have you tried to set parcelsIndex=false in the library http://parceler.org/#avoiding_parcels_indexing? – John Ericksen Feb 02 '16 at 22:54
  • @JohnEricksen I've just try to set parcelsIndex=false in all classes (library and app). Still doesn't work and Parceler returns the same error :( – Androidian Feb 04 '16 at 14:26
  • I've added the library dependency in the application build.gradle file too and now the $$Parcelable class is generated correctly, but still same error. – Androidian Feb 04 '16 at 17:01
  • Another alternative is to use Parceler only from your root application by mapping to your library classes via the @ParcelClass annotation http://parceler.org/#classes_without_java_source – John Ericksen Feb 05 '16 at 18:17
  • @JohnEricksen I've tried to use Parceler only from my root application by mapping library classes via ParcelClass annotation as you said. Still same error but I notice that $$Parcelable classes are generated inside build->generated->source->dataBinding folder. I think that's due to the fact that I've enabled android data binding in mi project. Could be this the problem? If yes, how could I fix it? – Androidian Feb 11 '16 at 10:11
  • I've made a try with [this tutorial](https://medium.com/@fabioCollini/android-data-binding-f9f9d3afc761#.jea03idlv) and all works fine. I've edited my post to add my build.gradle file, maybe there is something wrong. – Androidian Feb 11 '16 at 10:54
  • I haven't heard of any incompatabilities around Android data binding and annotation processors, but it may be what is causing your problem. I will need some more information to be helpful here... If you'd like I could take a look at a sample project if you could share one with me. You can find my email address on my GitHub profile if you want to contact me directly. – John Ericksen Feb 11 '16 at 14:04
  • @JohnEricksen I've wrote you a mail with a sample project that reproduce the problem, thank you very much for help! :) – Androidian Feb 12 '16 at 17:20

1 Answers1

2

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);
John Ericksen
  • 10,995
  • 4
  • 45
  • 75