Visual Studio Code(Flutter)中的build.gradle错误 [英] Error on build.gradle In Visual Studio Code(Flutter)

查看:270
本文介绍了Visual Studio Code(Flutter)中的build.gradle错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试为Google Play商店构建应用,并且需要制作一个已签名并发布的APK.我尝试更新两个build.gradle文件,但出现此错误:

I am currently trying to build an app for the Google Play Store and need to make a signed and released APK. I tried updating both build.gradle files, but I get this error:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/herb/Downloads/morningly/android/app/build.gradle' line: 30

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method android() for arguments [build_4k00465lacv9h9hnlvfrbb5oa$_run_closure2@7532b849] on project ':app' of type org.gradle.api.Project.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

这是我的build.gradle文件:

Here are my build.gradle files:

android build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:3.2.1'
    } 
}

allprojects {
    repositories {
        google()
        jcenter()
    }
} 

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}

subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

android/app build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

def keystoreProperties = new Properties()
   def keystorePropertiesFile = rootProject.file('key.properties')
   if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
   }

   android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.morningly"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile file(keystoreProperties['storeFile'])
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

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

现在,我关注了这篇文章( https://flutter.dev/docs/deployment/android )来帮助我完成此过程.我确保编辑了正确的Gradle文件,甚至检查了答案,但无济于事.拜托,如果您有任何意见,请告诉我们.我非常想上传我的应用.

Now, I followed this article (https://flutter.dev/docs/deployment/android) to help me with this process. I made sure that I edited the right Gradle files, and I even checked over answers, but no avail. Please, if you have any input, let me know. I desperately want to upload my app.

推荐答案

您缺少以下内容:

 apply plugin: 'com.android.application'

就在android/app build.gradle文件的line 30上方.没有这个,它不理解android{}. 移动:

just above line 30 of your android/app build.gradle file. It does not understand android{} without this. Move:

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

,也要使其保持整洁,并且最好尽早阅读,以后的内容可能取决于它.

up too, too keep it tidy and best to read it early, later stuff may depend on it.

这篇关于Visual Studio Code(Flutter)中的build.gradle错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