无法在项目':app'上找到参数的方法buildTypes()的类型为org.gradle.api.Project

时间:2018-06-06 12:14:09

标签: java android android-studio gradle

将Eclipse projet导入Android studio 3.0.1之后

现在这是我的项目的build.gradle

CommandBars

这是root build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "com.zombieshunter.gameoverstudios"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 3
        versionName "1.0"
        testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
        ndk {
            moduleName "player_shared"
        }
        multiDexEnabled true

    }

    dexOptions {
        javaMaxHeapSize "4g"
    }
}

buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        productFlavors {
            prod {
                buildConfigField 'String', 'URL', '"http://api.abcd.com"'
            }
    }


    dependencies {
        compile 'com.google.android.gms:play-services:12.0.1'
        compile 'com.android.support:support-v13:27.1.1'
        compile 'com.android.support:multidex:1.0.1'
        compile files('libs/dagger-1.2.2.jar')
        compile files('libs/javax.inject-1.jar')
        compile files('libs/nineoldandroids-2.4.0.jar')
        compile files('libs/support-v4-19.0.1.jar')
    }
}

这是输出

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://maven.google.com" }
    }
}

1 个答案:

答案 0 :(得分:4)

我猜问题是因为buildTypes位置错误:

立即

apply plugin: 'com.android.application'

android {
    ...
}

buildTypes {
    ...

    dependencies {
        ...
    }

}

<强>正确

apply plugin: 'com.android.application'

android {
    ...
    buildTypes {
        ...
    }
}

dependencies {
    ...
}