Remove JRE entry from External Library for Android Studio project



I am building a project for a specific environment which must no rely on the standard JRE. Standard Java APIs are provided by other project dependencies. Therefore I would like to remove the JRE entry from the External Dependencies.

I can remove it by deleting the following line from the .iml file:

<orderEntry type="inheritedJdk" />

but it is added back as soon as I reload the Gradle project.

Is there a way to remove it permanently ?




Register listener com.intellij.openapi.externalSystem.service.project.manage.ProjectDataImportListener and modify IDE-side model accordingly (



Thanks for your answer.

I tried to use the listener ProjectDataImportListener by creating this class:

class MyProjectDataImportListener : ProjectDataImportListener {
override fun onImportFinished(projectPath: String?) {
val Log: Logger = Logger.getInstance("logger")
Log.error("#### onImportFinished ...")

override fun onImportFailed(projectPath: String?) {

and adding it in the plugin.xml file:

   <listener class="" topic="com.intellij.openapi.externalSystem.service.project.manage.ProjectDataImportListener"/>

But it does not seem to be executed.

I tried the same thing with the listener ProjectManagerListener, it is well called:

override fun projectOpened(project: Project) {
val Log = Logger.getInstance("logger")"#### MyProjectManagerListener ...")

val r = Runnable {
val projectSdk: Sdk? = ProjectRootManager.getInstance(project).projectSdk"#### Name = " + projectSdk?.name)
ProjectRootManager.getInstance(project).projectSdk = null
WriteCommandAction.runWriteCommandAction(project, r);

Not sure it is the right way to remove the SDK but the SDK does not appear anymore in the External Libraries. The remaining problem is that it appears again as soon as I reload the Gradle project (right-click on the project in the Gradle view > Reload Gradle project).

Would the use of ProjectDataImportListener listener solve this problem ? Should I use another listener ?




I found a way to have the JRE entry removed even after a Gradle project reload by using the extension com.intellij.openapi.roots.ProjectExtension:

internal class MyProjectExtension(private val myProject: Project) : ProjectExtension() {

  override fun projectSdkChanged(sdk: Sdk?) {
    if(sdk != null) {
      ProjectRootManager.getInstance(myProject).projectSdk = null


<extensions defaultExtensionNs="com.intellij">
   <projectExtension implementation=""></projectExtension>

The drawback is that this extension is an internal API. But I didn't find a better way so far.

Also I would like to be able to do the same thing but as the module level : in a project, a module uses the JRE as a dependency and another one does not. I tried to use the ModuleManager API but did not find a way to remove the JRE entry. Is this even possible ?




It seems your ProjectDataImportListener doesn't have Project CTOR parameter, then it should work.


class MyListener(val project: Project) : ProjectDataImportListener {...}

Please sign in to leave a comment.