1: Task failed with an exception.
-----------
* What went wrong:
A problem was found with the configuration of task ':mylibrary:extractDebugAnnotations' (type 'ExtractAnnotations').
- Gradle detected a problem with the following location: 'E:\xxx\Test2\mylibrary\src\main\java'.
Reason: Task ':mylibrary:extractDebugAnnotations' uses this output of task ':mylibrary:greendao' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
Possible solutions:
1. Declare task ':mylibrary:greendao' as an input of ':dblibrary:extractDebugAnnotations'.
2. Declare an explicit dependency on ':mylibrary:greendao' from ':dblibrary:extractDebugAnnotations' using Task#dependsOn.
3. Declare an explicit dependency on ':mylibrary:greendao' from ':mylibrary:extractDebugAnnotations' using Task#mustRunAfter.
For more information, please refer to https://docs.gradle.org/8.7/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
Android Studio Koala | 2024.1.1
gradle插件版本 8.5.0
gradle版本8.7
在最新版的AndroidStudio和gradle上面使用greenDao,按照之前的配置,会产生上面的错误。
在project的build.gradle里面引入greenDao的插件
dependencies {
classpath 'com.android.tools.build:gradle:8.5.0'
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.1' // add plugin
}
注意在gradle8.0以上要引入greenDao插件版本为3.3.1,greenDao版本用3.3.0,在主module app的build.gradle下导入
apply plugin: 'org.greenrobot.greendao'
android {
...
greendao {
schemaVersion 1
targetGenDir 'src/main/java'
//生成DaoMaster、DaoSession、Dao包名的目录
daoPackage 'com.android.sdlc.mylibrary.gen'
}
}
dependencies {
//greenDao数据库
implementation 'org.greenrobot:greendao:3.3.0'
...
}
导入完成之后写一个类
然后Build -> make project 会自动生成DaoMaster、DaoSession、Dao文件,然后就就可以使用了,按照以前的用法这样是没问题的。
在最新版本下的主module里引入greenDao这样写也没问题,
重点出问题的地方来了:
在最新版AndroidStudio和最新版gradle 8.7 下,如果在project里面创建子module,在子module里使用greenDao的话,如果按照上面的写法就会出现最上面的那个问题。
既然出问题了就要解决,直接上处理方法:
重点重点重点,重要的事情说三遍
只需将targetGenDir这一行配置去掉就可以了,其他都不变。去掉这一行配置之后make project之后你会发现在找不到自动生成的DaoMaster、DaoSession、Dao 这些文件,没关系,这些都是自动生成的不可编辑的文件,实际是已经生成了,可以直接使用,只是没有像之前那样直接显示出来而已,具体为什么变成这样了,需要查询官方资料了解。