melos icon indicating copy to clipboard operation
melos copied to clipboard

fix: Android Studio crashes when uses Melos

Open ChaserVasya opened this issue 3 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues.

Version

2.7.0

Description

Flutter project. When AS tries to index project it is broken with exception below. It makes AS useless. It has started after installing Melos.

java.lang.IllegalStateException: Exclude folder file://C:/Dev/Projects/mobile-websales-git/.dart_tool must be under content entry file://C:/Dev/Projects/mobile-websales-git/.
	at com.intellij.workspaceModel.ide.impl.legacyBridge.module.roots.ModifiableContentEntryBridge.addExcludeFolder(ModifiableContentEntryBridge.kt:111)
	at com.intellij.workspaceModel.ide.impl.legacyBridge.module.roots.ModifiableContentEntryBridge.addExcludeFolder(ModifiableContentEntryBridge.kt:126)
	at com.intellij.openapi.roots.ModuleRootModificationUtil.lambda$updateExcludedFolders$12(ModuleRootModificationUtil.java:168)
	at com.intellij.openapi.roots.ModuleRootModificationUtil.lambda$updateModel$9(ModuleRootModificationUtil.java:134)
	at com.intellij.openapi.roots.ModuleRootModificationUtil.modifyModel(ModuleRootModificationUtil.java:142)
	at com.intellij.openapi.roots.ModuleRootModificationUtil.updateModel(ModuleRootModificationUtil.java:133)
	at com.intellij.openapi.roots.ModuleRootModificationUtil.updateExcludedFolders(ModuleRootModificationUtil.java:161)
	at com.jetbrains.lang.dart.DartStartupActivity.excludeBuildAndToolCacheFolders(DartStartupActivity.java:97)
	at com.jetbrains.lang.dart.DartStartupActivity.lambda$runActivity$2(DartStartupActivity.java:64)
	at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:214)
	at com.intellij.openapi.application.TransactionGuardImpl.access$200(TransactionGuardImpl.java:21)
	at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:196)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:805)
	at com.intellij.openapi.application.impl.ApplicationImpl.lambda$invokeLater$4(ApplicationImpl.java:348)
	at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:82)
	at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:131)
	at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:47)
	at com.intellij.openapi.application.impl.FlushQueue$FlushNow.run(FlushQueue.java:187)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:891)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:760)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:447)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:818)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:446)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:805)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:492)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
...
  • Dart Plugin - 213.7371
  • AS - 2021.3.1

Steps to reproduce

Install Melos melos bootstrap open flutter project

Expected behavior

there is no exceptions

Screenshots

Result of broken analyzer (not parsed to OOP-entities file) image

Part of file hierarchy described in exception (little more then described) image

Additional context and comments

No response

ChaserVasya avatar Sep 22 '22 01:09 ChaserVasya

Thanks for reporting this issue! Looks related to https://github.com/invertase/melos/issues/324#issuecomment-1215233568. I'll have to look into this, but this looks more like a bug in AS or the Dart Plugin.

blaugold avatar Sep 25 '22 14:09 blaugold

Also having the same issue. Detailed my issue on this link too: https://github.com/flutter/flutter-intellij/issues/6656 Have found that the one thing that seems to sort-of help is.

  1. Copy both root folder .iml files somewhere and delete them from the project.
  2. Restart android studio.
  3. Run melos clean and flutter clean.
  4. Paste the .iml files back in.
  5. Restart android studio. Run melos bootstrap.
  6. The problem is fixed in all packages in some packages.

However if nothing else helps then need to clone project again and open up the project in a new window. That takes away all issues however it takes time setting everything up again..

aleks5751 avatar Mar 05 '23 16:03 aleks5751

@aleks5751 Could you post your melos.yaml config?

blaugold avatar Mar 07 '23 22:03 blaugold

Hi,

File upload is not supported for .yaml type. Since its a short file I will just add it here:

name: melos

packages:
  - packages/**
  - '*'

scripts:
  postbootstrap:
    melos exec -c 1 --fail-fast --file-exists="l10n.yaml" -- \
    flutter gen-l10n
  analyze:
    exec: flutter analyze . --fatal-infos --fatal-warnings

aleks5751 avatar Mar 08 '23 14:03 aleks5751

@aleks5751 Thanks. I've seen this problem in other Melos workspaces and the issue seems to be related to having a Dart package at the root of the workspace and bootstrapping it with Melos, so that Melos generates an IntelliJ IDEA config file for that package. This seems like a bug in the IntelliJ Dart/Flutter plugin.

A workaround is to not include the package in the Melos workspace, so in this case removing the '*' pattern from packages and deleting the .iml file at the workspace root, that was generated by Melos.

blaugold avatar Mar 08 '23 20:03 blaugold

Epic @blaugold !! It seems that this fixed it for me. I will let you know if I find any downsides to it but it seems to do the trick atm.

Added an answer here too: https://github.com/flutter/flutter-intellij/issues/6656#issuecomment-1461808422

Not sure why it was doing this but might be something that could be included in the initial setup of melos section of the melos docs as a warning. As it seems that this could happen for more people.

Thank you so much for the help!

aleks5751 avatar Mar 09 '23 11:03 aleks5751

Is there any update on it?

AlexeyKatsuro avatar Jul 02 '23 09:07 AlexeyKatsuro

@AlexeyKatsuro I took another look and finally found the issue.

@aleks5751 Thanks for filing the issue in flutter/flutter-intellij. The information in that thread helped me find the root cause.

blaugold avatar Jul 02 '23 17:07 blaugold

when will be release new version with this bugfix ?

jiechic avatar Jul 04 '23 02:07 jiechic

@Salakar If you have time, there are a few fixes that could be released.

blaugold avatar Jul 04 '23 07:07 blaugold

I use next command for get new version before new version release dart pub global activate -sgit https://github.com/invertase/melos.git --git-path "packages/melos"

jiechic avatar Jul 14 '23 05:07 jiechic