Flutter集成Google Maps与location插件构建应用时遇双重错误求助
Hey there, let's work through these issues step by step to get your app up and running smoothly!
1. First: Fix the AndroidManifest.xml Permission Placement Error
The error unexpected element <uses-permission> found in <manifest><application> is a straightforward fix—you've placed your permission declaration inside the <application> tag, but it needs to live directly under the root <manifest> tag.
Here's the corrected version of your AndroidManifest.xml (I've also added the common ACCESS_COARSE_LOCATION permission for better device compatibility):
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.gmaps_test"> <!-- Permissions go HERE, outside the <application> tag --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <application android:name="io.flutter.app.FlutterApplication" android:label="gmaps_test" android:icon="@mipmap/ic_launcher"> <meta-data android:name="..." android:value="..."/> <!-- Your Google Maps API key --> <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" /> <meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" /> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <meta-data android:name="flutterEmbedding" android:value="2" /> </application> </manifest>
2. Fix the :location_web not found Plugin Issue
The code you added to settings.gradle is an outdated way to configure Flutter plugins. Modern Flutter versions (2.0+) use automatic plugin binding, so manual configuration like this will cause conflicts. Here's what to do:
- Delete all the custom code you added to
settings.gradleand revert it to the default state. A standardsettings.gradlelooks like this:
include ':app' def localPropertiesFile = new File(rootProject.projectDir, "local.properties") def properties = new Properties() assert localPropertiesFile.exists() localPropertiesFile.withInputStream { stream -> properties.load(stream) } 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"
- Run
flutter cleanin your project root directory to clear old build files. - Run
flutter pub getto let Flutter automatically handle all plugin dependencies correctly.
Final Verification Steps
- Save the corrected AndroidManifest.xml
- Restore settings.gradle to its default state
- Run
flutter clean - Run
flutter pub get - Restart your Flutter project
This should resolve both errors you encountered.
内容的提问来源于stack exchange,提问作者SOS video

