简体   繁体   English

找不到参数 org.gradle.api.Project 的方法 android()

[英]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.

相关问题 无法为 org.gradle.api.Project 类型的项目“:app”的参数找到方法 buildTypes() - Could not find method buildTypes() for arguments on project ':app' of type org.gradle.api.Project Android Studio:“无法获得类型为 org.gradle.api.Project 的项目的未知属性‘VERSION_NAME’” - Android Studio : “Could not get unknown property 'VERSION_NAME' for project of type org.gradle.api.Project” 无法为 org.gradle.api.Project 类型的根项目“[redacted]”获取未知属性“artifactory_contextUrl” - Could not get unknown property 'artifactory_contextUrl' for root project '[redacted]' of type org.gradle.api.Project 无法为org.gradle.api.Project类型的根项目“MyApplication3”获取未知属性“删除” - Could not get unknown property 'Delete' for root project 'MyApplication3' of type org.gradle.api.Project 无法获得类型为org.gradle.api.Project的项目':app'的未知属性'VERSION_CODE' - Could not get unknown property 'VERSION_CODE' for project ':app' of type org.gradle.api.Project 无法为 org.gradle.api.Project 类型的项目 ':library' 获取未知属性 'VERSION_NAME' - Could not get unknown property 'VERSION_NAME' for project ':library' of type org.gradle.api.Project 从gradle org.gradle.api.Project获取ClassLoader? - Get ClassLoader from gradle org.gradle.api.Project? groovy.lang.MissingPropertyException:无法为类型为org.gradle.api.Project的项目':flamingo'设置未知属性'versionKey' - groovy.lang.MissingPropertyException: Could not set unknown property 'versionKey' for project ':flamingo' of type org.gradle.api.Project Gradle在根项目上找不到参数“()”作为参数 - Gradle Could not find method “() for arguments on root project 在 org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler 类型的存储库容器上找不到 arguments [] 的方法 jCenter() - Could not find method jCenter() for arguments [] on repository container of type org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM