如何解决"未找到的错误︰ 错误︰ 行,(23) Gradle DSL 方法: android ()"

发布时间: 2016/9/16 21:39:42
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我正在我的项目 Android studio在 Windows 上,但现在我正在尝试在 Ubuntu 上打开但它不断抱怨的︰

Error:Error:line (23)Gradle DSL method not found: 'android()' Possible causes: //(Error23,0)

The project 'POSTER' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
The build file may be missing a Gradle plugin. Apply Gradle plugin

项目 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:2.1.2'
        classpath 'com.google.gms:google-services:3.0.0'

        // 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 {
    compileSdkVersion 23
    buildToolsVersion '24.0.0'
}

应用程序 Gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "com.ozuf.poster"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 5
        versionName "0.5 Beta"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    compile project(':volley')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    compile 'org.jsoup:jsoup:1.9.1'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:cardview-v7:23.4.0'
    compile 'com.android.support:recyclerview-v7:23.4.0'
    compile 'ch.acra:acra:4.9.0-RC-2'
    compile 'com.google.firebase:firebase-core:9.0.2'
    compile 'com.google.firebase:firebase-ads:9.0.2'
}


apply plugin: 'com.google.gms.google-services'

Gradle-wrapper.properties

#Fri Apr 08 19:27:52 WAT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

求你了,你知道什么吗什么造成这以及如何修复它吗?

解决方法 1:

删除 android settings 在项目 gradle

android {
    compileSdkVersion 23
    buildToolsVersion '24.0.0'
}

如果你想要设置一样常见 config ,你可以使用就是这个样子︰

项目 gralde:

ext {
    compileSdkVersion 23
    buildToolsVersion '24.0.0'
}

gralde 应用程序︰

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.ozuf.poster"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 5
        versionName "0.5 Beta"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
官方微信
官方QQ群
31647020