Flutter:在根项目“android”中找不到任务“assembleStageDebug”

Posted

技术标签:

【中文标题】Flutter:在根项目“android”中找不到任务“assembleStageDebug”【英文标题】:Flutter: Task 'assembleStageDebug' not found in root project 'android' 【发布时间】:2020-11-10 15:34:06 【问题描述】:

我正在尝试在 android 设备上使用颤振制作的应用程序,当我尝试在手机上运行该应用程序时,我收到以下错误 “在根项目 'android' 中找不到任务 'assembleStageDebug'。”

我的应用在 ios 上运行良好,但在 android 上运行时,它会导致问题。颤振医生没有发现任何问题,似乎没有人和我有同样的问题。我首先面临“不支持的Android插件版本:4.0.1”的问题。我被告知通过运行 -> 编辑配置 -> 风味添加风味并将名称添加到风味并使用 flutter run --flavor "flavor_name" 运行应用程序,这导致了此错误。提前致谢!

错误信息

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 (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

【问题讨论】:

我以前也遇到过同样的问题。我做了颤振升级,它解决了问题。 【参考方案1】:

我的问题是我在根项目下没有 settings.gradle 所以,在根项目下添加该文件并在其中添加这一行

include ':app'

希望它有效。

【讨论】:

【参考方案2】:

问题是因为你在android/app/build.gradle/中没有提到flavorDimensions

我希望您已经为您的项目正确创建了flavor。如果没有,请阅读这篇文章和set up your flavor。

设置您的flavor 后,您需要将此代码添加到android/app/build.gradle/android 部分。

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

将此作为您的代码

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'

运行flutter clean 并重新运行应用程序,它将被修复。

【讨论】:

【参考方案3】:

使用 android studio 运行 flutter 尝试进入你的项目结构并将项目 SDK 更改为 Android API 27 平台然后应用并重新运行应用程序

【讨论】:

【参考方案4】:

试试:

flutter upgrade

然后

flutter run -v

这对你有帮助

【讨论】:

以上是关于Flutter:在根项目“android”中找不到任务“assembleStageDebug”的主要内容,如果未能解决你的问题,请参考以下文章

在根项目中找不到 Android Studio 0.8 任务组合

在根项目中找不到任务“publishApkRelease”

在根项目中找不到任务“publishApkRelease”

在根项目“网关”中找不到任务“bootRepackage”

在根项目“myproject”中找不到路径为“:mypath”的项目

错误:在根项目“projectName”中找不到项目“app”