Flutter应用在Galaxy设备安装时出现双图标问题求助
Flutter应用在Galaxy设备安装后出现双图标问题
我通过Android Studio在Galaxy设备上运行Flutter创建的应用时,安装后会生成两个应用图标。我怀疑是AndroidManifest.xml或build.gradle文件存在错误,但无法定位问题所在。有人说intent-filter代码位置异常可能导致该问题,但我检查后排除了这种情况,同时也排查了debug版本的AndroidManifest文件,未发现问题。以下是我的AndroidManifest.xml和build.gradle文件内容:
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rainbowapps"> <uses-permission android:name="android.permission.INTERNET" /> <queries> <!-- If your app opens https URLs --> <intent> <action android:name="android.intent.action.VIEW" /> <data android:scheme="https" /> </intent> </queries> <application android:label="무지개 숲" android:name="${applicationName}" android:icon="@mipmap/ic_launcher" android:usesCleartextTraffic="true"> <activity android:name=".MainActivity" android:exported="true" 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"> <!-- Specifies an Android theme to apply to this Activity as soon as the Android process has started. This theme is visible to the user while the Flutter UI initializes. After that, this theme continues to determine the Window background behind the Flutter UI. --> <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" /> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <!-- Don't delete the meta-data below. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> <meta-data android:name="flutterEmbedding" android:value="2" /> </application> </manifest>
build.gradle
def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '2' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0.6' } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } android { compileSdkVersion 33 ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.rainbowapps" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. minSdkVersion 20 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null storePassword keystoreProperties['storePassword'] } } buildTypes { release { signingConfig signingConfigs.release } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } }
解决方案
1. 检查合并后的Manifest文件
主Manifest可能没问题,但Flutter插件会自动合并配置,可能新增带LAUNCHER过滤的Activity:
- 切换到Android Studio的
Project视图 - 导航到
app/build/intermediates/merged_manifests/,找到对应build类型(debug/release)的AndroidManifest.xml - 搜索
intent.category.LAUNCHER,确认是否存在多个Activity包含该规则
2. 排查图标资源重复
- 检查
res/mipmap-*目录,确认没有多个图标资源被配置为启动图标 - 确保所有组件的
android:icon指向同一资源,没有其他组件用不同图标同时标记为LAUNCHER
3. 清理缓存并重建项目
- 执行
Build > Clean Project清理缓存 - 执行
Build > Rebuild Project重新编译 - 卸载设备上的旧应用后重新安装
4. 排查第三方插件影响
暂时移除所有第三方Flutter插件,重新运行应用。如果双图标消失,逐个添加插件排查是哪个插件导致的异常配置。
5. 检查Product Flavor配置
如果项目使用了多渠道打包,确认不同flavor的配置没有重复生成启动图标或Activity配置
内容的提问来源于stack exchange,提问作者gill
相关产品推荐
相关产品推荐

