Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio is not building flutter app correctly

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

enter image description here

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 enter image description here 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

like image 224
Mohammed Avatar asked Apr 08 '20 02:04

Mohammed


People also ask

Is Android Studio good for Flutter?

Flutter Or Android Studio With Flutter, you can create the best cross-platform apps available on the market. Both have pros and cons that are unique to themselves. Although Android Studio is a fantastic tool, the Hot Load functionality of flutter makes it superior to Android Studio in many ways.

Is there an alternative to Android Studio Flutter?

Flutter is a mobile app SDK to help developers and designers build modern mobile apps for iOS and Android. Android Studio belongs to "Integrated Development Environment" category of the tech stack, while Flutter can be primarily classified under "Cross-Platform Mobile Development".

Can you build full app with Flutter?

Yes you can. It is an open-source UI sdk created by Google. You can build cross platform applications using flutter.


2 Answers

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!

like image 65
Juan Camilo Cubillos Diaz Avatar answered Oct 19 '22 11:10

Juan Camilo Cubillos Diaz


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'
like image 29
Dr. Sahib Avatar answered Oct 19 '22 12:10

Dr. Sahib