数据库
首页 > 数据库> > AS4.x中java/kotlin使用objectBox数据库无法找到MyObjectBox类

AS4.x中java/kotlin使用objectBox数据库无法找到MyObjectBox类

作者:互联网

目录

一、java下引入objectBox

二、kotlin下引入objectBox

三、参考


一、java下引入objectBox

1.build.gradle (project level):

buildscript {
    ext.objectboxVersion = '2.9.1'
    repositories {
        maven {
            url 'http://maven.aliyun.com/nexus/content/groups/public/'
        }
    }
    dependencies {
        classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
    }
}

2.build.gradle (module level):

apply plugin: 'io.objectbox' // after applying Android plugin

3.增加一个entity

import io.objectbox.annotation.Entity;
import io.objectbox.annotation.Id;

@Entity
public class Test {
    @Id long id;
}

4.build项目,才能得到MyObjectBox类

二、kotlin下引入objectBox

1.build.gradle (project level):

buildscript {
    ext.kotlin_version = '1.4.31'
    ext.objectboxVersion = '2.8.1'
    repositories {
        maven {
            url 'http://maven.aliyun.com/nexus/content/groups/public/'
        }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
    }
}

2.build.gradle (module level): 

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

dependencies {
    implementation "io.objectbox:objectbox-android:$objectboxVersion"
    implementation "io.objectbox:objectbox-kotlin:$objectboxVersion"
    annotationProcessor "io.objectbox:objectbox-processor:$objectboxVersion"
}

apply plugin: 'io.objectbox' // after applying Android plugin

3.增加一个entity

import io.objectbox.annotation.Entity
import io.objectbox.annotation.Id

@Entity
data class Note(
        @Id var id: Long = 0,
        var text: String? = null,
        var comment: String? = null
)

4.build项目,才能得到MyObjectBox类

三、参考

1.github不稳定 如何解决github.io访问不稳定问题?

2.java和kotlin语言互转

3.Android Studio 4.1 kotlin不能直接引用控件

4.Kotlin初体验(一)-引入Android Studio

5.ObjectBox数据库使用说明

 

 

标签:MyObjectBox,java,AS4,kotlin,plugin,gradle,objectbox,io,objectboxVersion
来源: https://blog.csdn.net/lyl0530/article/details/117336474