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

时间:2016-01-29 15:39:26

标签: java android parcelable parceler

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

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

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

我没有在app 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 :(得分:2)

当前版本(1.0.4)不支持通过@Parcel实用程序类的Parcels带注释类的数组。相反,我建议使用List

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