无法在android studio中运行greendao生成器类文件

无法在android studio中运行greendao生成器类文件,android,android-studio,greendao,Android,Android Studio,Greendao,我在我的项目中使用了greendao来维护本地数据库 projectbuild.gradle buildscript { ext.kotlin_version = '1.1.2-4' repositories { maven { url 'https://maven.google.com' } jcenter() } dependencies { classpath 'com.

我在我的项目中使用了greendao来维护本地数据库

projectbuild.gradle

buildscript {
    ext.kotlin_version = '1.1.2-4'
    repositories {
        maven {
            url 'https://maven.google.com'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'org.greenrobot.greendao'

...

dependencies {...
compile 'org.greenrobot:greendao:3.2.2'
    compile project(':greendaolib')
}
apply plugin: 'java'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'org.greenrobot:greendao-generator:3.2.2'
}


public class MainGenerator {

    public static void main(String[] args)  throws Exception {

        //place where db folder will be created inside the project folder
        Schema schema = new Schema(1,"com.v_empowr.voicestry.database");

        //Entity i.e. Class to be stored in the database // ie table LOG
        Entity word_entity= schema.addEntity("LOG");

        word_entity.addIdProperty(); //It is the primary key for uniquely identifying a row

        word_entity.addStringProperty("text").notNull();  //Not null is SQL constrain

        //  ./app/src/main/java/   ----   com/codekrypt/greendao/db is the full path
        new DaoGenerator().generateAll(schema, "./app/src/main/java");

    }
}
android {
..

sourceSets {
        main{
            java.srcDirs = ['src/main/java','src/main/java-gen','../greendaolib/classes']

        }
    }
}
应用程序build.gradle

buildscript {
    ext.kotlin_version = '1.1.2-4'
    repositories {
        maven {
            url 'https://maven.google.com'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'org.greenrobot.greendao'

...

dependencies {...
compile 'org.greenrobot:greendao:3.2.2'
    compile project(':greendaolib')
}
apply plugin: 'java'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'org.greenrobot:greendao-generator:3.2.2'
}


public class MainGenerator {

    public static void main(String[] args)  throws Exception {

        //place where db folder will be created inside the project folder
        Schema schema = new Schema(1,"com.v_empowr.voicestry.database");

        //Entity i.e. Class to be stored in the database // ie table LOG
        Entity word_entity= schema.addEntity("LOG");

        word_entity.addIdProperty(); //It is the primary key for uniquely identifying a row

        word_entity.addStringProperty("text").notNull();  //Not null is SQL constrain

        //  ./app/src/main/java/   ----   com/codekrypt/greendao/db is the full path
        new DaoGenerator().generateAll(schema, "./app/src/main/java");

    }
}
android {
..

sourceSets {
        main{
            java.srcDirs = ['src/main/java','src/main/java-gen','../greendaolib/classes']

        }
    }
}
Greendaolib build.gradle

buildscript {
    ext.kotlin_version = '1.1.2-4'
    repositories {
        maven {
            url 'https://maven.google.com'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'org.greenrobot.greendao'

...

dependencies {...
compile 'org.greenrobot:greendao:3.2.2'
    compile project(':greendaolib')
}
apply plugin: 'java'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'org.greenrobot:greendao-generator:3.2.2'
}


public class MainGenerator {

    public static void main(String[] args)  throws Exception {

        //place where db folder will be created inside the project folder
        Schema schema = new Schema(1,"com.v_empowr.voicestry.database");

        //Entity i.e. Class to be stored in the database // ie table LOG
        Entity word_entity= schema.addEntity("LOG");

        word_entity.addIdProperty(); //It is the primary key for uniquely identifying a row

        word_entity.addStringProperty("text").notNull();  //Not null is SQL constrain

        //  ./app/src/main/java/   ----   com/codekrypt/greendao/db is the full path
        new DaoGenerator().generateAll(schema, "./app/src/main/java");

    }
}
android {
..

sourceSets {
        main{
            java.srcDirs = ['src/main/java','src/main/java-gen','../greendaolib/classes']

        }
    }
}
运行程序时出现错误消息

Exception in thread "main" java.lang.NoClassDefFoundError: org/greenrobot/greendao/generator/Schema
    at com.example.MainGenerator.main(MainGenerator.java:12)
Caused by: java.lang.ClassNotFoundException: org.greenrobot.greendao.generator.Schema
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more
这是我用的 安卓工作室3.0金丝雀1 建造#AI-171.4010489,建造于2017年5月16日 JRE:1.8.0_112-release-736 amd64 JVM:JetBrains s.r.o提供的OpenJDK 64位服务器虚拟机 Windows7.6.1

所以请建议我解决这个问题

应用程序内:build.gradle

buildscript {
    ext.kotlin_version = '1.1.2-4'
    repositories {
        maven {
            url 'https://maven.google.com'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'org.greenrobot.greendao'

...

dependencies {...
compile 'org.greenrobot:greendao:3.2.2'
    compile project(':greendaolib')
}
apply plugin: 'java'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'org.greenrobot:greendao-generator:3.2.2'
}


public class MainGenerator {

    public static void main(String[] args)  throws Exception {

        //place where db folder will be created inside the project folder
        Schema schema = new Schema(1,"com.v_empowr.voicestry.database");

        //Entity i.e. Class to be stored in the database // ie table LOG
        Entity word_entity= schema.addEntity("LOG");

        word_entity.addIdProperty(); //It is the primary key for uniquely identifying a row

        word_entity.addStringProperty("text").notNull();  //Not null is SQL constrain

        //  ./app/src/main/java/   ----   com/codekrypt/greendao/db is the full path
        new DaoGenerator().generateAll(schema, "./app/src/main/java");

    }
}
android {
..

sourceSets {
        main{
            java.srcDirs = ['src/main/java','src/main/java-gen','../greendaolib/classes']

        }
    }
}
在格林达利布格勒酒店

project(":greendaolib")
        {
            apply plugin: 'java'
            apply plugin: 'application'

            mainClassName = 'your main class full path'
            outputDatabase = 'classes/'

            dependencies {
                compile fileTree(include: ['*.jar'], dir: 'libs')
                 compile 'org.greenrobot:greendao-generator:3.2.2'
            }

            task createDirs {
                def dir = file(outputDatabase)
                dir.mkdir()
            }
            run {
                args outputDatabase
            }
        }
终于开始上课了