0

I'm manually changing android launcher icon following this 2nd answer of this post, this requires working in Android Studio.

My project is in VS code from day one, and created by command flutter create xxx.

When I open this existing project in Android Studio and right-click on res folder to add a new Image Asset, instead of popping up configure image asset, it gives me IDE Error Occurred with

java.lang.NullPointerException
    at com.android.tools.idea.configurations.ConfigurationManager.create(ConfigurationManager.java:165)
    at com.android.tools.idea.configurations.ConfigurationManager.getConfiguration(ConfigurationManager.java:142)
    at com.android.tools.idea.editors.theme.ThemeEditorUtils.getConfigurationForModule(ThemeEditorUtils.java:523)
    at com.android.tools.idea.npw.assetstudio.DrawableRenderer.<init>(DrawableRenderer.java:72)
    at com.android.tools.idea.npw.assetstudio.wizard.GenerateImageAssetPanel.<init>(GenerateImageAssetPanel.java:216)
    at com.android.tools.idea.npw.assetstudio.wizard.NewImageAssetStep.<init>(NewImageAssetStep.java:39)
    at com.android.tools.idea.actions.NewImageAssetAction.createWizard(NewImageAssetAction.kt:33)
    at com.android.tools.idea.actions.AndroidAssetStudioAction.actionPerformed(AndroidAssetStudioAction.java:108)
    at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:261)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:278)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.lambda$actionPerformed$0(ActionMenuItem.java:292)
    at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:283)
    at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:107)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:282)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$fireActionPerformed$0(ActionMenuItem.java:111)
    at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88)
    at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransaction$1(TransactionGuardImpl.java:111)
    at com.intellij.openapi.application.TransactionGuardImpl.submitTransaction(TransactionGuardImpl.java:120)
    at com.intellij.openapi.application.TransactionGuard.submitTransaction(TransactionGuard.java:121)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:111)
    at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:524)
    at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:35)
    at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:546)
    at java.awt.Component.processMouseEvent(Component.java:6550)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3325)
    at java.awt.Component.processEvent(Component.java:6315)
    at java.awt.Container.processEvent(Container.java:2239)
    at java.awt.Component.dispatchEventImpl(Component.java:4899)
    at java.awt.Container.dispatchEventImpl(Container.java:2297)
    at java.awt.Component.dispatchEvent(Component.java:4721)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
    at java.awt.Container.dispatchEventImpl(Container.java:2283)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4721)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
    at java.awt.EventQueue.access$500(EventQueue.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:715)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    at java.awt.EventQueue$4.run(EventQueue.java:739)
    at java.awt.EventQueue$4.run(EventQueue.java:737)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:736)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:757)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:702)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:375)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

To narrow down the bug, I flutter create yyyy another project, open in Android Studio, the bug is reproduced.

Then I Start a new Flutter project in Android Studio, the counter app, then right-click new image asset, the configure image asset pops up.

Did I miss anything in Android Stuido settings? or there's differences between flutter create xxx and Start a new Flutter project?

Wenhui Luo
  • 266
  • 3
  • 13

1 Answers1

1

Unfortunately I don't have a good answer for that specific issue after hours of research. I faced this exact bug when trying to generate a new adaptive icon for Android apps after having created my app with flutter create my_app and trying to edit the icon in Android Studio.

My work around for that was to use the plugin fluter_launcher_icons and specifying a foreground and background images to the plugin. My foreground image was simply the main part of the icon, and the background was the gradient that my icon was placed against on the regular version of the icon. I ended up with three icon images: icon.png a 1024x1024 high quality image used by the plugin to generate all sizes of icons needed by different devices); foreground.png, the main body of the icon. In my case a diamond; and background.png, the gradient background of my icon.

To use that plugin just add it to your pubscpec.yaml file, under dev_dependencie section like such:

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_launcher_icons:

and add a new section in your pubscpec file like this:

flutter_icons:
  image_path: "assets/app_icon.png"
  android: true
  ios: true
  adaptive_icon_background: assets/background.png
  adaptive_icon_foreground: assets/foreground.png

If you are developing in VS Code and you have the dart and flutter plugins installed, simply saving the pubspec.yaml file will run flutter pub get automatically, otherwise make sure to run that command in the terminal before proceeding. The last step is to run this command in your terminal:

flutter packages pub run flutter_launcher_icons:main

This command will generate the icons for you and configure your app to use them. The next time you run your app, the icons will be updated in the emulator/device and your app will have nice custom icons.

Personally, this solution works better for me, as I prefer to stay within flutter and VS Code for my workflow. I hope this works at least as a workaround for you.