【问题标题】:Could not find method buildTypes() for arguments on project ':app' of type org.gradle.api.Project无法为 org.gradle.api.Project 类型的项目“:app”上的参数找到方法 buildTypes()
【发布时间】:2018-06-06 12:14:08
【问题描述】:

在我将 Eclipse 项目导入到 Android Studio 3.0.1 之后

现在这是我的项目的 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')
    }
}

这是根 build.gradle

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

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

这是输出

Error:(27, 0) Could not find method buildTypes() for arguments [build_4fb364oy5uo8h1irwj22vkw4h$_run_closure2@601eabab] on project ':app' of type org.gradle.api.Project.
<a href="openFile:G:\my game of now\zombies\android studio\app\build.gradle">Open File</a>

【问题讨论】:

    标签: java android android-studio gradle


    【解决方案1】:

    我猜问题是因为buildTypes 放错地方了:

    现在

    apply plugin: 'com.android.application'
    
    android {
        ...
    }
    
    buildTypes {
        ...
    
        dependencies {
            ...
        }
    
    }
    

    正确

    apply plugin: 'com.android.application'
    
    android {
        ...
        buildTypes {
            ...
        }
    }
    
    dependencies {
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 2020-05-03
      • 2020-08-31
      • 2017-07-17
      • 1970-01-01
      • 2018-08-12
      • 2021-09-08
      • 2019-07-26
      • 2023-03-29
      • 1970-01-01
      相关资源
      最近更新 更多