react-native-change-icon icon indicating copy to clipboard operation
react-native-change-icon copied to clipboard

[Error: ICON_INVALID]

Open Ammarlio opened this issue 3 years ago • 15 comments

Platform

  • [ ] iOS
  • [X] Android

Description After Integrating and follow the same steps for Android, i am getting [Error: ICON_INVALID]. I did all the steps as the docs and all icons are valid. Anyway on IOS it works fine. Even if i am setting enable property to true in activity-alias for default icon, i am getting the same error.

To Reproduce Steps to reproduce the behavior:

  1. invoke changeIcon('blueicon');
  2. getting the error message [Error: ICON_INVALID]

Screenshots [Error: ICON_INVALID]

Device (please complete the following information):

  • Device: [Android A52s 5G]

Versions

  • react-native: [^0.68.2]
  • react-native-change-icon: [^4.0.0]

Code Snippet

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS" />

<application
    android:name=".MainApplication"
    android:allowBackup="false"
    android:icon="@mipmap/defaulticon"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/defaulticon_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <receiver
        android:name=".widgets.summaryWidget.summaryWidget"
        android:exported="true">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>

        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/summary_widget_info" />
    </receiver>
    <receiver
        android:name=".widgets.performanceWidget.PerformanceWidget"
        android:exported="true">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>

        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/testdemo_widget_info" />
    </receiver>

    <activity
        android:name=".widgets.performanceWidget.WidgetActivity"
        android:exported="false">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:exported="true"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustPan">
    </activity>

    <activity-alias
        android:name="com.testdemo.MainActivitydefaulticon"
        android:enabled="false"
        android:exported="true"
        android:icon="@mipmap/defaulticon"
        android:roundIcon="@mipmap/defaulticon_round"
        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="com.testdemo.MainActivityblueicon"
        android:enabled="false"
        android:exported="true"
        android:icon="@mipmap/blueicon"
        android:roundIcon="@mipmap/blueicon_round"
        android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity-alias>
</application>

Ammarlio avatar Oct 26 '22 12:10 Ammarlio

@Ammarlio please use v5 and try using the updated docs for the setup

skb1129 avatar Aug 20 '23 05:08 skb1129

@Ammarlio I was facing the same issue, the solution was to pass package name into the ChangeIconPackage constructor in MainApplication.java file

 @Override
    protected List<ReactPackage> getPackages() {
      List<ReactPackage> result = new ArrayList<ReactPackage>();

      result.addAll(Arrays.<ReactPackage>asList(
      ...
         new ChangeIconPackage("com.your.package")
         ));
     }

P.S: In my project library linking in both iOS and Android is manual.

mayyas-nakhli avatar Sep 01 '23 09:09 mayyas-nakhli

Hello @skb1129

I tried using your package and getting the same error on the PROD. When I tried to display system generated error to get more detail about the error, I got below error: " java.lang.SecurityException: Attempt to change component state; pid=5326, uid=10523, component=ComponentInfo{com.package-name/{com.package-name.MainActivityExpressShipColor} "

@mayyas-nakhli I've tried your solution as well but that's also not working.

@skb1129 Also updated to V5 and got this error.

MandaliyaPruthvi avatar Sep 19 '23 08:09 MandaliyaPruthvi

Make sure your applicationId is correct in android/app/build.gradle. This mismatch can cause problems.

defaultConfig {
    applicationId "com.yourapplicationid"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    signingConfig signingConfigs.debug
    vectorDrawables.useSupportLibrary = true
}

vimosan7 avatar Oct 02 '23 14:10 vimosan7

Thanks for your response I'll have a look into it and get back to you if it helps or not.

On Mon, 2 Oct 2023, 8:07 pm vimosan7, @.***> wrote:

Make sure your applicationId is correct in android/app/build.gradle. This mismatch can cause problems.

