【问题标题】:Gradle DSL method not found: 'android()'找不到 Gradle DSL 方法:'android()'
【发布时间】:2015-10-08 06:21:07
【问题描述】:

我正在使用 android studio 1.4 毕业版本 2.4 android插件版本1.3.0

错误:(7, 0) Gradle DSL 方法未找到:'android()'

可能的原因:

  • 项目“Up_13_7_2015”可能正在使用 不包含该方法的 Gradle 版本。 Gradle 设置
  • 构建文件 可能缺少 Gradle 插件。申请 Gradle 插件
  • Build.gradle 文件是

    android {
        compileSdkVersion 19
        buildToolsVersion "19.0.0"
    
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aidl.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
            }
    
            // Move the tests to tests/java, tests/res, etc...
            instrumentTest.setRoot('tests')
    
            // Move the build types to build-types/<type>
            // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
            // This moves them out of them default location under src/<type>/... which would
            // conflict with src/ being used by the main source set.
            // Adding new build types or product flavors should be accompanied
            // by a similar customization.
            debug.setRoot('build-types/debug')
            release.setRoot('build-types/release')
    
    
        }
    }
    dependencies {
        apply plugin: 'announce'
        compile fileTree(dir: 'libs', include: '*.jar')
        compile project(':Downloads:Android-ViewPagerIndicator-master:library')
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
    

    【问题讨论】:

      标签: android android-studio


      【解决方案1】:

      在您的项目级 build.gradle 文件中查找错误并修复它们。

      在我的情况下,当我将新的库模块添加到项目中时,问题就出现了。我的build.gradle 看起来像这样:

      // Top-level build file where you can add configuration options common to all sub-projects/modules.
      
      buildscript {
          ext.kotlin_version = '1.3.50' '1.3.31'
          repositories {
              google()
              jcenter()
      
          }
          dependencies {
              classpath 'com.android.tools.build:gradle:3.5.0'
              classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
              // NOTE: Do not place your application dependencies here; they belong
              // in the individual module build.gradle files
          }
      }
      
      allprojects {
          repositories {
              google()
              jcenter()
      
          }
      }
      
      task clean(type: Delete) {
          delete rootProject.buildDir
      }
      

      如你所见,这一行是不正确的:

      ext.kotlin_version = '1.3.50' '1.3.31'
      

      我改成

      ext.kotlin_version = '1.3.50' 
      

      而且我不再收到错误消息了。

      【讨论】:

        【解决方案2】:

        compile 语句必须在应用模块的build.gradle 中 所以如果你从这个文件中删除它们并将它们添加到那里,它就会起作用。

        【讨论】:

        • 项目根目录下有一个build.gradle文件,你的app文件夹下有一个build.gradle文件,我指的是后者
        • @android 你也应该看看this answer
        • 我没有任何应用程序文件夹我从 eclipse 导出我的项目....这是个问题...
        【解决方案3】:

        你需要

        apply plugin: 'com.android.application'
        

        在你的应用模块build.gradle文件的顶部,android { }之前。

        【讨论】:

        • 添加后显示错误:(4, 0) 未找到 ID 为 'com.android.application' 的插件。 "openFile:/home/data/AndroidStudioProjects/Up_13_7_2015/build.gradle">打开文件
        • 那么,你的项目根级 build.gradle 中有什么?
        • 以上文件在根级build.gradle
        • android 的东西会转到特定于模块(子目录)的 build.gradle,而不是通常只配置存储库等的项目级别。
        • 我从 Eclipse 导出了我的项目,但它只显示我的项目中的一个 build.gradle 文件....这是个问题..
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-16
        • 2020-04-16
        • 1970-01-01
        • 2019-10-21
        • 2015-11-19
        相关资源
        最近更新 更多