Android Parceler 库:无法找到生成的 Parcelable class

Android Parceler library: Unable to find generated Parcelable class

我正在尝试在我的 Android Studio 项目中使用 Parceler 库。 该项目有两个模块,一个是应用程序本身,另一个是包含各种助手和通用实体的个人 android 核心库。

但是,我在我的核心库中添加了 Parceler 依赖项,因为我也需要它,所以在库中 build.gradle 我添加了以下行:

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

我没有在应用 build.gradle 文件中指定这些行,因为来自 Parceler 的依赖项将自动导入。

在我的应用程序中,我定义了一个必须是 Parcelable 的实体,其实现是:

@Parcel
public class Course {
    public String name;

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

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

但是当我尝试做的时候

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

框架触发以下异常:

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.

我已经阅读了有关该异常的各种帖子,但找不到解决我的问题的方法。

谁能帮帮我?

提前致谢:)

编辑:build.gradle 文件

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.0.4) 不支持通过 Parcels 实用程序 class 注释 class 的 @Parcel 数组。相反,我建议使用 List:

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