schedule2019-08-07

【Android Studio】java.lang.RuntimeException java.lang.AssertionError:Already disposed Module:'my-app'

git cloneしたAndroidのプロジェクトを端末で実行できず悩んでいたエラーを解消した。

症状は以下の通り。

  • Run/Debug ConfigurationsのModules:が<no module>しか選択できずError: Module not specifiedが出ている。
  • WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders()'.が出てビルドが止まる。(これは解消していないけど実行できるようになった)
  • idea.logに以下のエラー。
2019-08-07 11:46:03,693 [ thread 10]   WARN - ea.IdeaSyncPopulateProjectTask - Sync failed: Already disposed: Module: 'my-app' 
java.lang.RuntimeException: java.lang.AssertionError: Already disposed: Module: 'my-app'
	at com.intellij.openapi.application.impl.LaterInvocator.invokeAndWait(LaterInvocator.java:179)
	at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:678)
	at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:683)
	at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.executeOnEdt(ExternalSystemApiUtil.java:373)
	at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.executeProjectChangeAction(ExternalSystemApiUtil.java:362)
	at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl.commit(ProjectDataManagerImpl.java:461)
	at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl.importData(ProjectDataManagerImpl.java:176)
	at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl.importData(ProjectDataManagerImpl.java:253)
	at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl.importData(ProjectDataManagerImpl.java:260)
	at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.doPopulateProject(IdeaSyncPopulateProjectTask.java:121)
	at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.populate(IdeaSyncPopulateProjectTask.java:98)
	at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.access$000(IdeaSyncPopulateProjectTask.java:40)
	at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask$1.run(IdeaSyncPopulateProjectTask.java:87)
	at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:727)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:164)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:582)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:532)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:87)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:151)
	at com.intellij.openapi.progress.impl.CoreProgressManager$4.run(CoreProgressManager.java:403)
	at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:314)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.AssertionError: Already disposed: Module: 'my-app'
	at com.intellij.openapi.components.impl.ComponentManagerImpl.lambda$throwAlreadyDisposed$1(ComponentManagerImpl.java:245)
	at com.intellij.openapi.application.ReadAction.lambda$run$1(ReadAction.java:53)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:973)
	at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:57)
	at com.intellij.openapi.application.ReadAction.run(ReadAction.java:53)
	at com.intellij.openapi.components.impl.ComponentManagerImpl.throwAlreadyDisposed(ComponentManagerImpl.java:243)
	at com.intellij.openapi.components.impl.ComponentManagerImpl.getPicoContainer(ComponentManagerImpl.java:236)
	at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponent(ComponentManagerImpl.java:146)
	at com.intellij.openapi.roots.ModuleRootManager.getInstance(ModuleRootManager.java:35)
	at com.intellij.openapi.roots.impl.ModuleRootManagerImpl.doCommit(ModuleRootManagerImpl.java:170)
	at com.intellij.openapi.roots.impl.ModifiableModelCommitter.lambda$multiCommit$0(ModifiableModelCommitter.java:52)
	at com.intellij.openapi.module.impl.ModuleManagerImpl.lambda$commitModel$5(ModuleManagerImpl.java:983)
	at com.intellij.openapi.roots.impl.ProjectRootManagerImpl.makeRootsChange(ProjectRootManagerImpl.java:329)
	at com.intellij.openapi.module.impl.ModuleManagerImpl.commitModel(ModuleManagerImpl.java:968)
	at com.intellij.openapi.module.impl.ModuleManagerImpl.access$1500(ModuleManagerImpl.java:62)
	at com.intellij.openapi.module.impl.ModuleManagerImpl$ModuleModelImpl.commitWithRunnable(ModuleManagerImpl.java:876)
	at com.intellij.openapi.module.impl.ModuleManagerImpl$ModuleModelImpl.access$1200(ModuleManagerImpl.java:640)
	at com.intellij.openapi.module.impl.ModuleManagerImpl.commitModelWithRunnable(ModuleManagerImpl.java:631)
	at com.intellij.openapi.roots.impl.ModifiableModelCommitter.multiCommit(ModifiableModelCommitter.java:50)
	at com.intellij.openapi.roots.impl.ModifiableModelCommitter.multiCommit(ModifiableModelCommitter.java:39)
	at com.intellij.openapi.externalSystem.service.project.AbstractIdeModifiableModelsProvider.lambda$commit$4(AbstractIdeModifiableModelsProvider.java:458)
	at com.intellij.openapi.roots.impl.ProjectRootManagerImpl.mergeRootsChangesDuring(ProjectRootManagerImpl.java:306)
	at com.intellij.openapi.externalSystem.service.project.AbstractIdeModifiableModelsProvider.commit(AbstractIdeModifiableModelsProvider.java:432)
	at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl$3.execute(ProjectDataManagerImpl.java:465)
	at com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange.run(DisposeAwareProjectChange.java:23)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1057)
	at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.lambda$executeProjectChangeAction$4(ExternalSystemApiUtil.java:362)
	at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:315)
	at com.intellij.openapi.application.impl.LaterInvocator$1.run(LaterInvocator.java:156)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:435)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:419)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:403)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
	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:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:755)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:704)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:391)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	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)

環境

  • Windows 10 Home 64bit
  • Gradle 5.1.1
&gt;gradlew -v

------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------

Build time:   2019-01-10 23:05:02 UTC
Revision:     3c9abb645fb83932c44e8610642393ad62116807

Kotlin DSL:   1.1.1
Kotlin:       1.3.11
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_211 (Oracle Corporation 25.211-b12)
OS:           Windows 10 10.0 amd64

解消方法

※正直、よくわかっていないので参考程度に考えて下さい。

Android Studio Gradle Already disposed Module - Stack Overflowに書いてあった方法を試したところ実行できるようになった。

簡単な解決策:動作させるために最も簡単なのは.idea/modules.xml.imlファイルを削除することです。さらに、.idea/modules/フォルダーが存在する場合は削除する価値があります。Android Studioを再起動し(キャッシュをクリアする必要はありません)、GradleビューまたはツールバーからGradle同期を強制してファイルを再作成します。

.idea/フォルダと.imlを全て削除してSync Project with Gradle Filesを実行したところ、エラーを解消することができた。 .ideaはGradleから自動生成されるファイルです。 恐らく、悩んで適当にポチポチして合わないファイルを作成してしまったか、前のプロジェクト(構成を大きく変えていた)のものが残っていたことが原因(?)。

分からないのが気持ち悪いが、とりあえず動いた。。。

他に試したこと

  • gradlew clean

ローカルビルドのキャッシュを削除するコマンド。 変わらなかった。。