簡體   English   中英

Android Studio 未正確構建 flutter 應用程序

[英]Android Studio is not building flutter app correctly

我有一個正在開發的應用程序,當我打開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'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

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

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

控制台 Output:

在調試模式下在 IA 模擬器上的 AOSP 上啟動 lib\main.dart... 運行 Gradle 任務“assembleDebug”...

FAILURE:構建失敗並出現異常。

  • 出了什么問題:任務':app:stripDebugDebugSymbols'的執行失敗。

    沒有與請求的版本 20.0.5594570 匹配的 NDK 版本。 本地可用版本:21.0.6113669

  • 嘗試:使用 --stacktrace 選項運行以獲取堆棧跟蹤。 使用 --info 或 --debug 選項運行以獲得更多日志 output。 運行 --scan 以獲得完整的見解。

  • https://help.gradle.org獲得更多幫助

BUILD FAILED in 1s Finished with error: Gradle task assembleDebug failed with exit code 1

logcat中還有一條信息Please configure Android SDK 在此處輸入圖像描述 我尋找解決方案,但沒有找到解決方案

我只是需要幫助,不知道我是否違反了網站的法律,因為我不會說流利的英語

解決方案之一是這樣,

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'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

lintOptions {
    disable 'InvalidPackage'
}

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

buildTypes {
    release {
        signingConfig signingConfigs.debug
    }
}

ndkVersion "21.0.6113669" ///  <<---Add this, 



}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

The reason is because you have installed other NDK, and android studio has other version, the other solutions is, -> Go to sdk tools, and uninstall NDK and Cmake.

對不起我的英語,我不是母語人士。 祝你好運!

此問題是由於與最新的 android gradle 插件版本不兼容。 您可以嘗試在android/build.gradle其版本降級為 3.5.0:

classpath 'com.android.tools.build:gradle:3.5.0'

修改 app/build.gradle 並添加 ndkVersion 我用過以下版本。 您必須使用兼容版本

在此處輸入圖像描述

嘗試將android/build.gradle中的類路徑更改為

dependencies {
    classpath 'com.android.tools.build:gradle:4.0.0'
    ...
}

並確保您的gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

或此處所示的版本https://developer.android.com/studio/releases/gradle-plugin

  1. 請檢查安裝在 Extensions inside settings 中的 flutter 和 dart 插件。
  2. 然后運行 flutter 清潔。
  3. 運行 flutter 升級。
  4. 如果仍然無法正常工作,請將 flutter SDK 路徑添加到環境變量。
  5. 我看到了服務錯誤。所以請驗證 build.gradle 依賴項中的 com.google.services。 希望它有效。

將 app\build.gradle 文件修改為:在 android 塊內添加

ndkVersion "21.0.6113669"

    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 = '2'
}

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

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

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28
    ndkVersion "21.0.6113669"

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "com.dawamisr.app"
        minSdkVersion 19
        targetSdkVersion 28
        multiDexEnabled true
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}
flutter {
    source '../..'
}

依賴項 { testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' implementation 'com.google.ZBF12E1515C25C7D9A81C03:55C25C7D9A1C03: 17.2.1' 實施 'com.google.firebase:firebase-messaging:20.1.0' 實施 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }

應用插件:'com.google.gms.google-services' 應用插件:'kotlin-android'

解決方案是重新安裝 Android Studio 考慮到從 android studio 正確安裝(Java & All packages)

暫無
暫無

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

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