Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Error: ICON_INVALID] #74

Open
1 of 2 tasks
Ammarlio opened this issue Oct 26, 2022 · 15 comments
Open
1 of 2 tasks

[Error: ICON_INVALID] #74

Ammarlio opened this issue Oct 26, 2022 · 15 comments
Assignees

Comments

@Ammarlio
Copy link

Ammarlio commented Oct 26, 2022

Platform

  • iOS
  • 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>
@skb1129
Copy link
Owner

skb1129 commented Aug 20, 2023

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

@mayyas-nakhli
Copy link

mayyas-nakhli commented Sep 1, 2023

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

@MandaliyaPruthvi
Copy link

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.

@vimosan7
Copy link

vimosan7 commented Oct 2, 2023

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
}

@MandaliyaPruthvi
Copy link

MandaliyaPruthvi commented Oct 2, 2023 via email

@vikasrai1502
Copy link

vikasrai1502 commented Dec 8, 2023

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>

@yunuskucuk11
Copy link

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

@jalvarez930
Copy link

tions give this error because of the package name, how

Have the same error. Do you resolve it

@n76i
Copy link

n76i commented Mar 12, 2024

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

@sheriffmarley
Copy link

sheriffmarley commented Nov 5, 2024

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.

@marcosbotene
Copy link

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.

@git-jr
Copy link

git-jr commented Dec 6, 2024

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

@lucassms9
Copy link

lucassms9 commented Dec 9, 2024

@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);

@git-jr
Copy link

git-jr commented Dec 10, 2024

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

@vikas-chhabra
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests