android - ParcelCreator lint 抑制不起作用

标签 android kotlin android-gradle-plugin parcelable kotlin-extension

我正在尝试添加 Parcelize 实现,但它似乎不起作用。

这是我项目的 gradle 的样子:

buildscript {
ext.kotlin_version = '1.2.30'

repositories {
    maven { url "https://jitpack.io" }
    google()
    jcenter()    }
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"

    //Realm as ORM
    classpath "io.realm:realm-gradle-plugin:4.3.3"
}
}

allprojects {
repositories {
    maven { url "https://jitpack.io" }
    google()
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

应用的构建等级:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

apply plugin: 'realm-android'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.----.----"
    minSdkVersion 21
    targetSdkVersion 27
    multiDexEnabled true
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

kapt {
generateStubs = true
}

dependencies {

def supportVersion = '27.1.0'

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:' + supportVersion
implementation 'com.android.support:preference-v14:' + supportVersion
implementation 'com.android.support:support-v4:' + supportVersion
implementation 'com.android.support:design:' + supportVersion
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
//noinspection GradleCompatible
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
// Dagger 2
implementation 'com.google.dagger:dagger:2.14.1'
kapt 'com.google.dagger:dagger-compiler:2.14.1'

// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
implementation 'com.squareup.moshi:moshi-kotlin:1.5.0'

//Rx
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'

//Glide
implementation 'com.github.bumptech.glide:glide:4.6.1'
implementation 'jp.wasabeef:glide-transformations:3.1.1'
kapt 'com.github.bumptech.glide:compiler:4.6.1'

//Recycler view, Card view
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'

//video player
implementation 'com.google.android.exoplayer:exoplayer:r2.5.1'

//circle image view
implementation 'de.hdodenhof:circleimageview:2.2.0'

//page indicator
implementation 'com.romandanylyk:pageindicatorview:1.0.0'

//spinner
implementation 'com.jaredrummler:material-spinner:1.2.4'

}
repositories {
mavenCentral()
}

这是我尝试实现 Parcelize 的模型:

@SuppressLint("ParcelCreator")
@Parcelize
data class StatusMessagesSender(@Json(name = "firstName")
                            val firstName: String?,
                            @Json(name = "lastName")
                            val lastName: String?,
                            @Json(name = "pushDeviceToken")
                            val pushDeviceToken: String?,
                            @Json(name = "address")
                            val address: String?,
                            @Json(name = "phoneNumber")
                            val phoneNumber: String?,
                            @Json(name = "name")
                            val name: String?,
                            @Json(name = "userId")
                            val userId: String?,
                            @Json(name = "age")
                            val age: Int?,
                            @Json(name = "email")
                            val email: String?): Parcelable

所以即使我添加了这个注解@SuppressLint("ParcelCreator"),也没有任何改变。没有它它仍然给我同样的错误:

“类‘StatusMessagesSender’不是抽象的,也没有实现抽象成员 public abstract fun writeToParcel(dest: Parcel!, flags: Int): Unit defined in android.os.Parcelable”

任何人都可以告诉我是否在这里做错了什么?

最佳答案

将下一个代码放在 android { } 中,放在您的应用程序的文件 build.gradle 中。

androidExtensions {
    experimental = true
}

关于android - ParcelCreator lint 抑制不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49602783/

相关文章:

elasticsearch - 我是如何达到 index.mapping.total_fields.limit 的?

android - com.github.PhilJay :MPAndroidChart library 的问题

android - 在Kotlin中共享具有 Intent 的 ImageView 的图像

java - 如何在 Android 中创建包含额外内容和过渡的 bundle

android - SugarORM 删除 log.i

android - 如何删除android页面顶部的应用程序栏?

kotlin - 如何从json构造我的Kotlin API类? (使用莫西)

android - 从Gradle构建APK时设置 'buildNumber'和 'versionNumber'

android - 进程意外退出,AAPT2错误

android - 错误:error: expected float but got (raw string) match-parent