Android Studio无法正确构建Flutter应用 [英] Android Studio is not building flutter app correctly

查看:269
本文介绍了Android Studio无法正确构建Flutter应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在使用的应用程序,当我打开build.gradle文件时 出现了几个错误

I have an app I'm working on and when I open build.gradle file Several errors appeared

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

控制台输出:

以调试模式在IA仿真器上的AOSP上启动lib \ main.dart ... 正在运行Gradle任务"assembleDebug" ...

Launching lib\main.dart on AOSP on IA Emulator in debug mode... Running Gradle task 'assembleDebug'...

失败:构建失败,并出现异常.

FAILURE: Build failed with an exception.

  • 出了什么问题:任务':app:stripDebugDebugSymbols'的执行失败.

  • What went wrong: Execution failed for task ':app:stripDebugDebugSymbols'.

没有NDK版本与请求的版本20.0.5594570相匹配.本地可用版本:21.0.6113669

No version of NDK matched the requested version 20.0.5594570. Versions available locally: 21.0.6113669

  • 尝试:使用--stacktrace选项运行以获取堆栈跟踪.使用--info或--debug选项运行,以获取更多日志输出.与--scan一起运行以获得完整的见解.

  • 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.

    https://help.gradle.org

    在1秒钟内构建失败,并完成以下错误:Gradle任务assembleDebug 失败,退出代码为1

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

    logcat中也有一条消息 Please configure Android SDK 我正在寻找解决方案,却没有找到解决方案

    Also there is a message in logcat Please configure Android SDK I looked for a solution and did not find a solution for it

    我只需要帮助,不知道是否因为我不会流利的英语而违反了网站法律

    I just need help and don't know if I have violated the laws of the site because I do not speak English fluently

    推荐答案

    解决方案之一就是这个,

    one of the solutions is this,

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

    原因是因为您已经安装了其他NDK,而android studio具有其他版本,其他解决方案是->转到sdk工具,并卸载NDK和Cmake.

    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.

    对不起,我的英语不是我的母语.祝你好运!

    Sorry for my english, im not native speaker. Good luck!

    这篇关于Android Studio无法正确构建Flutter应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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