defaultConfig { applicationId "com.yourapplicationid" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" signingConfig signingConfigs.debug vectorDrawables.useSupportLibrary = true }

— Reply to this email directly, view it on GitHub https://github.com/skb1129/react-native-change-icon/issues/74#issuecomment-1743141234, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE7ZQYKGEW2RZRGU35EE23DX5LGQZAVCNFSM6AAAAAARO6TK3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBTGE2DCMRTGQ . You are receiving this because you commented.Message ID: @.***>

MandaliyaPruthvi avatar Oct 02 '23 15:10 MandaliyaPruthvi

I'm facing issues to make changes in AndroidManifest.xml, when I'm having .SplashActivity (react-native-splash-screen). I tried multiple permutation-combination but either app is crashing or getting [Error:ICON_INVALID]. Current AndroidManifest.xml code is below and getting [Error:ICON_INVALID] error.

Thanks

<activity
        android:name=".SplashActivity"
        android:theme="@style/AppTheme"
        android:label="@string/app_name"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
      </activity>  
        <activity-alias 
            android:name="com.packagename.SplashActivityDefault"
            android:enabled="true"
            android:exported="true"
            android:icon="@mipmap/ic_launcher"
            android:roundIcon="@mipmap/ic_launcher"
            android:targetActivity=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
            </intent-filter>
        </activity-alias>
        <activity-alias 
            android:name="com.packagename.SplashActivityXmas"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_launcher_xmas"
            android:roundIcon="@mipmap/ic_launcher_xmas"
            android:targetActivity=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
            </intent-filter>
        </activity-alias>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme"
        android:exported="true">
          <intent-filter android:autoVerify="true">
              <action android:name="android.intent.action.VIEW"/>
              <category android:name="android.intent.category.DEFAULT"/>
              <category android:name="android.intent.category.BROWSABLE"/>
              <data android:scheme="http" />
              <data android:scheme="https" />
          </intent-filter>
      </activity>

vikasrai1502 avatar Dec 08 '23 08:12 vikasrai1502

I use more than one variant. These types of applications give this error because of the package name, how should we use it?

yunuskucuk11 avatar Jan 31 '24 13:01 yunuskucuk11

tions give this error because of the package name, how

Have the same error. Do you resolve it

jalvarez930 avatar Mar 08 '24 22:03 jalvarez930

tions give this error because of the package name, how

Have the same error. Do you resolve it

Hello, I have the same error too, here is something can fix it:

  • You have more than one variant, but you have only one package (com.example)
  • Open ChangeIconModule.java in node_modules and edit something:
  • Find final String activeClass = this.packageName + newIconName;
  • And update with your package: final String activeClass = "com.example.MainActivity" + newIconName;
  • Now it worked, create patch-package to use and wait update from lib owner

n76i avatar Mar 12 '24 16:03 n76i

I use more than one variant. These types of applications give this error because of the package name, how should we use it?

Had the same issue, this is because if you define a flavor with an applicationId, the packageName would become: com.example.myapp.dev but we need com.example.myapp

I could solve it by removing the flavor in ChangeIconModule.java on line 75 final String activeClass = this.packageName + ".MainActivity" + newIconName;

So i came up with this solution:

String activeClass = this.packageName + ".MainActivity" + newIconName;
        if (activeClass.contains(".dev.")) {
            activeClass = activeClass.replace(".dev.", ".");
        }

Guess we need a way to detect flavors properly so they can be removed.

sheriffmarley avatar Nov 05 '24 15:11 sheriffmarley

I use more than one variant. These types of applications give this error because of the package name, how should we use it?

Had the same issue, this is because if you define a flavor with an applicationId, the packageName would become: com.example.myapp.dev but we need com.example.myapp

I could solve it by removing the flavor in ChangeIconModule.java on line 75 final String activeClass = this.packageName + ".MainActivity" + newIconName;

So i came up with this solution:

String activeClass = this.packageName + ".MainActivity" + newIconName;
        if (activeClass.contains(".dev.")) {
            activeClass = activeClass.replace(".dev.", ".");
        }

Guess we need a way to detect flavors properly so they can be removed.

I tried this solution but it didn't work very well, my app duplicated on the device with different icons, at least I could see the library working (I have 3 different versions in my app, without this workaround I couldn't even see the library working), but it didn't solve my problem, unfortunately I was forced to stop the feature I was developing.

marcosbotene avatar Dec 03 '24 14:12 marcosbotene

For me, the solution was to remove the applicationId and leave just "MainActivityIconName": Before:

        <activity-alias
            android:name="com.teste.MainActivity2"
            android:enabled="true"
            android:exported="true"...

After:

        <activity-alias
            android:name=".MainActivity2"
            android:enabled="true"
            android:exported="true"...

git-jr avatar Dec 06 '24 20:12 git-jr

@marcosbotene in Android the native behaviour is create two icons, keep the old one and create the new one. if you want to avoid this behaviour, you have to use the COMPONENT_ENABLED_STATE_DISABLED params in the setComponentEnabledSetting method.

try do that in your ChangeIconModule.java:

 // display new icon
   activity.getPackageManager().setComponentEnabledSetting(
                    new ComponentName(this.packageName, activeClass),
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                    PackageManager.DONT_KILL_APP);
 // hide old icon
            activity.getPackageManager().setComponentEnabledSetting(
                    new ComponentName(this.packageName, activeClassDefault),
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);

lucassms9 avatar Dec 09 '24 18:12 lucassms9

@lucassms9 Thank you so much for your help! Your solution worked perfectly and saved me a lot of time. I really appreciate your effort and support!

git-jr avatar Dec 10 '24 12:12 git-jr

Reason - Your app must have build variants due to which this.packageName get's combined with the build variant. Example Package Name - com.somepackage.app Build Variant is - stage, prod this.packageName - com.somepackage.app.stage

But to change the icon we don't need to combine the packagename with build variant so, for a temproary solution

open node_modules/react-native-change-icon/android/src/main/java/com/reactnativechangeicon/ChangeIconModule.java

// OLD
L75: final String activeClass = this.packageName + ".MainActivity" + newIconName;
// New
 final String activeClass = "com.somepackage.app" + ".MainActivity" + newIconName;

then run

npx patch-package react-native-change-icon

vikas-chhabra avatar Dec 16 '24 20:12 vikas-chhabra