Execute test while org.jetbrains.android is added as dependency

Answered

Plugin org.jetbrains.android is declared as dependency in build.gradle.kts:

intellij { 
localPath = <path to android studio 4.2>
setPlugins("java", "org.jetbrains.kotlin", "org.intellij.groovy", "org.jetbrains.android")
...
}

When I execute task runIde, it works fine.

However, when task test is executed, I get error at runtime:

ERROR: Cannot create class org.jetbrains.android.dom.drawable.fileDescriptions.AdaptiveIconDomFileDescription [Plugin: org.jetbrains.android]
com.intellij.diagnostic.PluginException: Cannot create class org.jetbrains.android.dom.drawable.fileDescriptions.AdaptiveIconDomFileDescription [Plugin: org.jetbrains.android]
at com.intellij.serviceContainer.ComponentManagerImpl.instantiateClass(ComponentManagerImpl.kt:656)
at com.intellij.openapi.extensions.impl.ExtensionComponentAdapter.instantiateClass(ExtensionComponentAdapter.java:50)
at com.intellij.openapi.extensions.impl.XmlExtensionAdapter$SimpleConstructorInjectionAdapter.instantiateClass(XmlExtensionAdapter.java:133)
....
Caused by: java.lang.NoClassDefFoundError: com/android/resources/ResourceFolderType
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3137)
at java.base/java.lang.Class.getConstructor0(Class.java:3342)
at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2553)
at com.intellij.serviceContainer.ComponentManagerImpl.instantiateClass(ComponentManagerImpl.kt:613)
... 45 more
Caused by: java.lang.ClassNotFoundException: com.android.resources.ResourceFolderType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 50 more

I failed to upload txt file with entire exception, but it is actually much longer.

 

Once I remove "org.jetbrains.android" from setPlugins:

setPlugins("java", "org.jetbrains.kotlin", "org.intellij.groovy")

it begins to work (task test executes fine).

 

It looks like "org.jetbrains.android" is absent in IDE instance, which is used to execute test. But in which IDE instance tests are executed?

My test class:

public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase {

@Override
protected String getTestDataPath() {
return "testData";
}

public void testCompletion() {
}
}

Nothing is tested actually, I`m just starting in plugin testing.

 

So my question is: what to do to execute tests with "org.jetbrains.android" plugin declared as dependency in build.gradle.kts?

0
6 comments

I had to add all dependencies of org.jetbrains.android to setPlugins.

It turned out to be quite verbose:

gradle.properties:
platformPlugins = java, org.jetbrains.kotlin, org.intellij.groovy, org.jetbrains.android, com.android.tools.idea.smali, com.android.layoutlib.standard, intellij.webp, org.jetbrains.plugins.gradle, com.android.layoutlib.native, com.intellij.properties, JUnit, com.intellij.platform.images, org.jetbrains.kotlin, org.intellij.intelliLang, org.intellij.groovy
build.gradle.kts:
setPlugins(*platformPlugins.split(',').map(String::trim).filter(String::isNotEmpty).toTypedArray())

I`m not sure, all of them are necessary though.

0

Do you build _and_ run against exact same IDE?

0

intellij.localPath and runIde.ideDirectory have the same value, so as far as I understand, yes, I build and run against the same IDE.

0

I've debugged the libraries attached to the testRuntimeClasspath, and in the first case:

setPlugins("java", "org.jetbrains.kotlin", "org.intellij.groovy", "org.jetbrains.android")

there are almost all the required plugins present:

testRuntimeClasspath - Runtime classpath of compilation 'test' (target  (jvm)).
+--- com.jetbrains:ideaLocal:AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:java:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:Kotlin:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:Groovy:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:android:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:properties:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:platform-images:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:IntelliLang:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:junit:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:webp:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:gradle-java:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:smali:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:gradle:ideaLocal-AI-202.7660.26.42.7351085
\--- org.jetbrains:annotations:21.0.0

Comparing to the verbose list, the following two are added:

+--- unzipped.com.jetbrains.plugins:android-layoutlib:ideaLocal-AI-202.7660.26.42.7351085
+--- unzipped.com.jetbrains.plugins:android-layoutlib-native:ideaLocal-AI-202.7660.26.42.7351085

but to make the test running, you'll have to add to the plugins list:

"com.android.layoutlib.standard"

 

0

I've checked, why the layoutlib is not loaded automatically, and this is because it is marked as optional:

<!-- One of the layoutlib plugins is required -->
<depends optional="true" config-file="layoutlib-native.xml">com.android.layoutlib.native</depends>
<depends optional="true" config-file="layoutlib-standard.xml">com.android.layoutlib.standard</depends>

I bet one of them is enabled automatically in the runtime, but when obtaining plugins for the classpath, none is picked because of that flag.

0

Adding only layoutlib works as well. The less verbose, the better, thank you.

Interesting though, these 2 libs are not truly optional.

0

Please sign in to leave a comment.