Rohit Varma
Rohit Varma

Reputation: 317

Flutter: Task 'assembleStageDebug' not found in root project 'android'

I was trying my app which is made on flutter on an android device and when I tried running the app on my mobile, I am getting the following error "Task 'assembleStageDebug' not found in root project 'android'. "

my app works well on iOS but when running it on android, it is causing the problem. The flutter doctor detected no issues and no one seems to have the same problem as I do. I was first facing the problem of " Unsuported Android Plugin version: 4.0.1.". I was told to add a flavor by going to run -> edit config -> flavors and added the name to the flavor and ran the app using flutter run --flavor "flavor_name" which resulted in this error. Thanks in advance!

Error Message

FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
Task 'assembleStageDebug' not found in root project 'android'.          
                                                                        
* Try:                                                                  
Run gradlew tasks to get a list of available tasks. 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                                                      
Running Gradle task 'assembleStageDebug'...                             
Running Gradle task 'assembleStageDebug'... Done                    2.4s

[!]  Gradle project does not define a task suitable for the requested build.
The android/app/build.gradle file does not define any custom product flavors. You cannot use the --flavor option.
Gradle task assembleStageDebug failed with exit code 1

Flutter Doctor

[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.5 19F101, locale en-IN)
    • Flutter version 1.12.13+hotfix.5 at /Users/apple/Documents/flutter
    • Framework revision 27321ebbad (7 months ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/apple/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3.1, Build version 11C504
    • CocoaPods version 1.9.1

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (2 available)
    • A1601             • HMG6NJZPTCWWNRJJ                     • android-arm64 • Android 5.1 (API 22)
    • iPhone 11 Pro Max • BC0BB924-53E6-4FEB-98BD-7873F1B272A3 • ios           • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

• No issues found!
Process finished with exit code 0

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  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 plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"


android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.enigma.vibing"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        ndkVersion '21.3.6528147'
        ndk {
            abiFilters 'x86', 'armeabi-v7a'
        }
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    splits {
        abi {
            enable true
            reset()
            include 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
            universalApk true
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics:17.4.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.android.support:multidex:1.0.3'
}

Android/build.gradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath 'com.google.gms:google-services:4.3.3'
    }
}

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
}

Upvotes: 11

Views: 21563

Answers (6)

Muhammad Adil Mehmood
Muhammad Adil Mehmood

Reputation: 51

THIS FIX WORKED FOR ME

We have to add flavorDimensions and other lines after buildTypes.

I was adding falvorDimensions inside buildTypes so it was giving me the error and once I removed the flavor config from buildTypes and moved it right after the closing } bracket, it started working.

These are flavor config I used (Remember after closing } of buildTypes):

buildTypes {
} // TODO: After this, add productFlavors

productFlavors {
    production {
        dimension "default"
        resValue "string", "app_name", "APP_NAME"
        applicationIdSuffix ""
    }
    staging {
        dimension "default"
        resValue "string", "app_name", "Stg APP_NAME"
        applicationIdSuffix ".stg"
    }
    development {
        dimension "default"
        resValue "string", "app_name", "Dev APP_NAME"
        applicationIdSuffix ".dev"
    }
}

Just an extra point: Depending on the IDE that you are using, configure the different flavor builds in specific files to avoid using the command every time.

Upvotes: 1

Baker
Baker

Reputation: 28010

Problem

I cloned a Flutter project from my git remote repository to run on a different machine.

Some required files for an Android build were not committed to repository.

Android builds would fail with:

task 'assembledebug' not found in root project 'android'

Solution

Inside the project directory, in a terminal (re-) run:

flutter create .

What Happens

This creates a couple key files if missing:

  • android/settings.gradle
  • android/gradle.properties

The output will be similar:

$ flutter create .

Recreating project ....
  your_project.iml (created)
  .metadata (created)
  android/gradle.properties (created)
  android/.gitignore (created)
  android/settings.gradle (created)
  android/your_project_android.iml (created)
  .idea/runConfigurations/main_dart.xml (created)
  .idea/libraries/KotlinJavaRuntime.xml (created)
Wrote 11 files.

Why this works

gradle.properties is important for Android app SDK levels beyond 28 which replaces the old Android Support Libraries with AndroidX:

android.useAndroidX=true
android.enableJetifier=true

settings.gradle is important for its including of :app and setting the Flutter SDK location:

include ':app'

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

After these two files in are in place, Android builds should complete properly.

Upvotes: 0

Ahmed Nabil
Ahmed Nabil

Reputation: 161

the problem for me was that i didn't had settings.gradle under root project so, add that file under root project and add this line in it

include ':app'

hope it works.

Upvotes: 2

Maruf Hassan
Maruf Hassan

Reputation: 1248

The issue is because you have not mentioned the flavorDimensions in android/app/build.gradle/

I hope you have created the flavor properly for your project. If not, then read this article and set up your flavor.

After setting up your flavor, you need to add this code into your android/app/build.gradle/ in the android section.

flavorDimensions "default"
    productFlavors {
        dev {
            dimension "default"
            versionNameSuffix "--dev"
        }
        stage {
            dimension "default"
            versionNameSuffix "--stage"
        }
        prod {
            dimension "default"
        }
    }

Use this as your code

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  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 plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"


android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.enigma.vibing"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        ndkVersion '21.3.6528147'
        ndk {
            abiFilters 'x86', 'armeabi-v7a'
        }
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    //Add this code for flavor
    flavorDimensions "default"
    productFlavors {
        dev {
            dimension "default"
            versionNameSuffix "--dev"
        }
        stage {
            dimension "default"
            versionNameSuffix "--stage"
        }
        prod {
            dimension "default"
        }
    }
    splits {
        abi {
            enable true
            reset()
            include 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
            universalApk true
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics:17.4.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.android.support:multidex:1.0.3'
}

Run flutter clean and re-run the app and it will be fixed.

Upvotes: 11

Chukwuebuka Durumbah
Chukwuebuka Durumbah

Reputation: 11

Using android studio to run flutter try going to your project structure and change project SDK to Android API 27 Platform then apply and re-run the app

Upvotes: 1

littleironical
littleironical

Reputation: 1914

Try:

flutter upgrade

then

flutter run -v

This will help you

Upvotes: 0

Related Questions