注意:无法读取获取等等的kotlin元数据,并输入转换器

问题描述 投票:7回答:2

添加房间数据库依赖关系并使用我的应用程序配置它后,我得到了几个错误,大部分是Failed to read get kotlin metadata for...虽然我不在我的项目中使用kotlin,第二个错误是关于变量private List<String> labels;的TypeConverter我做了一些搜索如何添加列表或ArrayList作为TypeConverter,但我没有找到灵魂

> Task :app:processDebugAnnotationsWithJavac
D:\Courses\Java\Android Projects\ProCSIS\app\src\main\java\www\pro_cs_is\com\Item.java:20: Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@2f693bda
public class Item implements Serializable {
       ^
D:\Courses\Java\Android Projects\ProCSIS\app\src\main\java\www\pro_cs_is\com\Item.java:67: error: Cannot figure out how to save this field into database. You can consider adding a type converter for it.
    private List<String> labels;
                         ^
D:\Courses\Java\Android Projects\ProCSIS\app\src\main\java\www\pro_cs_is\com\ItemDao.java:13: Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@5179217e
    @Insert
    ^
D:\Courses\Java\Android Projects\ProCSIS\app\src\main\java\www\pro_cs_is\com\Item.java:20: Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@3aa7911
public class Item implements Serializable {
       ^
D:\Courses\Java\Android Projects\ProCSIS\app\src\main\java\www\pro_cs_is\com\ItemDao.java:13: Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@19ce5518
    @Insert
    ^

这是我的实体数据库类

@Entity(tableName = "Item")
public class Item implements Serializable {

    @SerializedName("kind")
    @Expose
    private String kind;
    @SerializedName("id")
    @Expose
    @PrimaryKey
    @NonNull
    private String id;
    @SerializedName("blog")
    @Expose

    @Ignore
    private Blog blog;
    @SerializedName("published")
    @Expose
    private String published;
    @SerializedName("updated")
    @Expose
    private String updated;
    @SerializedName("etag")
    @Expose
    private String etag;
    @SerializedName("url")
    @Expose
    private String url;
    @SerializedName("selfLink")
    @Expose
    private String selfLink;
    @SerializedName("title")
    @Expose
    private String title;
    @SerializedName("content")
    @Expose
    private String content;
    @SerializedName("author")
    @Expose
    @Ignore
    private Author author;
    @SerializedName("replies")
    @Expose
    @Ignore
    private Replies replies;
    @SerializedName("labels")
    @Expose

    private List<String> labels; // here is I should use type converter


    public String getKind() {
        return kind;
    }

    public void setKind(String kind) {
        this.kind = kind;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Blog getBlog() {
        return blog;
    }

    public void setBlog(Blog blog) {
        this.blog = blog;
    }

    public String getPublished() {
        return published;
    }

    public void setPublished(String published) {
        this.published = published;
    }

    public String getUpdated() {
        return updated;
    }

    public void setUpdated(String updated) {
        this.updated = updated;
    }

    public String getEtag() {
        return etag;
    }

    public void setEtag(String etag) {
        this.etag = etag;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getSelfLink() {
        return selfLink;
    }

    public void setSelfLink(String selfLink) {
        this.selfLink = selfLink;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Author getAuthor() {
        return author;
    }

    public void setAuthor(Author author) {
        this.author = author;
    }

    public Replies getReplies() {
        return replies;
    }

    public void setReplies(Replies replies) {
        this.replies = replies;
    }


    public List<String> getLabels() {
        return labels;
    }

    public void setLabels(List<String> labels) {
        this.labels = labels;
    }

}

ItemDao界面

@Dao
public interface ItemDao {

    @Insert
    void insert(Item item);

    @Query("SELECT * FROM Item")
    LiveData<List<Item>> getItems();
}

gradle依赖


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.1.0-alpha04'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.firebase:firebase-messaging:17.5.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha4', {
        exclude group: 'com.google.code.findbugs'
    })
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    implementation 'org.jsoup:jsoup:1.11.3'
    implementation 'com.google.apis:google-api-services-blogger:v3-rev57-1.23.0'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.j256.ormlite:ormlite-android:5.1'
    implementation 'com.j256.ormlite:ormlite-core:5.1'
    implementation 'org.apache.commons:commons-lang3:3.8.1'
    implementation 'com.github.ybq:Android-SpinKit:1.2.0'
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.8@aar') {
        transitive = true
    }

    implementation 'androidx.multidex:multidex:2.0.1'
    // ViewModel and LiveData
    dependencies {
        def lifecycle_version = "2.0.0"

        // ViewModel and LiveData
        implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
        implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
        implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
        implementation 'android.arch.lifecycle:extensions:1.1.1'
        // optional - ReactiveStreams support for LiveData
        implementation "androidx.lifecycle:lifecycle-reactivestreams:$lifecycle_version"
        // For Kotlin use lifecycle-reactivestreams-ktx
        // optional - Test helpers for LiveData
        testImplementation "androidx.arch.core:core-testing:$lifecycle_version"
    }
    configurations {
        all*.exclude group: 'com.google.guava', module: 'listenablefuture'
    }
    implementation 'com.android.support:customtabs:28.3.0'
    implementation 'org.jetbrains:annotations:15.0'
    implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
    implementation 'com.google.firebase:firebase-ads:17.2.0'

    def room_version = "2.1.0-alpha06"

    implementation "androidx.room:room-runtime:$room_version"
    annotationProcessor "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor

    // Test helpers
    testImplementation "androidx.room:room-testing:$room_version"

}
android android-gradle android-room androidx android-jetpack
2个回答
9
投票

似乎新的room(ver 2.1.0-alpha06)本身使用kotlin并且有一个错误。在我的情况下降级room版本工作。试试这个,直到谷歌团队发布更新以解决此问题。这是我的依赖:

implementation 'androidx.room:room-runtime:2.1.0-alpha04'
annotationProcessor 'androidx.room:room-compiler:2.1.0-alpha04'
implementation 'androidx.room:room-rxjava2:2.1.0-alpha04'

1
投票

尝试将以下依赖项添加到项目存储库:

buildscript {

   repositories {
       ...

       maven {
           url 'https://kotlin.bintray.com/kotlinx/'
       }

   }
   dependencies {
       .....
   }
} 
© www.soinside.com 2019 - 2024. All rights reserved.