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

Android Manifest添加EnableSafeBrowsing遇Lint警告问题咨询

Fixing "Element meta-data is not allowed here" for WebView SafeBrowsing Manifest Entry

Let's break down why you're seeing this Lint warning and how to fix it properly (without relying on suppression comments):

The Root Cause

The android.webkit.WebView.EnableSafeBrowsing meta-data tag must be placed directly inside the <application> element of your AndroidManifest.xml. If you've nested it inside an <activity>, <service>, or another component tag, Lint will flag it as invalid (since meta-data has strict placement rules per Android's manifest schema), and worse—your SafeBrowsing configuration won't actually take effect.

Correct Manifest Structure

Move the meta-data tag to be a direct child of <application> like this:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.MyApp">

    <!-- Correct placement: Directly under <application> -->
    <meta-data
        android:name="android.webkit.WebView.EnableSafeBrowsing"
        android:value="true" />

    <!-- Your activities, services, receivers, etc. go here -->
    <activity
        android:name=".MainActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

Why This Works

Android's manifest schema allows meta-data tags only as children of specific components (<application>, <activity>, <service>, etc.), but WebView's SafeBrowsing flag is an application-wide setting. Placing it at the <application> level ensures it's applied to all WebViews in your app, and it aligns with Lint's validation rules—so the warning will disappear automatically.

If for some edge case you can't move the tag (though this shouldn't be necessary for SafeBrowsing), you can disable the specific Lint check for your manifest instead of using inline comments. Create or update a lint.xml file in your module's root directory:

<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <issue id="AndroidElementNotAllowed">
        <ignore path="app/src/main/AndroidManifest.xml" />
    </issue>
</lint>

But again, fixing the tag placement is the cleanest, most correct solution.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 07:34:55