簡體   English   中英

build.gradle 在 Visual Studio Code(Flutter) 中出錯

[英]Error on build.gradle In Visual Studio Code(Flutter)

我目前正在嘗試為 Google Play 商店構建一個應用程序,並且需要制作一個簽名並發布的 APK。 我嘗試更新兩個 build.gradle 文件,但出現此錯誤:

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 文件:

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 文件,我什至檢查了答案,但無濟於事。 如果您有任何意見,請告訴我。 我非常想上傳我的應用程序。

您錯過了:

 apply plugin: 'com.android.application'

就在您的android/app build.gradle文件的line 30上方。 沒有這個,它就無法理解android{} 移動

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

得也保持它的整潔最佳的閱讀它的早期 ,后來的東西可以依賴於它。

拋出新的 GradleException(“未找到 Flutter SDK。在 local.properties 文件中使用 flutter.sdk 定義位置。”)

我有一個錯誤,我打開 android/apps/build.gradle/ errroe 只是彈出來解決它我只是從 Gradel Expection 中刪除“new”。 拋出 GradleException(“未找到 Flutter SDK。在 local.properties 文件中使用 flutter.sdk 定義位置。”)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM