Symptoms
After upgrading a project to IntelliJ Platform Gradle Plugin 2.3 and running unit tests, exceptions were encountered. The first exception was regarding a TextMate bundle that could not be loaded:
ERROR: Cannot load builtin textmate bundle
...
java.lang.NoSuchMethodError: 'void kotlinx.serialization.json.JsonBuilder.setAllowTrailingComma(boolean)'
...
This issue was resolved by replacing a library file in the Contents/plugins/textmate folder. But another exception then occurred:
getService(...) must not be null
java.lang.NullPointerException: getService(...) must not be null
...
This occurred with IDEA 2024.3, Android Studio 2024.3.1, JDK21, Gradle 8.11 and IntelliJ Platform Gradle Plugin 2.3.
Cause
The exception was due to issues with how the Android plugin was being applied when using both IntelliJ and Android Studio. For IntelliJ, the Android plugin was correctly sourced from the JetBrains Marketplace, but when using Android Studio this conflicted with a bundled version of the plugin.
Resolution
Instead of treating the Android plugin as a separate plugin that is dependent on IntelliJ, it should be regarded as a bundled plugin within Android studio. This can be achieved by moving the org.jetbrains.android entry from the platformPlugins property to the platformBundledPlugins property in the Gradle build file, with no version specified:
platformPlugins =
platformBundledPlugins = ....., org.jetbrains.android
With this adjustment, the unit tests run successfully without exceptions.
Ref: Failed to run unit test: 'getService(...) must not be null' at junit.framework.TestCase.runTest (Android Studio, IJPL Gradle Plugin) Failed to run unit test: 'getService(...) must not be null' at junit.framework.TestCase.runTest (Android Studio, IJPL Gradle Plugin)
Comments
0 comments
Please sign in to leave a comment.