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

Compose Multiplatform应用如何正确申请网络权限?

在Compose Multiplatform中配置Android网络权限的正确方式

你遇到的问题大概率是权限标签放置位置错误或Manifest文件存在语法问题,以下是具体解决步骤:

  • 确认权限标签的正确位置:
    <uses-permission android:name="android.permission.INTERNET" /> 必须放在 <manifest> 根标签内部、<application> 标签之外,不能嵌套在<application>里。正确的Manifest结构示例:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- 网络权限声明在这里 -->
        <uses-permission android:name="android.permission.INTERNET" />
        <!-- 可选:如果需要检测网络状态,添加此权限 -->
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
        <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">
            <activity
                android:name=".MainActivity"
                android:exported="true"
                android:label="@string/app_name"
                android:theme="@style/Theme.MyApp">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    </manifest>
    
  • 检查Manifest语法错误:
    确保所有标签正确闭合,<manifest>标签中存在正确的xmlns属性(xmlns:android="http://schemas.android.com/apk/res/android"),无拼写错误。

  • 清理并重新构建项目:
    执行以下命令清理缓存后重新构建安装:

    # Mac/Linux
    ./gradlew clean assembleDebug
    # Windows
    gradlew clean assembleDebug
    
  • 权限类型说明:
    INTERNET属于Android的正常权限,无需在运行时动态申请,只要在Manifest中声明即可生效,不需要额外写权限请求代码。

如果按上述步骤操作后仍无法安装,建议查看Android Studio的构建日志,定位具体的安装失败报错(比如重复权限声明、SDK版本不兼容等)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 03:00:00