SNNafi / variable_app_icon

A flutter plugin to use multiple app icon on iOS
https://pub.dev/packages/variable_app_icon
MIT License
22 stars 6 forks source link

Please add to the pub.dev readme that 'flutter run' will not be available. #4

Closed kouroku-room closed 5 months ago

kouroku-room commented 5 months ago

The readme for pub.dev includes the following.

Remove <category android:name="android.intent.category.LAUNCHER" /> from the main activity's <intent-filter>.

At this time, Flutter is unable to flutter run a main activity that LAUNCHER has been removed due to this issue. https://github.com/flutter/flutter/issues/38965

This issue can be reproduced in the sample app from this repository.

Log after flutter run in sample app:

Resolving dependencies...
  flutter_lints 3.0.2 (4.0.0 available)
  leak_tracker 10.0.0 (10.0.5 available)
  leak_tracker_flutter_testing 2.0.1 (3.0.5 available)
  leak_tracker_testing 2.0.1 (3.0.1 available)
  lints 3.0.0 (4.0.0 available)
  material_color_utilities 0.8.0 (0.11.1 available)
  meta 1.11.0 (1.15.0 available)
  shared_preferences 2.2.2 (2.2.3 available)
  shared_preferences_android 2.2.1 (2.2.2 available)
  shared_preferences_foundation 2.3.5 (2.4.0 available)
  test_api 0.6.1 (0.7.1 available)
  vm_service 13.0.0 (14.2.2 available)
  win32 5.4.0 (5.5.0 available)
Got dependencies!
13 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
package identifier or launch activity not found.
Please check C:\projects\variable_app_icon\example\android\app\src\main\AndroidManifest.xml for errors.
No application found for TargetPlatform.android_x64.
Is your project missing an android\app\src\main\AndroidManifest.xml?
Consider running "flutter create ." to create one.

I noticed that <intent-filter> is only required on the first 'flutter run' after 'flutter clean', and on subsequent flutter run, no error occurs even if LAUNCHER is commented out. Therefore, I now operate with it commented out and only uncomment it when this error appears.

Can you please add to the readme that because of this issue, removing LAUNCHER will cause an error in the use of flutter run? Or could you change the Readme from deleting LANUCHER to commenting out, and change to uncomment out only if an error occurs? (Or run flutter build apk --debug once)

Of course, we can get to this Issue by searching for the error text, but I think it would be more helpful if it were mentioned in the Readme from the beginning!

SNNafi commented 5 months ago

This is a bug in the __flutter_tools . This plugin code has NO__ error. You can verify it by generating an apk using flutter build apk.

The error occurs while running by flutter run. It only happens when activity-alias is used as an android.intent.category.LAUNCHER instead of an activity. flutter_tools has no logic to handle activity-alias.

And this is the only way to use multiple app icons in Android.

I am working on a PR to fix this.

SNNafi commented 5 months ago

I will add this in the README.md

kouroku-room commented 5 months ago

Thank you for your prompt reply! I knew there was someone working on PR, but I didn't recognize you as the same as the author of the library😂. I wish your PR success!

Mohdx commented 4 months ago

Thank you for this package @SNNafi

I'm somehow stuck here... I have two icons

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application
        android:name="${applicationName}">
        <activity-alias
            android:name="appicon.DEFAULT"
            android:enabled="true"
            android:exported="true"
            android:icon="@mipmap/ic_launcher"
            android:label="MYAPP"
            android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity-alias>
        <activity-alias
            android:name="appicon.MYAPP"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_launcher2"
            android:label="MYAPP"
            android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity-alias>
        <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"
              />
        </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>
    <!-- Required to query activities that can process text, see:
         https://developer.android.com/training/package-visibility?hl=en and
         https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.

         In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
    <queries>
        <intent>
            <action android:name="android.intent.action.PROCESS_TEXT"/>
            <data android:mimeType="text/plain"/>
        </intent>
    </queries>
</manifest>

DEBUG CONSOLE

Launching lib\main.dart on YAL L21 in debug mode...
package identifier or launch activity not found.
Please check C:\flutter apps\myapp\android\app\src\main\AndroidManifest.xml for errors.
No application found for TargetPlatform.android_arm64.
Is your project missing an android\app\src\main\AndroidManifest.xml?
Consider running "flutter create ." to create one.
soyeon-lq commented 3 months ago

I have a temporary solution

You can add the following code in the activity

<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>

When running for the first time, there is no need to comment out the code in the <intent-filter> .

After the application is running, comment out the <intent-filter> and then run flutter run This completes the development environment run

But this is not perfect. The perfect way still requires the author's PR success