【问题标题】:Could not find method android()找不到方法 android()
【发布时间】:2020-03-12 17:37:46
【问题描述】:

错误日志:

错误:找不到参数的方法 android() [build_szu6u1qudhn719nxb58vfd0f$_run_closure1@1fcc37a7] 在根 项目“prueva2”。

这是我的 build.gradle:

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'

    defaultConfig {
        applicationId 'com.MyApp'
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    lintOptions {
        abortOnError false
    }

    buildscript {
        repositories {
            google() // For Gradle 4.0+
            maven { url 'https://maven.google.com' }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.0'

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

    allprojects {
        repositories {
            jcenter()
            maven
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    }
}

gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.6-all.zip

这可能是什么问题,有什么解决办法吗?

【问题讨论】:

  • 看到了,不知道改什么
  • 你不应该只看到它。您应该仔细阅读并查看示例。
  • 看起来您正在将顶级 build.gradle 中的项目配置与模块级 build.gradle 中的模块配置混合在一起。 android 的东西只进入模块级别,你需要应用 android 插件。另外,gradle 2.6 太旧了,考虑使用更新的版本,比如 5.6.4。
  • distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip*** 还是一样

标签: android android-studio gradle build


【解决方案1】:

您使用了错误 build.gradle 文件。

您不能在顶级文件中定义 android 块。

您必须删除您的

中的这部分
android {
    compileSdkVersion 19
    buildToolsVersion '25.0.2'
    dexOptions {
        incremental true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
}
dependencies {compile files('app/libs/junit-4.12-JavaDoc.jar')
}
apply plugin: 'maven'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 2023-04-05
    相关资源
    最近更新 更多