赞
踩
greendao在项目的build.gradle中配置和以前一样,在项目中build.gradle自动生成结构和以前不一样,在build.gradle中仍然可以使用老的 buildscript,来配置需要的插件:
buildscript { dependencies { classpath 'org.greenrobot:greendao-gradle-plugin:3.3.1' } repositories { mavenCentral() } } plugins { id 'com.android.application' version '8.0.1' apply false id 'com.android.library' version '8.0.1' apply false }
编译后会报
A problem occurred configuring project ':app'.
> Could not create task ':app:greendaoPrepare'.
> Cannot use @TaskAction annotation on method DetectEntityCandidatesTask.execute() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.
发现问题发生在org.greenrobot:greendao-gradle-plugin:3.3.0的问题上,这是由于 Gradle 8 删除了已弃用的IncrementalTaskInputs API造成的。
升级到3.3.1版本就可以了,其他不变:
classpath org.greenrobot:greendao-gradle-plugin:3.3.1
app build.gradle也贴一下
plugins { id 'com.android.application' id 'org.greenrobot.greendao' } android { namespace 'com.library.myappdao' compileSdk 33 defaultConfig { applicationId "com.library.myappdao" minSdk 24 targetSdk 33 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } greendao{ schemaVersion 1 daoPackage 'com.library.myappdao.greendao' } } dependencies { implementation 'org.greenrobot:greendao:3.3.0' implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.recyclerview:recyclerview:1.1.0' }
写一个bean文件
package com.example.basetest;
@Entity
public class UserBean {
@Id(autoincrement = true)
private Long id;
private String username;
private String password;
}
build下工程会自动生成 DaoMaster、DaoSession、 UserBeanDao
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。