我正在尝试在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)不支持通过@Parcel实用程序类使用Parcels注释类的数组。相反,我建议使用List

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

10-03 00:38