Android 使用Greendao gradle 出現 Error:Unable to find method 'org.gradle.api.tasks.TaskInputs.file(Ljava/lang/Object;)
錯誤截圖如下:
出現此gradle sync的錯誤原因是:
gradle 版本 和 greendao 版本不兼容
筆者本地Android 開發環境如下:
Android Studio 2.1.1. + gradle 2.10 + greendao 3.2.2
解決方案:
一、升高gradle 的版本 到 3.5
也就是
Android Studio 2.1.1. + gradle 3.5 + greendao 3.2.2
是個可行的方案
二、降低greendao 版本到 3.0.1
也就是
Android Studio 2.1.1. + gradle 2.10 + greendao 3.0.1
是個可行的方案
筆者采用的是第二個方案
具體配置如下:
項目下build.gradle
buildscript { repositories { maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' classpath 'org.greenrobot:greendao-gradle-plugin:3.0.0' } } allprojects { repositories { maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} } } task clean(type: Delete) { delete rootProject.buildDir }
app/build.gradle 下
apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' android { compileSdkVersion 23 buildToolsVersion "28.0.3" defaultConfig { applicationId "com.jack.testmd" minSdkVersion 19 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } greendao { schemaVersion 1 targetGenDir 'src/main/java' daoPackage "${android.defaultConfig.applicationId}.greendao" } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' *** compile 'org.greenrobot:greendao:3.0.1' }
okay,修改完成之后,再點擊 sync ,就可以了!
本博客地址: wukong1688
本文原文地址:https://www.cnblogs.com/wukong1688/p/10705096.html
轉載請著名出處!謝謝~~