Build script error, unsupported Gradle DSL method found: 'android()'!

前端 未结 2 1193
予麋鹿
予麋鹿 2020-12-19 10:34

I\'m using Android Studio 0.4.5 and having troubles syncing gradle.

When I try to do that I get this error:

Gradle \'MyApp\' project refresh failed:          


        
相关标签:
2条回答
  • 2020-12-19 11:01

    The main reason was having this:

    android {    
        packagingOptions {
            exclude 'META-INF/LICENSE.txt'
        }
    }
    

    in the root build.gradle.

    0 讨论(0)
  • 2020-12-19 11:16

    Remove following lines of code from Module1 build.gradle file :

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.8.+'
        }
    }buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.8.+'
        }
    }
    

    As you are using the same configuration across all your modules, so it is fine to have it in root gradle file only.

    Even if you want it in module's build.gradle file this code should be before applying android plugin.

    Final Module1 build.gralde file :

    apply plugin: 'android'
    
    android {
        compileSdkVersion 19
        buildToolsVersion "19.0.1"
    
        defaultConfig {
            minSdkVersion 9
            targetSdkVersion 19
        }
    
        buildTypes {
            release {
                runProguard false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
    }
    

    Also make sure below mentioned configuration should be same across the modules

    android {
        compileSdkVersion 19
        buildToolsVersion "19.0.1"
    
        defaultConfig {
            minSdkVersion 9
            targetSdkVersion 19
        }
     }
    

    You can use whatever you want but should be same.

    0 讨论(0)
提交回复
热议问题