[英]Could not find method android() for arguments org.gradle.api.Project
Getting a bug, when I try to compile my project in studio , i have search quite a bit with no real solution to it遇到一个错误,当我尝试在 Studio 中编译我的项目时,我搜索了很多,但没有真正的解决方案
Error:(17, 0) Could not find method android() for arguments [build_a7zf1o8ge4ow4uolz6kqzw5ov$_run_closure2@19201053] on root project 'booksStudioDir' of type org.gradle.api.Project.错误:(17, 0) 在 org.gradle.api.Project 类型的根项目“booksStudioDir”上找不到参数 [build_a7zf1o8ge4ow4uolz6kqzw5ov$_run_closure2@19201053] 的方法 android()。
This is a sample of my build/gradle file这是我的构建/gradle 文件的示例
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 21
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.peade.time"
minSdkVersion 10
targetSdkVersion 13
}
signingConfigs {
release {
storeFile file("/home/bestman/Desktop/mkey/key")
storePassword "androidkeys"
keyAlias "peade"
keyPassword "yes1234"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
}
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
compile 'com.edmodo:cropper:1.0.1'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.itextpdf:itextpdf:5.5.6'
// compile files('libs/commons-lang3-3.3.2.jar')
compile files('libs/dropbox-android-sdk-1.6.1.jar')
// compile files('libs/httpmime-4.0.3.jar')
compile files('libs/json_simple-1.1.jar')
compile files('libs/picasso-2.5.2.jar')
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
transitive = true;
}
compile project(':owncloud')
}
There are two build.gradle files.有两个 build.gradle 文件。 One is in the top-level holder, and the other is in module holder.
一个在顶层支架中,另一个在模块支架中。
Below is an example.下面是一个例子。
Top-level build.gradle:顶级 build.gradle:
https://github.com/nickbutcher/plaid/blob/master/build.gradle https://github.com/nickbutcher/plaid/blob/master/build.gradle
module's build.gradle:模块的 build.gradle:
https://github.com/nickbutcher/plaid/blob/master/app/build.gradle https://github.com/nickbutcher/plaid/blob/master/app/build.gradle
The android
block should be in module's build.gradle . android
块应该在模块的 build.gradle 中。 I guess you must have defined the android
block in top-level build.gradle which is causing the error.我猜您一定在顶级 build.gradle 中定义了导致错误的
android
块。
I had same problem if your android block is in module's build.gradle and use google services, just add these 2 lines before android block:如果您的 android 块在模块的 build.gradle 中并使用谷歌服务,我会遇到同样的问题,只需在 android 块之前添加以下两行:
apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services'
Invalidate Cache and restart使缓存无效并重新启动
Go to : File/Invalidate Cache/Click on Invalidate and Restart This should solve your problem for you.转到:文件/无效缓存/单击无效并重新启动这应该可以为您解决问题。
buildscript {
ext.versions = [
'compileSdk' : 27,
'targetSdk' : 27,
'buildTools' : '27.0.3',
'butterknife' : '8.8.1',
'glide' : '4.6.1',
'kotlin' : '1.2.21',
'retrofit' : '2.3.0',
'supportLibrary': '27.0.2'
]
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha01'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.