【问题标题】:Gradle Dsl method not found: android() android studio 2.1.3找不到 Gradle Dsl 方法:android() android studio 2.1.3
【发布时间】:2016-09-20 20:55:36
【问题描述】:

我正在使用 android studio 2.1.3 来自Create Hello-JNI with Android Studio

编译时输出如下。

错误:(3, 0) Gradle DSL 方法未找到:'android()' 可能的原因:

  • 项目“FirstDemo”可能正在使用不包含该方法的 Android Gradle 插件版本(例如,在 1.1.0 中添加了“testCompile”)。 修复插件版本并同步项目
  • 项目“FirstDemo”可能正在使用不包含该方法的 Gradle 版本。 打开 Gradle 包装文件
  • 构建文件可能缺少 Gradle 插件。 应用 Gradle 插件
  • build.gradle(模块):

        apply plugin: 'com.android.model.application'
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
        defaultConfig {
            applicationId "com.example.sprinkle.firstdemo"
            minSdkVersion 22
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    

    buil.gradle(顶部)

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle-experimental:0.7.2'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    
    //task clean(type: Delete) {
    //    delete rootProject.buildDir
    //}
    

    【问题讨论】:

    • android {} 应该包含在模型 {} 中。它在教程中。
    • 嗨,我试过了,我得到了错误 org.gradle.api.internal.ExtensibleDynamicObject
    • 所以试图删除模型
    • 你试过不使用实验性 gradle 插件吗?我认为当前版本的标准插件支持原生代码。
    • 哦...原因是 android 2.1.3 和教程给出的版本。谢谢,我会尝试不使用实验性 gradle 插件。

    标签: android android-studio


    【解决方案1】:

    它的工作

    改变了

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

    proguardFiles.add(file('proguard-android.txt'))
     proguardFiles.add(file('proguard-rules.txt'))
    

    【讨论】:

    • Proguard-android.txt 在 sdk 目录下,而不是在你的项目目录下。你确定这些规则真的被应用了吗?
    • 它对我有用,在 android studio 2.1.3 中编译成功,没有任何警告/错误
    • 当然编译好了,这没问题。您是否尝试运行发布版 APK?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 2020-04-16
    相关资源
    最近更新 更多