现象
Mac电脑某一天突然打不开 Android Studio,点击之后,图标跳动一下之后就没有任何反应了,有时候会有一个弹窗,提示有错误,出现三个按钮,“重试”、“发送错误报告”、“退出”(大致是这个意思,交互具体是什么不记得了)。卸载重装也没有任何用处,电脑也关了重启过。
关于如何卸载Android Studio不赘述,网上很多教程。
解决
1.1 查看错误日志
“访达” -> "Application" -> "Android Studio" -> 右键 "显示包内容" -> 一路找到 "studio" -> 双击运行 附了一张图跟直观
我的错误日志如下:
Last login: Fri May 19 17:31:15 on ttys000
/Applications/Android\ Studio.app/Contents/MacOS/studio ; exit;
➜ ~ /Applications/Android\ Studio.app/Contents/MacOS/studio ; exit;
2023-05-19 17:31:32.672 studio[3626:33500] allVms required 1.8*,1.8+
2023-05-19 17:31:32.672 studio[3626:33504] Current Directory: /Users/user
2023-05-19 17:31:32.673 studio[3626:33504] parseVMOptions: STUDIO_VM_OPTIONS = /Users/user/Downloads/jetbra/vmoptions/studio.vmoptions
2023-05-19 17:31:32.674 studio[3626:33504] parseVMOptions: platform=-1 user=-1 file=(null)
2023-05-19 17:31:32.727 studio[3626:33504] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
*** First throw call stack:
(
0 CoreFoundation 0x00000001a2d44418 __exceptionPreprocess + 176
1 libobjc.A.dylib 0x00000001a288eea8 objc_exception_throw + 60
2 CoreFoundation 0x00000001a2d6d830 _CFBundleGetValueForInfoKey + 0
3 AppKit 0x00000001a5f42bd8 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 320
4 AppKit 0x00000001a5f31730 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 816
5 AppKit 0x00000001a608c484 -[NSPanel _initContent:styleMask:backing:defer:contentView:] + 48
6 AppKit 0x00000001a5f313f4 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 48
7 AppKit 0x00000001a608c438 -[NSPanel initWithContentRect:styleMask:backing:defer:] + 48
8 AppKit 0x00000001a5f2ffe0 -[NSWindowTemplate nibInstantiate] + 216
9 AppKit 0x00000001a5f02e60 -[NSIBObjectData instantiateObject:] + 212
10 AppKit 0x00000001a5f02828 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 252
11 AppKit 0x00000001a5ef85d8 loadNib + 340
12 AppKit 0x00000001a5ef7c08 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 560
13 AppKit 0x00000001a5ef790c -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 180
14 AppKit 0x00000001a61cb098 -[NSAlert init] + 92
15 studio 0x00000001026a8be0 parseVMOptions + 1092
16 studio 0x00000001026a7bd8 -[Launcher buildArgsFor:] + 180
17 studio 0x00000001026a81e8 -[Launcher launch] + 644
18 Foundation 0x00000001a3bc9470 __NSThread__start__ + 716
19 libsystem_pthread.dylib 0x00000001a2bea06c _pthread_start + 148
20 libsystem_pthread.dylib 0x00000001a2be4e2c thread_start + 8
)
libc++abi: terminating with uncaught exception of type NSException
[1] 3626 abort /Applications/Android\ Studio.app/Contents/MacOS/studio
Saving session...completed.
[进程已完成]
解决
提示一个进程错误,就很迷惑,翻遍全网找到了如下相似解决方案: youtrack.jetbrains.com/issue/JBR-4…
里面有人提出了解决方案,操作如下:
- 打开下面的文件: /Users/{USER_NAME}/Library/LaunchAgents/jetbrains.vmoptions.plist
- 移除
launchctl setenv "*_OPTIONS" - 保存后删除
- 重启电脑
第二点具体删除 ‘STUDIO_VM_OPTIONS’ 即可
Android上述方法,就解决了 NSException 错误。