Android Studio is not building flutter app correctly

为君一笑 提交于 2020-06-28 06:52:08

问题


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

Console Output:

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

FAILURE: Build failed with an exception.

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

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

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

  • Get more help at https://help.gradle.org

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

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


回答1:


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

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!




回答2:


The solution is to reinstall Android Studio Taking into account the correct installation of (Java & All packages) from android studio




回答3:


  1. Do check the flutter and dart plugin installed in Extensions inside settings.
  2. Then run flutter clean.
  3. Run flutter upgrade.
  4. If still not working properly add flutter SDK path to environment variable.
  5. And i saw an error for services.So do verify the com.google.services in your build.gradle dependencies. Hope it work.



回答4:


This issue is due to incompatibility with the latest android gradle plugin version. You can try to downgrade its version to 3.5.0 in your android/build.gradle:

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


来源:https://stackoverflow.com/questions/61092361/android-studio-is-not-building-flutter-app-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!