在配置greenDao項目的時候,經常會遇到這樣的問題,全部的提示如下
Unable to find method ‘org.gradle.api.tasks.TaskInputs.file(Ljava/lang/Object;)Lorg/gradle/api/tasks/TaskInputs;’. Possible causes for this unexpected error include: Gradle’s dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network) The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart) Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project. In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
導致這個問題的原因是gradle版本的問題,在我這里出現這個問題時的配置如下
android studio 4.0.0 gradle:6.1.1 gradle Plugin:3.2.0 greenDao: 3.2.0
修改之后可以正常使用的配置如下
android studio 4.0.0 gradle:6.1.1 gradle Plugin:3.3.0 greenDao: 3.2.0
正確配置,外面的build.gradle的buildscript中配置gradle
buildscript { repositories { google() jcenter() maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } } dependencies { classpath "com.android.tools.build:gradle:4.0.0-rc01" // 使用butterknife需要實現以下方法 classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }
在里面的build.gradle中配置
apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' // 添加應用依賴插件 android { compileSdkVersion 29 defaultConfig { applicationId "com.example.easygreendao" minSdkVersion 16 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } // 配置GreenDao基本參數 greendao { schemaVersion 1 //當前數據庫版本 } } dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' //greendao implementation 'org.greenrobot:greendao:3.2.0' // add library implementation 'org.greenrobot:greendao-generator:3.2.0' // add library implementation 'com.github.yuweiguocn:GreenDaoUpgradeHelper:v2.1.0' }
經過上面配置,可以正常編譯運行。