gpt4 book ai didi

java - Android Parceler库: Unable to find generated Parcelable class

转载 作者:行者123 更新时间:2023-12-02 03:59:10 27 4
gpt4 key购买 nike

我正在尝试在我的 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 的依赖项将自动导入。

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

@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 实用程序类创建 @Parcel 注解类的数组。相反,我建议使用 List:

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

关于java - Android Parceler库: Unable to find generated Parcelable class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35088329/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com