Android GreenDao找不到org.greenrobot.GreenDao.annotation*

Android GreenDao找不到org.greenrobot.GreenDao.annotation*,android,android-studio,greendao,Android,Android Studio,Greendao,我从绿道3.2开始。我在libs文件夹中添加了GreendaoJAR,并将其添加为库。我使用greendao生成器生成实体。它生成实体,但生成的实体包含一些注释,android studio在这些注释上给出了一个错误。它给出了一个找不到“org.greenrobot.greendao.annotation.*”的错误。如何解决此问题?为什么要将.jar放在libs文件夹中,而不使用Gradle进行依赖关系管理?这很快就会导致依赖地狱。这要容易得多 内部mainbuild.gradle: buil

我从绿道3.2开始。我在libs文件夹中添加了GreendaoJAR,并将其添加为库。我使用greendao生成器生成实体。它生成实体,但生成的实体包含一些注释,android studio在这些注释上给出了一个错误。它给出了一个找不到“org.greenrobot.greendao.annotation.*”的错误。如何解决此问题?

为什么要将.jar放在
libs
文件夹中,而不使用
Gradle
进行依赖关系管理?这很快就会导致依赖地狱。这要容易得多

内部main
build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.0'
    }
}
apply plugin: 'org.greenrobot.greendao'

dependencies {
    compile 'org.greenrobot:greendao:3.2.0'
}
内部应用程序
build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.0'
    }
}
apply plugin: 'org.greenrobot.greendao'

dependencies {
    compile 'org.greenrobot:greendao:3.2.0'
}

为什么要将.jar放在
libs
文件夹中,而不使用
Gradle
进行依赖关系管理?这很快就会导致依赖地狱。这要容易得多

内部main
build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.0'
    }
}
apply plugin: 'org.greenrobot.greendao'

dependencies {
    compile 'org.greenrobot:greendao:3.2.0'
}
内部应用程序
build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.0'
    }
}
apply plugin: 'org.greenrobot.greendao'

dependencies {
    compile 'org.greenrobot:greendao:3.2.0'
}

可能您没有在应用程序模块中添加库。首先,您可以使用gradle依赖项,而不是使用jar。在生成器项目中添加以下依赖项

compile 'org.greenrobot:greendao-generator:3.2.0'
发电机模块的梯度文件应该是这样的

    apply plugin: 'java'

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'org.greenrobot:greendao-generator:3.2.0'
    }
  apply plugin: 'com.android.application'

    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.2"

        defaultConfig {
            applicationId "com.tcs.a1003548.greendao"
            minSdkVersion 14
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:24.2.0'
        compile 'org.greenrobot:greendao:3.2.0'

    }
并在您的gradle文件(模块应用程序)中添加以下内容

    compile 'org.greenrobot:greendao:3.2.0'  
你的主gradle文件(模块应用程序)应该是这样的

    apply plugin: 'java'

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'org.greenrobot:greendao-generator:3.2.0'
    }
  apply plugin: 'com.android.application'

    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.2"

        defaultConfig {
            applicationId "com.tcs.a1003548.greendao"
            minSdkVersion 14
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:24.2.0'
        compile 'org.greenrobot:greendao:3.2.0'

    }

可能您没有在应用程序模块中添加库。首先,您可以使用gradle依赖项,而不是使用jar。在生成器项目中添加以下依赖项

compile 'org.greenrobot:greendao-generator:3.2.0'
发电机模块的梯度文件应该是这样的

    apply plugin: 'java'

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'org.greenrobot:greendao-generator:3.2.0'
    }
  apply plugin: 'com.android.application'

    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.2"

        defaultConfig {
            applicationId "com.tcs.a1003548.greendao"
            minSdkVersion 14
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:24.2.0'
        compile 'org.greenrobot:greendao:3.2.0'

    }
并在您的gradle文件(模块应用程序)中添加以下内容

    compile 'org.greenrobot:greendao:3.2.0'  
你的主gradle文件(模块应用程序)应该是这样的

    apply plugin: 'java'

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'org.greenrobot:greendao-generator:3.2.0'
    }
  apply plugin: 'com.android.application'

    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.2"

        defaultConfig {
            applicationId "com.tcs.a1003548.greendao"
            minSdkVersion 14
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:24.2.0'
        compile 'org.greenrobot:greendao:3.2.0'

    }

从项目中删除jar文件,并从build.gradle中删除编译文件('libs/greendao-3.2.0.jar')。检查我编辑的答案从项目中删除jar文件,并从build.gradle中删除编译文件('libs/greendao-3.2.0.jar')。检查我编辑的答案