gpt4 book ai didi

android - Gradle 错误 : Could not find method android()

转载 作者:行者123 更新时间:2023-12-03 06:03:49 25 4
gpt4 key购买 nike

我已经尝试了很多来解决这个问题。我正在尝试使用 gradle 从命令行构建我的 android 应用程序,但出现以下错误

A problem occurred evaluating root project 'android-build'.
> Could not find method android() for arguments [build_bumi6pcyg9xxwmbnm52kyqutw$_run_closure1@6ba7383d] on root project 'android-build'.

有人可以指出我错了吗?

以下是我的 build.gradle
buildscript {
repositories {
maven {
url "http://repo1.maven.org/maven2"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}

android {
compileSdkVersion 23
buildToolsVersion "21.1.2"

def versionPropsFile = file('version.properties')

if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()

versionProps.load(new FileInputStream(versionPropsFile))

def code = versionProps['VERSION_CODE'].toInteger() + 1

versionProps['VERSION_CODE']=code.toString()
versionProps.store(versionPropsFile.newWriter(), null)

defaultConfig {
versionCode code
versionName "1.1"
minSdkVersion 14
targetSdkVersion 18
}
}
else {
throw new GradleException("Could not read version.properties!")
}
}

最佳答案

您需要在模块 build.gradle 文件的第一行添加此配置:

apply plugin: 'com.android.application'

如 android 的 developer guide 中所述:

The first line in the build configuration applies the Android plugin for Gradle to this build and makes the android {} block available to specify Android-specific build options.

关于android - Gradle 错误 : Could not find method android(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39985471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com