因為要將greenDao替換掉,研究了下用什么數(shù)據(jù)庫武学,后來選用Realm祭往!
GreenDao由商業(yè)公司greenrobot維護,但該公司在3年前就將重心轉(zhuǎn)移到新的數(shù)據(jù)庫ObjectBox火窒,
在最近一年已經(jīng)停止維護GreenDao硼补。
該項目僅開源了SDK部分的代碼,Gradle插件部分代碼并未開源沛鸵。由于沒有源碼括勺,
大量bug出現(xiàn)了數(shù)年都無法修復,在最新的開發(fā)環(huán)境下已經(jīng)難以編譯曲掰。預期2019年以后疾捍,
Android官方在Android Plugin 4.0刪除廢棄API后,GreenDAO將徹底不能使用栏妖。
greenrobot官方以無時間處理為由拖延拒絕提供插件源碼乱豆,導致該項目無法被社區(qū)維護。
Gradle團隊官方也曾介入吊趾,但greenrobot仍然無任何回應宛裕。
開發(fā)過程中遇到查看數(shù)據(jù)庫問題!之前都是用greendao時用facebook的stetho特別好用论泛!
因為Realm和Objectbox都是NoSql的揩尸,所以以前那種xx.db形式查看不了了
Realm官方是有介紹的,因為他們的數(shù)據(jù)庫格式是是xxx.realm屁奏,所以需要使用他們自己的工具查看
Realm Studio mac,linux,windows都有支持
但是不得不吐槽下岩榆,我是windows7系統(tǒng),realm studio只支持windows8.1以上系統(tǒng)
所以在windows7上使用Realm Studio只能放棄了
這里使用stetho_realm+chrome
但是git:stetho-realm最新更新時間是2年前了,接入還是有各種問題勇边,中間差點放棄使用Realm
可能會報各種錯誤犹撒,如
java.lang.NoClassDefFoundError Lio/realm/internal/SharedRealm$Durability
java.lang.NoClassDefFoundError: Failed resolution of: Lio/realm/internal/LinkView;
java.lang.NoClassDefFoundError Lio/realm/internal/SharedGroup
不過還是解決了,只是不知道隨著時間的推移粒褒,后面會不會再出現(xiàn)問題
好了正式介紹如何接入stetho_realm+chrome
1.在你的根build.gradle下识颊,或者app的build.gradle下都可以
maven { url 'https://github.com/WickeDev/stetho-realm/raw/master/maven-repo' }
以免遇到各種問題,我是在app的build.gradle下加入的
repositories {
maven { url 'https://github.com/WickeDev/stetho-realm/raw/master/maven-repo' }
}
dependencies {
debugApi 'com.facebook.stetho:stetho:1.5.1'
debugApi 'com.uphyca:stetho_realm:2.3.0'
}
注意:url地址奕坟,不是 maven {url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo' }
順便說下祥款,我用的Realm是:
classpath "io.realm:realm-gradle-plugin:5.11.0"
2.在application的onCreate下執(zhí)行:
Stetho.initialize( Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
.build())
網(wǎng)上也有如下配置的:(看注釋應該就知道什么意思了,但是我按照如下接入的時候chrome中還是打不開月杉,然后把withDeleteIfMigrationNeeded(true)去掉就可以了镰踏,大家可以自己測試)
Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(
RealmInspectorModulesProvider.builder(this)
.withDeleteIfMigrationNeeded(true) //if there is any changes in database schema then rebuild bd.
.withMetaTables() //extract table meta data
.withLimit(10000) //by default limit of data id 250, but you can increase with this
.build()
)
.build());
完成之后,運行你的代碼沙合,觸發(fā)數(shù)據(jù)存儲之后
在chrome瀏覽器中輸入:chrome://inspect
選中你自己項目的那一項
注意:有時候確定已經(jīng)接入沒有問題奠伪,但是在Web SQL下就是看不到xxx.realm,我也遇到過這個問題首懈,弄了半天!
我是如下解決的:
1.代碼中修改xxx.realm的名字或者version之后绊率,應用卸載重裝
2.換手機等等
總會出現(xiàn)的!究履!