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

Roh*_*rma 10 android gradle android-gradle-plugin flutter

我正在尝试在 Android 设备上使用 flutter 制作的应用程序,当我尝试在移动设备上运行该应用程序时,出现以下错误\n“在根项目“android”中找不到任务“assembleStageDebug”。”

\n

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

\n

错误信息

\n
FAILURE: Build failed with an exception.                                \n                                                                        \n* What went wrong:                                                      \nTask 'assembleStageDebug' not found in root project 'android'.          \n                                                                        \n* Try:                                                                  \nRun 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.\n                                                                        \n* Get more help at https://help.gradle.org                              \n                                                                        \nBUILD FAILED in 1s                                                      \nRunning Gradle task 'assembleStageDebug'...                             \nRunning Gradle task 'assembleStageDebug'... Done                    2.4s\n\n[!]  Gradle project does not define a task suitable for the requested build.\nThe android/app/build.gradle file does not define any custom product flavors. You cannot use the --flavor option.\nGradle task assembleStageDebug failed with exit code 1\n
Run Code Online (Sandbox Code Playgroud)\n

颤振医生

\n
[\xe2\x9c\x93] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.5 19F101, locale en-IN)\n    \xe2\x80\xa2 Flutter version 1.12.13+hotfix.5 at /Users/apple/Documents/flutter\n    \xe2\x80\xa2 Framework revision 27321ebbad (7 months ago), 2019-12-10 18:15:01 -0800\n    \xe2\x80\xa2 Engine revision 2994f7e1e6\n    \xe2\x80\xa2 Dart version 2.7.0\n\n[\xe2\x9c\x93] Android toolchain - develop for Android devices (Android SDK version 29.0.2)\n    \xe2\x80\xa2 Android SDK at /Users/apple/Library/Android/sdk\n    \xe2\x80\xa2 Android NDK location not configured (optional; useful for native profiling support)\n    \xe2\x80\xa2 Platform android-29, build-tools 29.0.2\n    \xe2\x80\xa2 Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java\n    \xe2\x80\xa2 Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)\n    \xe2\x80\xa2 All Android licenses accepted.\n\n[\xe2\x9c\x93] Xcode - develop for iOS and macOS (Xcode 11.3.1)\n    \xe2\x80\xa2 Xcode at /Applications/Xcode.app/Contents/Developer\n    \xe2\x80\xa2 Xcode 11.3.1, Build version 11C504\n    \xe2\x80\xa2 CocoaPods version 1.9.1\n\n[\xe2\x9c\x93] Android Studio (version 4.0)\n    \xe2\x80\xa2 Android Studio at /Applications/Android Studio.app/Contents\n    \xe2\x80\xa2 Flutter plugin version 47.1.2\n    \xe2\x80\xa2 Dart plugin version 193.7361\n    \xe2\x80\xa2 Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)\n\n[\xe2\x9c\x93] Connected device (2 available)\n    \xe2\x80\xa2 A1601             \xe2\x80\xa2 HMG6NJZPTCWWNRJJ                     \xe2\x80\xa2 android-arm64 \xe2\x80\xa2 Android 5.1 (API 22)\n    \xe2\x80\xa2 iPhone 11 Pro Max \xe2\x80\xa2 BC0BB924-53E6-4FEB-98BD-7873F1B272A3 \xe2\x80\xa2 ios           \xe2\x80\xa2 com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)\n\n\xe2\x80\xa2 No issues found!\nProcess finished with exit code 0\n
Run Code Online (Sandbox Code Playgroud)\n

应用程序/build.gradle

\n
def localProperties =  new Properties()\ndef localPropertiesFile = rootProject.file('local.properties')\nif (localPropertiesFile.exists()) {\n    localPropertiesFile.withReader('UTF-8') { reader ->\n        localProperties.load(reader)\n    }\n}\n\ndef flutterRoot = localProperties.getProperty('flutter.sdk')\nif (flutterRoot == null) {\n    throw  GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")\n}\n\ndef flutterVersionCode = localProperties.getProperty('flutter.versionCode')\nif (flutterVersionCode == null) {\n    flutterVersionCode = '1'\n}\n\ndef flutterVersionName = localProperties.getProperty('flutter.versionName')\nif (flutterVersionName == null) {\n    flutterVersionName = '1.0'\n}\n\napply plugin: 'com.android.application'\napply plugin: 'com.google.gms.google-services'\napply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"\n\n\nandroid {\n    compileSdkVersion 29\n\n    sourceSets {\n        main.java.srcDirs += 'src/main/kotlin'\n    }\n\n    lintOptions {\n        disable 'InvalidPackage'\n    }\n\n    defaultConfig {\n        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).\n        applicationId "com.enigma.vibing"\n        minSdkVersion 16\n        targetSdkVersion 29\n        versionCode flutterVersionCode.toInteger()\n        versionName flutterVersionName\n        ndkVersion '21.3.6528147'\n        ndk {\n            abiFilters 'x86', 'armeabi-v7a'\n        }\n        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"\n        multiDexEnabled true\n    }\n\n    buildTypes {\n        release {\n            // TODO: Add your own signing config for the release build.\n            // Signing with the debug keys for now, so `flutter run --release` works.\n            signingConfig signingConfigs.debug\n            minifyEnabled true\n            useProguard true\n            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\n        }\n    }\n    splits {\n        abi {\n            enable true\n            reset()\n            include 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'\n            universalApk true\n        }\n    }\n}\n\nflutter {\n    source '../..'\n}\n\ndependencies {\n    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"\n    implementation 'com.google.firebase:firebase-analytics:17.4.3'\n    testImplementation 'junit:junit:4.12'\n    androidTestImplementation 'androidx.test:runner:1.2.0'\n    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'\n    implementation 'com.android.support:multidex:1.0.3'\n}\n
Run Code Online (Sandbox Code Playgroud)\n

Android/build.gradle

\n
buildscript {\n    ext.kotlin_version = '1.3.50'\n    repositories {\n        google()\n        jcenter()\n    }\n\n    dependencies {\n        classpath 'com.android.tools.build:gradle:4.0.1'\n        classpath 'com.google.gms:google-services:4.3.3'\n    }\n}\n\nallprojects {\n    repositories {\n        google()\n        jcenter()\n\n    }\n}\n\n\nrootProject.buildDir = '../build'\nsubprojects {\n    project.buildDir = "${rootProject.buildDir}/${project.name}"\n}\nsubprojects {\n    project.evaluationDependsOn(':app')\n}\n\ntask clean(type: Delete) {\n    delete rootProject.buildDir\n}\n
Run Code Online (Sandbox Code Playgroud)\n

Mar*_*san 9

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

我希望您已经为您的项目正确创建了该flavor项目。如果没有,请阅读本文并 设置您的风格

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

flavorDimensions "default"
    productFlavors {
        dev {
            dimension "default"
            versionNameSuffix "--dev"
        }
        stage {
            dimension "default"
            versionNameSuffix "--stage"
        }
        prod {
            dimension "default"
        }
    }
Run Code Online (Sandbox Code Playgroud)

使用它作为您的代码

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 Code Online (Sandbox Code Playgroud)

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


lit*_*cal 0

尝试:

flutter upgrade

然后

flutter run -v

这会帮助你