ParcelCreator lint抑制不起作用

时间:2018-04-01 21:25:16

标签: android kotlin android-gradle 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
}

应用程序构建gradle:

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"),也没有任何变化。没有它,它仍然会给我同样的错误:

" Class' StatusMessagesSender'不是抽象的,也没有实现抽象成员公共抽象乐趣writeToParcel(dest:parcel!,flags:Int):在android.os.Parcelable中定义的单位"

任何人都可以判断我在这里做错了什么?

2 个答案:

答案 0 :(得分:1)

android { }中的下一个代码放入App的文件build.gradle中。

androidExtensions {
    experimental = true
}

答案 1 :(得分:0)

这是一个你可以忽略的已知问题,它已经用kotlin 1.2.31修复,所以只需在你的gradle文件中更新kotlin