You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter集成Google Maps与location插件构建应用时遇双重错误求助

Fixing Your Flutter Google Maps + Location Plugin Errors

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.gradle and revert it to the default state. A standard settings.gradle looks 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 clean in your project root directory to clear old build files.
  • Run flutter pub get to let Flutter automatically handle all plugin dependencies correctly.

Final Verification Steps

  1. Save the corrected AndroidManifest.xml
  2. Restore settings.gradle to its default state
  3. Run flutter clean
  4. Run flutter pub get
  5. Restart your Flutter project

This should resolve both errors you encountered.

内容的提问来源于stack exchange,提问作者SOS video

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 13:42:37