Multiple class loaders loading same library class AndroidSdkType issue

Sharankruthi

Mar 30, 09:58

Hi,

Am developing a plugin to extend new project wizard.

When I try to call AndroidSdkUtils.isAndroidSdkAvailable() am getting Assertion:null, Pasted the error below,

null
java.lang.AssertionError
at com.intellij.openapi.projectRoots.SdkType.findInstance(SdkType.java:207)
at org.jetbrains.android.sdk.AndroidSdkType.getInstance(AndroidSdkType.java:231)
at org.jetbrains.android.sdk.AndroidSdkUtils.getAllAndroidSdks(AndroidSdkUtils.java:462)
at org.jetbrains.android.sdk.AndroidSdkUtils.getAndroidSdkPathsFromExistingPlatforms(AndroidSdkUtils.java:443)
at org.jetbrains.android.sdk.AndroidSdkUtils.tryToChooseAndroidSdk(AndroidSdkUtils.java:853)
at com.android.tools.idea.npw.ConfigureAndroidProjectPath.putSdkDependentParams(ConfigureAndroidProjectPath.java:97)
at com.android.tools.idea.npw.ConfigureAndroidProjectPath.init(ConfigureAndroidProjectPath.java:59)
at com.android.tools.idea.wizard.dynamic.DynamicWizardPath.attachToWizard(DynamicWizardPath.java:98)
at com.android.tools.idea.wizard.dynamic.DynamicWizard.addPath(DynamicWizard.java:242)
at com.android.tools.idea.npw.NewProjectWizardDynamic.addPaths(NewProjectWizardDynamic.java:84)
at tru.NewModuleWizardDynamicExtension.init(NewModuleWizardDynamicExtension.java:27)
at NewProAction.actionPerformed(NewProAction.java:30)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:182)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter$1.run(ActionMenuItem.java:311)
at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:958)
at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:124)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:281)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:109)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:308)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at com.apple.laf.ScreenMenuItemCheckbox.itemStateChanged(ScreenMenuItemCheckbox.java:193)
at java.awt.CheckboxMenuItem.processItemEvent(CheckboxMenuItem.java:389)
at java.awt.CheckboxMenuItem.processEvent(CheckboxMenuItem.java:357)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:351)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:339)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:761)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:866)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:654)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:381)
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)

This happens because findInstance method tries to compare AndroidSdkType.Class with one of the sdkType class inside a for loop, Classes are actually same but loaded by two different loaders, one from (org.jetbrains.android) and other from local loader (com.sample.sample)

How Do I solve this issue?

Because of this class loader issue, I often get classcastexception also. So when I try using different ways to develop plugin am struck with this class loader issue.

Kindly give a solution asap.

2 comments

You must add dependencies to Android plugin libraries to your IntelliJ Platform SDK, not to your module's dependencies

1

Thank you very much Yann. This hint led me to this documentation 

http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html

This is very useful information for those who are struggling from library classes loading in two different class loaders. 

And yes I was able to successfully execute my plugin code.

For the sake of others, am attaching the screenshot where "android.jar" is added in the classpath of Plugin SDK.

And the following is the code snippet that I added to plugin.xml file where "org.jetbrains.android" is the plugin ID of "android.jar" plugin.

<depends>org.jetbrains.android</depends>

And also as am developing this for android studio, I was not able to run in Intellij IDE
but was able to execute in android studio.

1

Please sign in to leave a comment.