Android GreenDAO 适配 AGP 8.0+

在 Android 中使用 GreenDao,由于 GreenDao 现在不维护,所以更新到新版本的 Gradle 经常出问题,在这记录一些升级遇到的问题,并且记录解决方案。

博主博客

  • https://blog.uso6.com
  • https://blog.csdn.net/dxk539687357

一、‘:app:greendao’ without declaring an explicit or implicit dependency.

1.1 Gradle 8.0.2

从 Gradle 7.x 升级到 Gradle 8.x 会遇到以下错误

org.gradle.internal.execution.WorkValidationException: Some problems were found with the configuration of task ':app:greendao' (type 'DefaultTask').
	- Gradle detected a problem with the following location: '/Users/nukix/AndroidStudioProjects/Demo/app/src/main/java'.
	
Reason: Task ':app:compileOfficialDebugKotlin' uses this output of task ':app: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 ':app:greendao' as an input of ':app:compileOfficialDebugKotlin'.
	2. Declare an explicit dependency on ':app:greendao' from ':app:compileOfficialDebugKotlin' using Task#dependsOn.
	3. Declare an explicit dependency on ':app:greendao' from ':app:compileOfficialDebugKotlin' using Task#mustRunAfter.

Please refer to https://docs.gradle.org/8.0.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
groovy

修改项目根目录 build.gradle 为以下内容

buildscript {
	repositories {
		google()
		mavenCentral()
	}

	dependencies {
		classpath 'com.android.tools.build:gradle:8.0.2'
		classpath 'org.greenrobot:greendao-gradle-plugin:3.3.1'
	}
}

修改 app 模块下的 build.grade 为以下内容

plugins {
	id 'com.android.application'
	id 'org.jetbrains.kotlin.android'
	id 'kotlin-kapt'
	id 'org.greenrobot.greendao'
}

greendao {
	schemaVersion 1
	daoPackage 'com.uso6.greendao'
	targetGenDir 'src/main/java'
}

tasks.whenTaskAdded { task ->
    if (task.name.matches("compile\w*Kotlin")) {
        task.dependsOn('greendao')
    }
}

dependencies {
	implementation 'org.greenrobot:greendao:3.3.0'
}
kotlin

修改项目根目录 build.gradle.kts 为以下内容

buildscript {
	val agp_version: String by extra("8.1.2")
	
	repositories {
		gradlePluginPortal()
	}

	dependencies {
		...
		classpath("org.greenrobot:greendao-gradle-plugin:3.3.1")
	}
}

plugins {
	id("com.android.application") version("8.0.2") apply false
	id("com.android.library") version("7.4.1") apply false
	id("org.jetbrains.kotlin.android") version("1.8.10") apply false
}

修改 app 模块下的 build.grade.kts 为以下内容

plugins {
	id("com.android.application")
	id("org.jetbrains.kotlin.android")
    id("kotlin-kapt") 
    id("org.greenrobot.greendao")
}

android {
	...
	greendao {
		schemaVersion = 1
		daoPackage = "com.uso6.greendao"
		targetGenDir = file("src/main/java")
	}

	tasks.configureEach {
		if (this.name.matches(Regex("compile\\w*Kotlin"))) {
			this.dependsOn("greendao")
		}
	}
}

dependencies {
	implementation("org.greenrobot:greendao:3.3.0")
}

1.2 Gradle 8.12.1

升级到 8.12.1 会遇到以下错误(不一定是 8.12.1 版本,只是我在这个版本遇到了)

org.gradle.internal.execution.WorkValidationException: A problem was found with the configuration of task ':app:kaptGenerateStubsDebugKotlin' (type 'KaptGenerateStubsTask').
  - Gradle detected a problem with the following location: '/Users/nukix/AndroidStudioProjects/Demo/app/src/main/java'.

Reason: Task ':app:kaptGenerateStubsDebugKotlin' uses this output of task ':app: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 ':app:greendao' as an input of ':app:kaptGenerateStubsDebugKotlin'.
      2. Declare an explicit dependency on ':app:greendao' from ':app:kaptGenerateStubsDebugKotlin' using Task#dependsOn.
      3. Declare an explicit dependency on ':app:greendao' from ':app:kaptGenerateStubsDebugKotlin' using Task#mustRunAfter.
    
    For more information, please refer to https://docs.gradle.org/8.12.1/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.

这个问题跟上面的几乎一样,所以增加一个判断条件即可。

groovy

修改 app 模块下的 build.grade 为以下内容

tasks.whenTaskAdded { task ->
    if (task.name.matches("compile\w*Kotlin") 
	    || task.name.matches("kapt\\w*Kotlin")) {
        task.dependsOn('greendao')
    }
}
kotlin

修改 app 模块下的 build.grade.kts 为以下内容

tasks.configureEach {
	if (this.name.matches(Regex("compile\\w*Kotlin")) || this.name.matches(Regex("kapt\\w*Kotlin"))) {
		this.dependsOn("greendao")
	}
}

1.3 在 GitHub issues 里面有个老哥给出来的答案更完整,可以直接使用。

groovy
tasks.whenTaskAdded { task ->
    if (task.name.matches("\\w*compile\\w*Kotlin") 
	    || task.name.matches("\\w*kaptGenerateStubs\\w*Kotlin")
	    || task.name.matches("\\w*kapt\\w*Kotlin")) {
        task.dependsOn('greendao')
    }
}
kotlin
tasks.configureEach {
	if (this.name.matches(Regex("\\w*compile\\w*Kotlin")) || this.name.matches(Regex("\\w*kaptGenerateStubs\\w*Kotlin")) || this.name.matches(Regex("\\w*kapt\\w*Kotlin"))) {
		this.dependsOn("greendao")
	}
}

参考文献

  • The project encountered errors after updating Gradle Version 7.6.1 to Gradle Version 8.0+

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/973366.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

从传统到轻量级5G:网络架构演变与优化路径

轻量级5G​​​​ 随着5G技术的不断发展,通信网络架构正经历着前所未有的变革。传统的5G核心网架构虽然在性能和容量方面表现出色,但在灵活性、部署效率以及成本控制方面却面临一些挑战。为了应对日益复杂的通信需求,轻量级5G核心网成为了一种…

搭建Kubernetes (K8s) 集群----Centos系统

前期准备 准备3台Linux虚拟机(CentOS系统),参考 https://carry.blog.csdn.net/article/details/144578009https://carry.blog.csdn.net/article/details/144578009搭建Docker环境,参考 https://carry.blog.csdn.net/article/de…

OpenSSL实验

