gpt4 book ai didi

android - 找不到 Gradle DSL 方法 : 'android()' opening project in android studio 1. 4

转载 作者:行者123 更新时间:2023-11-29 01:26:45 25 4
gpt4 key购买 nike

我使用 Eclipse 编写 android 应用程序,现在我想使用 android studio。现在我是 android studio 的新手,我不太了解 gradle。我打开并使用 android studio 创建的项目。但是当我运行它时,这给了我以下错误:

Error:(17, 0) Gradle DSL method not found: 'android()' Possible causes:

  • The project 'sheidaamin-AndSt' may be using a version of Gradle that does not contain the method. Gradle settings
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • 我的 build.gradle 是:

    buildscript {
    repositories {
    jcenter()
    }

    dependencies {
    classpath 'com.android.tools.build:gradle:1.3.0'
    } } allprojects {
    repositories {
    jcenter()
    } }

    android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2' } dependencies { }

    有人知道我的项目设置有什么问题吗?

    最佳答案

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

    在 Android Studio 中你有这样的结构:

    root
    |--app
    |----build.gradle
    |--build.gradle //top level
    |--settings.gradle

    在顶级文件中,您不能使用 android block 。

    在顶级文件中,只需使用如下内容:

    buildscript {
    repositories {
    jcenter()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:1.3.1'
    }
    }

    allprojects {
    repositories {
    jcenter()
    }
    }

    您必须将 android block 移动到 app/build.gradle 文件中

    apply plugin: 'com.android.application'

    android {

    compileSdkVersion XX
    buildToolsVersion "XX"

    defaultConfig {
    //
    }

    }
    dependencies {
    //
    }

    关于android - 找不到 Gradle DSL 方法 : 'android()' opening project in android studio 1. 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33591176/

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