1. 按照官方文档配置Gradle
http://objectbox.io/documentation/introduction/
// In your root build.gradle file:
buildscript {
ext.objectboxVersion = '1.4.0'
repositories {
jcenter()
maven { url "http://objectbox.net/beta-repo/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
}
}
allprojects {
repositories {
jcenter()
maven { url "http://objectbox.net/beta-repo/" }
}
}
// In your (app) module build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'io.objectbox'
同步项目后就自动完成依赖添加
2. 创建任意一个 @Entity class
!!!注意这时候先不要在Application下添加
boxStore = MyObjectBox.builder().androidContext(App.this).build();
此时添加了也会一直提示找不到MyObjectBox
3. rebuild project
此时就可以在Application下使用MyObjectBox了
MyObjectBox是在build阶段生成的,而且项目必须有@Entity 注解类它才会被生成,所以必须添加@Entity类 然后 rebuild 后才能找到