Android Studio:Could not find method android() for arguments

Android Studio導入項目編譯報錯:Could not find method android() for arguments,我使用的版本是2.1.3,同事使用的是2.3.3,一直以爲是版本原因引起的。替換版本後還是不能解決。於是查找各種資料,終於找到引起的原因:

這個問題本質上是Android-gradle的一個使用限制. 對應的英文文檔android_tool文檔

如果你的App包含了多個android模塊, 應該儘量避免給每個模塊手動指定編譯SDK版本. 這些公有的編譯屬性最好一塊定義在主工程裏面 

解決方式:

// 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.3.3'

        // 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 25
//    buildToolsVersion '26.0.0'
//}
dependencies {
}
android {
    compileSdkVersion 25
    buildToolsVersion '26.0.0'
}
上面的註釋或者刪除即可



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章