注意:无法读取... etc的get kotlin元数据并键入转换器

时间:2019-03-27 15:35:52

标签: android android-gradle android-room androidx android-jetpack

添加Room db依赖性并使用我的应用对其进行配置后,我遇到了几个错误,尽管我没有在项目中使用kotlin,但大多数错误是Failed to read get kotlin metadata for...,第二个错误是关于变量{{的TypeConverter 1}}我在寻找如何将List或ArrayList添加为TypeConverter的方法,但是我没有为此而生

private List<String> labels;

这是我的Entity db Class

> 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
    ^

ItemDao界面

@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;
    }

}

等级依赖

@Dao
public interface ItemDao {

    @Insert
    void insert(Item item);

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

2 个答案:

答案 0 :(得分:9)

似乎新的room(ver 2.1.0-alpha06)本身使用kotlin并存在错误。在我的情况下,降级room版本有效。 尝试此操作,直到Google团队发布修复此问题的更新。 这是我的依赖项:

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 :(得分:1)

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

buildscript {

   repositories {
       ...

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

   }
   dependencies {
       .....
   }
}