Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未找到Android Studio Gradle DSL方法:';android()错误(17,0)_Android_Android Gradle Plugin_Dsl - Fatal编程技术网

未找到Android Studio Gradle DSL方法:';android()错误(17,0)

未找到Android Studio Gradle DSL方法:';android()错误(17,0),android,android-gradle-plugin,dsl,Android,Android Gradle Plugin,Dsl,我正在尝试在Android Studio中运行我的项目,但出现以下错误: 我跟踪了很多消息来源,只是为了让它运行起来,并在这里结束了,但不知道还能做什么 如何将此项目配置为运行 build.gradle: // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories {

我正在尝试在Android Studio中运行我的项目,但出现以下错误:

我跟踪了很多消息来源,只是为了让它运行起来,并在这里结束了,但不知道还能做什么

如何将此项目配置为运行

build.gradle:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.9.+'
        }
    }

    allprojects {
        repositories {
            mavenCentral()
        }
    }

    android {
        compileSdkVersion 19
        buildToolsVersion "19.1" 
    }
include ':app'
sdk.dir=C\:\\Users\\KJA\\AppData\\Local\\Android\\sdk
# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
设置。渐变:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.9.+'
        }
    }

    allprojects {
        repositories {
            mavenCentral()
        }
    }

    android {
        compileSdkVersion 19
        buildToolsVersion "19.1" 
    }
include ':app'
sdk.dir=C\:\\Users\\KJA\\AppData\\Local\\Android\\sdk
# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
本地。属性:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.9.+'
        }
    }

    allprojects {
        repositories {
            mavenCentral()
        }
    }

    android {
        compileSdkVersion 19
        buildToolsVersion "19.1" 
    }
include ':app'
sdk.dir=C\:\\Users\\KJA\\AppData\\Local\\Android\\sdk
# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
渐变属性:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.9.+'
        }
    }

    allprojects {
        repositories {
            mavenCentral()
        }
    }

    android {
        compileSdkVersion 19
        buildToolsVersion "19.1" 
    }
include ':app'
sdk.dir=C\:\\Users\\KJA\\AppData\\Local\\Android\\sdk
# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

我继续从您提供的链接下载了该项目:

由于这是一个老教程,您只需升级软件gradle、android构建工具和插件

确保您拥有最新的Gradle和Android Studio:
build.gradle: app/build.gradle: 然后运行gradle:
在您的顶级
build.gradle
中,您似乎拥有代码

android {
   compileSdkVersion 19
   buildToolsVersion "19.1" 
}

您不能将此代码放在顶层
build.gradle
,因为android构建插件尚未加载。您可以在应用程序级别
build.gradle
中定义编译版本和生成工具版本。我已尝试通过以下步骤管理此问题:

删除顶级根目录文件中的android{…}块

调查

 compileSdkVersion 22
 buildToolsVersion "22.0.0"
app/gradle文件中的代码行这里应该只显示下面下拉列表中存在的一个版本,否则它将为download提供相同的选项


纠正渐变设置相当困难。如果你对Gradle了解不多,那就需要你学很多东西。相反,您可以执行以下操作:

1) 在新文件夹中启动新项目。选择与gradle问题项目相同的设置,但保持简单:选择一个空的主活动。 2) 删除…\NewProjectName\app\src\main文件夹中的所有文件 3) 将…\ProjectWithGradleProblem\app\src\main文件夹中的所有文件复制到…\NewProjectName\app\src\main文件夹。 4) 如果您正在使用测试项目(\ProjectWithGradleProblem\app\src\AndroidTest),您也可以这样做


如果Gradle安装正常,此方法可以正常工作。如果您只是安装了Android studio,而没有对其进行修改,Gradle安装应该可以。

我在尝试将Eclipse NDK项目导入Android studio时遇到了相同的错误。事实证明,对于Android Studio中的NDK支持,您需要使用新的gradle和Android插件(以及gradle 2.5+版本)。此插件需要更改模块的build.gradle文件。具体地说,“android{…}”对象应该位于“model{…}”对象中,如下所示:

apply plugin: 'com.android.model.application'
model {
    android {
    ....
    }
}
因此,如果您已更新gradle配置以使用新的gradle插件和新的android插件,但未更改模块的build.gradle语法,则可能会出现“gradle DSL method not found:'android()'”错误

我在这里准备了一个补丁文件,在评论中有一些进一步的解释:
这些是我在将原生音频ndk项目导入Android Studio后所做的更改

只需从root build.gradle中删除这些行即可

android {
compileSdkVersion 19
buildToolsVersion '19.1' }

现在再次尝试编译。它应该有用。

事实上,我尝试了很多组合,但都不起作用

但是当我用以下代码修改我的应用程序gradle文件时

 buildTypes {
        release {
            minifyEnabled false
        }
    }
通过删除该行

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

它工作正常:)干杯

不知什么原因,Android Studio错误地添加了Android() 方法,该方法位于顶级build.gradle文件中

只要删除这个方法,它就对我有用了

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.2'
}

更改为root build.gradle文件


对我来说,有效的方法是使用“File->New->project from Version Control”导入项目,然后选择在线源代码(例如GitHub)。这样,所有.gradle文件都是在导入中创建的

我也遇到了这些问题,只需删除下面的代码:

DELETE THESE LINES:
android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'
}

它成功了。

如果您已经安装了android-studio-bundle-143.2915827-windows,那么还有另一个解决方案 和gradle2.14

您可以在中验证 C:\Program Files\Android\Android Studio\gradle,如果您有gradle-2.14

那你必须去 C:\Users\\AndroidStudioProjects\android\u应用程序\

在这个build.gradle中,您输入了以下代码:

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
然后,转到C:\Users\Raul\AndroidStudioProjects\android\u app\Desnutricion\u infantil\app

在这个build.gradle中,您将:

apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '24.0.0'
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
}
您必须检查sdk版本和构建工具。 编译DK23版 buildToolsVersion“24.0.0”


保存所有更改并重新启动AndroidStudio,一切正常

从Github导入项目时发生此错误。这是因为项目的版本较旧。只需尝试从根目录中删除以下方法

安卓{ 编译DK19版 BuildTools版本“19.1” }

然后再试一次


我希望它能起作用。

我猜你刚刚开始这个项目。为什么不选择File->New Project,让它为您设置Gradle。另外,将你的gradle插件升级到1.0。这是一个来自在线资源的项目,我从导入:请查看我的答案。您只需升级项目。首先感谢您的额外努力!!但当我下载项目并导入时,只有一个build.gradle文件。你是如何得到两个,应用程序和项目的?我下载了zip文件,并通过命令行浏览了文件。此外,通常还有top build.gradle和project build.gradle。将项目导入Intellij/Android Studio时,选择top build.gradle。“应用程序文件夹中有一个top build.gradle和另一个。@Sauron一切都适合你吗?”?您需要使用我更新的build.gradles才能运行它。还有,如果你需要更多的帮助,请告诉我@JaredBurrows你也能帮忙吗?这是一个类似的问题。我在升级Gradle时遇到了困难。我只是想补充一点,这对任何试图升级Gradle的人都是有效的