Getting exception: java.lang.ClassNotFoundException: com.android.tools.idea.common.editor.SmartRefreshable

Answered

I'm getting the following error for my plugin in Android Studio

com.intellij.diagnostic.PluginException: While loading class com.plugin.studio.myplugin.MyCustomViewPreview: com/android/tools/idea/common/editor/SmartRefreshable [Plugin: com.plugin.studio.myplugin]
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:262)
at com.intellij.ide.plugins.cl.PluginClassLoader.tryLoadingClass(PluginClassLoader.java:205)
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:113)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
at com.plugin.studio.myplugin.MyCustomViewPreview.createEditor(MyCustomViewPreview.kt:57)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl4Edt(FileEditorManagerImpl.java:826)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.lambda$null$8(FileEditorManagerImpl.java:796)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.runBulkTabChange(FileEditorManagerImpl.java:1635)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.lambda$openFileImpl4$9(FileEditorManagerImpl.java:795)
at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:467)
at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:485)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl4(FileEditorManagerImpl.java:794)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl3(FileEditorManagerImpl.java:739)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.lambda$openFileImpl2$5(FileEditorManagerImpl.java:722)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:212)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:178)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:168)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:154)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl2(FileEditorManagerImpl.java:722)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileWithProviders(FileEditorManagerImpl.java:653)
at com.intellij.openapi.fileEditor.ex.FileEditorManagerEx.openFile(FileEditorManagerEx.java:138)
at com.intellij.codeInsight.navigation.NavigationUtil.activatePsiElementIfOpen(NavigationUtil.java:203)
at com.intellij.codeInsight.navigation.NavigationUtil.lambda$openFileWithPsiElement$1(NavigationUtil.java:173)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:178)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:168)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:154)
at com.intellij.codeInsight.navigation.NavigationUtil.openFileWithPsiElement(NavigationUtil.java:172)
at com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode.navigate(AbstractPsiBasedNode.java:239)
at com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode.navigate(AbstractPsiBasedNode.java:249)
at com.intellij.ide.projectView.impl.nodes.PsiFileNode.navigate(PsiFileNode.java:115)
at com.intellij.util.OpenSourceUtil.navigateToSource(OpenSourceUtil.java:119)
at com.intellij.util.OpenSourceUtil.navigate(OpenSourceUtil.java:74)
at com.intellij.util.OpenSourceUtil.navigate(OpenSourceUtil.java:58)
at com.intellij.util.OpenSourceUtil.navigate(OpenSourceUtil.java:51)
at com.intellij.util.OpenSourceUtil.openSourcesFrom(OpenSourceUtil.java:19)
at com.intellij.util.EditSourceOnDoubleClickHandler$TreeMouseListener.processDoubleClick(EditSourceOnDoubleClickHandler.java:121)
at com.intellij.util.EditSourceOnDoubleClickHandler$TreeMouseListener.onDoubleClick(EditSourceOnDoubleClickHandler.java:115)
at com.intellij.ui.DoubleClickListener.onClick(DoubleClickListener.java:30)
at com.intellij.ui.ClickListener$1.mouseReleased(ClickListener.java:63)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6550)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3325)
at com.intellij.ui.treeStructure.Tree.processMouseEvent(Tree.java:394)
at com.intellij.ide.dnd.aware.DnDAwareTree.processMouseEvent(DnDAwareTree.java:44)
at java.awt.Component.processEvent(Component.java:6315)
at java.awt.Container.processEvent(Container.java:2239)
at java.awt.Component.dispatchEventImpl(Component.java:4899)
at java.awt.Container.dispatchEventImpl(Container.java:2297)
at java.awt.Component.dispatchEvent(Component.java:4721)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
at java.awt.Container.dispatchEventImpl(Container.java:2283)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4721)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
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:74)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
at java.awt.EventQueue$4.run(EventQueue.java:739)
at java.awt.EventQueue$4.run(EventQueue.java:737)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:736)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:974)
at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.java:912)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:844)
at com.intellij.ide.IdeEventQueue.lambda$null$8(IdeEventQueue.java:449)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:741)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:448)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:502)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
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)
Caused by: java.lang.NoClassDefFoundError: com/android/tools/idea/common/editor/SmartRefreshable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
at java.lang.ClassLoader.defineClass(ClassLoader.java:636)
at com.intellij.util.lang.UrlClassLoader._defineClass(UrlClassLoader.java:380)
at com.intellij.util.lang.UrlClassLoader.defineClass(UrlClassLoader.java:376)
at com.intellij.util.lang.UrlClassLoader._findClass(UrlClassLoader.java:340)
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:259)
... 84 more
Caused by: java.lang.ClassNotFoundException: com.android.tools.idea.common.editor.SmartRefreshable PluginClassLoader[com.plugin.studio.myplugin, 1.0-SNAPSHOT] com.intellij.ide.plugins.cl.PluginClassLoader@36994f23
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:115)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
... 91 more

 

This is the build.gradle.kts file.

plugins {
id("org.jetbrains.intellij") version "0.6.5"
java
kotlin("jvm") version "1.4.20"
}

version = "1.0-SNAPSHOT"
group = "com.plugin.studio.myplugin"

repositories {
mavenCentral()
}

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20")
}
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
testImplementation("junit:junit:4.12")
}


intellij {
pluginName = "MyPlugin"
version = "201.8743.12"
type = "IC"
setPlugins("java", "android", "org.jetbrains.kotlin:1.4.20-release-Studio4.1-1")
}

configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks {

compileKotlin {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = freeCompilerArgs + "-Xjvm-default=compatibility"
}
}
compileTestKotlin {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = freeCompilerArgs + "-Xjvm-default=compatibility"
}
}

runIde {
setIdeDirectory("/Applications/Android Studio.app/Contents")
}
}

tasks.getByName<org.jetbrains.intellij.tasks.PatchPluginXmlTask>("patchPluginXml") {
changeNotes(
"""
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
)
}

 

I've also posted another problem which is while building the project I'm getting an error message but the build is successful always. The link to that post is here

2 comments
Comment actions Permalink

So I found the reason.

I did set the compatible Android Studio version in the build.gradle.kts. Which is
201.8743.12 fo Android Studio 4.1.1.


The thing is The Android Studio is shipped with an android plugin which version is different. That is 201.8743.12.41.6953283. 

But if use the following config it adds android plugin 201.8743.12 it is adding the android plugin with version number 201.8743.12.

intellij { 
pluginName = "MyPlugin"
version = "201.8743.12"
type = "IC"
setPlugins("java", "Kotlin", "android")
}
0

Please sign in to leave a comment.