## <center><h1>GreenDao Module for Android Studio</h1></center>
This project aims to provide a reusable instrument for easy and fast implementation of [GreenDao](http://greendao-orm.com/) database in every Android project. It consists of Java module - GreenDao database universal generator which is ready to be put in any project. By editing single line of code, point a path to your project where ready to use database files will be created. Usage of module is presented on exemplary project that is also included in the package.
## Quick Setup
<h3>1. Download module</h3>
Pull the package with exemplary project and generator from GitHub.
<h3>2. Add module to project</h3>
Place MyDaoGenerator anywhere you like in your project tree.
<h3>3. Connect generator with project</h3>
By editing ONLY `outputDir` parameter in <i>gradle.build</i> file point the direction where database files should be created:
project(':MyDaoGenerator') {
apply plugin: 'application'
apply plugin: 'java'
mainClassName = "pl.surecase.eu.MyDaoGenerator"
// edit output direction
outputDir = "../DaoExample/src/main/java-gen"
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('de.greenrobot:DaoGenerator:1.3.0')
}
task createDocs {
def docs = file(outputDir)
docs.mkdirs()
}
run {
args outputDir
}
}
Module provide DaoGenerator library on its own via Maven software tool. This library is necessary for creating GreenDao database files. Directory entered by user will be created if it doesn't exist and sent do java code as console argument.
<h3>4. Create database</h3>
MyDaoGenerator contains only one java class. It is a place where you can create your database accordingly to your needs. Example presented below is a creation of single object named <i> Box </i> that contains fields such as ID, Name, Slots and Description. You can learn how to modify this file by using [GreenDao documentation](http://greendao-orm.com/documentation/).
public class MyDaoGenerator {
public static void main(String args[]) throws Exception {
Schema schema = new Schema(3, "greendao");
Entity box = schema.addEntity("Box");
box.addIdProperty();
box.addStringProperty("name");
box.addIntProperty("slots");
box.addStringProperty("description");
new DaoGenerator().generateAll(schema, args[0]);
}
}
<h3>5. Run module </h3>
After pointing output path of your database files and creating your database code, you can run the module to generate files. Module isn't a part of your project. It is only a tool that you use to generate files - it isn't compiled during build of your project.
- To run MyDaoGenerator go to Gradle task section in Android Studio.
- Pick MyDaoGenerator from the Gradle project tree.
- Chose <b>run</b> task.
![gradleRun](https://github.com/SureCase/GreenDaoForAndroidStudio/blob/master/Screenshots/gradleRun.png?raw=true)
- Module has created files accordingly to content of MyDaoGenerator.class and in directory specified in `outputDir` parameter.
<h3>6. Make project aware of GreenDao files</h3>
To use GreenDao objects, project needs GreenDao library to be included.
- It is possible to get it by [downloading *.JAR file](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22de.greenrobot%22%20AND%20a%3A%22greendao%22).
or:
- Add Maven code to <i>gradle.build</i> file.
dependencies {
compile 'de.greenrobot:greendao:1.3.7'
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
greendaoforandroidstudio-master.zip (68个子文件)
GreenDaoForAndroidStudio-master
Screenshots
gradleRun.png 32KB
GreenDaoForAndroidStudio
gradlew 5KB
settings.gradle 41B
MyDaoGenerator
src
main
java
pl
surecase
eu
MyDaoGenerator.java 564B
build.gradle 481B
DaoExample
src
main
AndroidManifest.xml 913B
java-gen
greendao
Box.java 1KB
DaoMaster.java 2KB
BoxDao.java 4KB
DaoSession.java 1KB
res
drawable-hdpi
ic_launcher.png 9KB
menu
box_list_menu.xml 484B
edit_item_menu.xml 304B
drawable-mdpi
ic_launcher.png 5KB
layout
activity_edit_box.xml 3KB
item_box.xml 1KB
activity_box_list.xml 482B
drawable-xxhdpi
ic_launcher.png 19KB
drawable-xhdpi
ic_action_new.png 234B
ic_launcher.png 14KB
ic_action_discard.png 543B
ic_cancel.png 1KB
values
colors.xml 148B
ids.xml 237B
strings.xml 1KB
styles.xml 194B
dimens.xml 216B
java
pl
surecase
eu
greendaoexample
DaoExampleApplication.java 781B
ui
activity
EditBoxActivity.java 5KB
BoxListActivity.java 4KB
adapter
DbItemsAdapter.java 3KB
backend
repositories
BoxRepository.java 1KB
build.gradle 604B
.idea
libraries
support_v4_19_0_1.xml 464B
greendao_1_3_7.xml 503B
appcompat_v7_19_0_1.xml 398B
freemarker_2_3_19.xml 520B
DaoGenerator_1_3_0.xml 521B
misc.xml 872B
compiler.xml 711B
gradle.xml 629B
.name 24B
encodings.xml 166B
modules.xml 556B
scopes
scope_settings.xml 139B
copyright
profiles_settings.xml 74B
vcs.xml 166B
gradle
gradlew 5KB
wrapper
gradle-wrapper.properties 230B
gradle-wrapper.jar 49KB
gradle
wrapper
gradle-wrapper.properties 230B
gradle-wrapper.jar 49KB
.gradle
1.10
taskArtifacts
cache.properties.lock 17B
fileHashes.bin 18KB
outputFileStates.bin 18KB
taskArtifacts.bin 19KB
fileSnapshots.bin 19KB
cache.properties 30B
gradlew.bat 2KB
.gradle
1.10
taskArtifacts
outputFileStates.bin 20KB
taskArtifacts.bin 61KB
fileSnapshots.bin 1.05MB
cache.properties 30B
gradlew.bat 2KB
gradle.properties 853B
build.gradle 312B
README.md 4KB
.gitignore 400B
共 68 条
- 1
资源评论
laowangkingggg
- 粉丝: 150
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功