Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Note: Failed to read get kotlin metadata for ...etc, and type converter

after add room db dependencies and configuring it with my app, I got several errors, most of it is Failed to read get kotlin metadata for... although I do not use kotlin in my project, the second error is about TypeConverter for the variable private List<String> labels; I doing some search for how to add List or ArrayList as a TypeConverter but I didn't found soultion for that

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

here's my Entity db Class

@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 interface

@Dao
public interface ItemDao {

    @Insert
    void insert(Item item);

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

gradel dependencies


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"

}
like image 515
Dr Mido Avatar asked Mar 27 '19 15:03

Dr Mido


Video Answer


2 Answers

Seems the new room (ver 2.1.0-alpha06) uses kotlin in itself and has a bug in it. In my case downgrade room version was worked. Try this until google team release an update for fixing this. here is my dependencies:

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'
like image 167
Mahdi Moqadasi Avatar answered Oct 18 '22 04:10

Mahdi Moqadasi


Try adding the following dependency to your project repository:

buildscript {

   repositories {
       ...

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

   }
   dependencies {
       .....
   }
} 
like image 30
OKILIPA Avatar answered Oct 18 '22 04:10

OKILIPA