ルームデータベースの依存関係を追加してアプリで構成した後、いくつかのエラーが発生しました。プロジェクトでkotlinを使用していませんが、ほとんどがFailed to read get kotlin metadata for...
です。2番目のエラーは、変数private List<String> labels;
のTypeConverterに関するものです。 Listまたは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();
}
gradel依存関係
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"
}
新しい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'
次の依存関係をプロジェクトリポジトリに追加してみてください。
buildscript {
repositories {
...
maven {
url 'https://kotlin.bintray.com/kotlinx/'
}
}
dependencies {
.....
}
}