文章目录 一、OpenSSL安装二、OpenSSL配置常见路径查找配置文件的方法示例**1. 配置文件结构****2. 主要段落及其作用****(1) 默认段(Default Section)****(2) OID段(OID Section)****(3) CA相关段(CA Section&#xf…

51单片机-按键

1、独立按键 1.1、按键介绍 轻触开关是一种电子开关,使用时,轻轻按开关按钮就可使开关接通,当松开手时,开关断开。 1.2、独立按键原理 按键在闭合和断开时,触点会存在抖动现象。P2\P3\P1都是准双向IO口,…

DeepSeek动画视频全攻略:从架构到本地部署

DeepSeek 本身并不直接生成动画视频,而是通过与一系列先进的 AI 工具和传统软件协作,完成动画视频的制作任务。这一独特的架构模式,使得 DeepSeek 在动画视频创作领域发挥着不可或缺的辅助作用。其核心流程主要包括脚本生成、画面设计、视频合成与后期处理这几个关键环节。 …

EasyRTC智能硬件:实时畅联、沉浸互动、消音护航

在当今智能硬件迅猛发展的时代,音视频通讯技术已成为设备与用户、设备与设备间不可或缺的沟通纽带。而EasyRTC,凭借其无可比拟的实时性能、卓越的互动感受以及强大的交互实力,正逐步演变为智能硬件领域的“超级动力”核心。特别是其倾力打造的…

[AI相关]Unity的C#代码如何简写

是一个某培训机构的飞行棋教学源码 不知道,是否有人想知道怎么可以简写 (这个问AI,DeepSeek也应该找不到答案的) 静态变量 属性引用 单例 注入 一些UnityEvent特性就不说了。。。 IL 注入 运算符号改写

ubuntu 执行 sudo apt-get update 报错

记录一下,遇到这个问题了,网络上看到的解决办法,亲测有效 执行sudo apt-get update ,却报以下错误,“SECURITY: URL redirect target contains control characters rejecting ” 经检查发现,/etc/apt/source.list 下的…

蓝桥杯学习大纲

(致酷德与热爱算法、编程的小伙伴们) 在查阅了相当多的资料后,发现没有那篇博客、文章很符合我们备战蓝桥杯的学习路径。所以,干脆自己整理一篇,欢迎大家补充! 一、蓝桥必备高频考点 我们以此为重点学习…

【插件】前端生成word 文件

文章目录 1、背景2、方式一:html-docx-js2.1 具体代码2.2 前端生成word文件的样式2.3 总结 3、方式二:pizzip docxtemplater3.1 具体代码3.2 前端生成word文件的样式3.3 总结 4、参考链接 1、背景 在实际开发中,业务需要,需要把数…

4. grafana(7.5.17)功能菜单简介

点击可以返回home页面 搜索Dashboard 新建按钮:用户创建Dashboard、文件夹。以及导入外部(社区)Dashboard 用于查看活管理Dashboard,包括home、Manage、playlists、snapshots功能 explore(探索)&#x…

QT之改变鼠标样式

QT改变鼠标图片 资源路径如下 代码实现 QPixmap customCursorPixmap(":/images/mouse.png");QCursor customCursor(customCursorPixmap);QWidget::setCursor(customCursor); // 可以设置为整个窗口或特定控件QWidget::setCursor(); // 设置为透明光标&#xff0c…

ctfshow web入门 web11-web24

web11 web12 进来浏览网站,底部有一串数字,根据提示可能有用,访问robots.txt,发现禁止访问/admin/,进去看看发现需要输入用户名和密码,刚想爆破就猜对了,用户名是admin,密码是页面下…

大模型开发实战篇7:语音识别-语音转文字

语音识别大模型,是人工智能领域的一项重要技术,它能够将人类的语音转换为文本。近年来,随着深度学习技术的不断发展,语音识别大模型取得了显著的进展,并在各个领域得到了广泛应用。 主流语音识别大模型 目前&#xf…

基于Flask的租房信息可视化系统的设计与实现

【Flask】基于Flask的租房信息可视化系统的设计与实现(完整系统源码开发笔记详细部署教程)✅ 目录 一、项目简介二、项目界面展示三、项目视频展示 一、项目简介 随着互联网的快速发展,租房市场日益繁荣,信息量急剧增加&#xff…

记一次一波三折的众测SRC经历

视频教程和更多福利在我主页简介或专栏里 (不懂都可以来问我 专栏找我哦) 目录: 前言 波折一:RCE漏洞利用失败 波折二:SQL时间盲注 波折三:寻找管理后台 总结 前言 先谈个人SRC心得体会吧,我虽…

java每日精进 2.13 MySql迁移人大金仓

1.迁移数据库 1. 数据库创建语句 MySQL: CREATE DATABASE dbname; 人大金仓(Kingbase): 在人大金仓中,CREATE DATABASE 的语法通常相同,但可能需要特别注意字符集的指定(如果涉及到多语言支持…

【单臂路由配置】

【单臂路由配置】 设备接口IP子网网关vlanR1G0/0/1.1192.168.1.254255.255.255.0NAvlan10R1G0/0/1.2192.168.2.254255.255.255.0NAvlan20R1G0/0/1.3192.168.3.254255.255.255.0NAvlan30PC1e0/0/1192.168.1.1255.255.255.0192.168.1.254vlan10PC2e0/0/1192.168.2.1255.255.255.0…

NutUI内网离线部署

文章目录 官网拉取源代码到本地仓库修改源代码打包构建nginx反向代理部署访问内网离线地址 在网上找了一圈没有写NutUI内网离线部署的文档,花了1天时间研究下,终于解决了。 对于有在内网离线使用的小伙伴就可以参考使用了 如果还是不会联系UP主:QQ:10927…

【Linux AnolisOS】关于Docker的一系列问题。尤其是拉取东西时的网络问题,镜像源问题。

AnolisOS 8中使用Docker部署(全)_anolis安装docker-CSDN博客 从在虚拟机安装龙蜥到安装docker上面这篇文章写的很清晰了,我重点讲述我解决文章里面问题一些的方法。 问题1: docker: Get https://registry-1.docker.io/v2/: net/h…