使用Android Studio创建Flutter项目失败,提示找不到androidx选项
Hey there, let's get this sorted out quickly! That error pops up because the --androidx command-line option you're using (either manually or via Android Studio's template) is no longer supported in newer Flutter versions. AndroidX has been the default configuration for Flutter projects for a while now, so that parameter was removed entirely.
Here are the step-by-step fixes:
Upgrade your Flutter SDK (recommended)
First, check your current Flutter version by running:flutter --versionIf it's not the latest stable release, update it with:
flutter upgradeAfter upgrading, create your project without the
--androidxparameter—just use:flutter create your_project_nameAndroidX will be enabled by default automatically.
Adjust Android Studio's project creation settings
If you're using Android Studio to create the project, the wizard might be stuck trying to add the outdated--androidxparameter. Go through the creation steps again, and make sure you haven't manually added this option in any advanced settings. New versions of Android Studio's Flutter plugin don't require this checkbox/parameter anymore.Verify AndroidX configuration in existing projects
If you already started a project and ran into this, check yourandroid/gradle.propertiesfile to ensure these lines are present:android.useAndroidX=true android.enableJetifier=trueThese lines enable AndroidX support and automatically migrate third-party dependencies to AndroidX, so you don't need the command-line flag at all.
Clean cache if issues persist
Sometimes old cache can cause weird behavior. Run this command to clear Flutter's cache:flutter cleanThen restart Android Studio and try creating the project again.
内容的提问来源于stack exchange,提问作者john

