how to solve ava.lang.AssertionError: Leaked SDKs error?

Answered

when i run the test case use com.intellij.testFramework after the case is running ,the error popup As bellow:


Leaked SDKs: [Android API 23 Platform (/Users/androidbot/Library/Android/sdk), Android API 19 Platform (/Users/androidbot/Library/Android/sdk), Android API 27 Platform (/Users/androidbot/Library/Android/sdk), Android API 29 Platform (/Users/androidbot/Library/Android/sdk), Android API 25 Platform (/Users/androidbot/Library/Android/sdk), Android API 24 Platform (/Users/androidbot/Library/Android/sdk), Android API 26 Platform (/Users/androidbot/Library/Android/sdk), Android API 28 Platform (/Users/androidbot/Library/Android/sdk)]
java.lang.AssertionError: Leaked SDKs: [Android API 23 Platform (/Users/androidbot/Library/Android/sdk), Android API 19 Platform (/Users/androidbot/Library/Android/sdk), Android API 27 Platform (/Users/androidbot/Library/Android/sdk), Android API 29 Platform (/Users/androidbot/Library/Android/sdk), Android API 25 Platform (/Users/androidbot/Library/Android/sdk), Android API 24 Platform (/Users/androidbot/Library/Android/sdk), Android API 26 Platform (/Users/androidbot/Library/Android/sdk), Android API 28 Platform (/Users/androidbot/Library/Android/sdk)]
at org.junit.Assert.fail(Assert.java:88)
at com.intellij.testFramework.SdkLeakTracker.checkForJdkTableLeaks(SdkLeakTracker.java:54)
at com.intellij.testFramework.LightPlatformTestCase.lambda$tearDown$8(LightPlatformTestCase.java:399)
at com.intellij.testFramework.RunAll.collectExceptions(RunAll.java:53)
at com.intellij.testFramework.RunAll.run(RunAll.java:43)
at com.intellij.testFramework.RunAll.run(RunAll.java:40)
at com.intellij.testFramework.LightPlatformTestCase.tearDown(LightPlatformTestCase.java:404)
at com.intellij.testFramework.LightPlatformCodeInsightTestCase.tearDown(LightPlatformCodeInsightTestCase.java:280)
at com.sap.cloud.mobile.android.assistant.test.application.tests.uitest.common.NoUITests.tearDown(NoUITests.java:298)
at com.intellij.testFramework.LightPlatformTestCase.startRunAndTear(LightPlatformTestCase.java:577)
at com.intellij.testFramework.LightPlatformTestCase.lambda$runBareImpl$42(LightPlatformTestCase.java:542)
at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:19)
at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:14)
at com.intellij.testFramework.EdtTestUtilKt$runInEdtAndWait$2.run(EdtTestUtil.kt:65)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:301)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
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:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:349)
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)
0
9 comments

Please use com.intellij.openapi.projectRoots.ProjectJdkTable#addJdk(com.intellij.openapi.projectRoots.Sdk, com.intellij.openapi.Disposable) with com.intellij.testFramework.fixtures.CodeInsightTestFixture#getProjectDisposable as Disposable to register SDK temporarily.

0

where can i use this code? and my another machine do not have the same problem.

0

In your test code? It seems you might have different target platforms/version on the other machine.

1

yes, i have install different android sdk platform versions.  

0

Yann Cebron the Test case will generate an android application, and do some test. 

0

different target platforms/version == different IntelliJ/Android Studio Platform SDK for your plugin

the test must behave exactly the same in any case

0

I have the same problem. Leaking jdks absent in

com.intellij.openapi.projectRoots.ProjectJdkTable.getInstance().allJdks

While

com.android.tools.idea.sdk.AndroidSdks.getInstance().allAndroidSdks

returns empty collection.

So my question is: how to add jdks (android sdks) to the table? Where do I take references to those jdks?

0

evg64 Please provide full sources of your plugin/testcase to reproduce

0

Yann Cebron

I managed to reproduce it here:

https://github.com/evg64/LeakSdkExample

The project contains only 1 test-class, so no way to launch wrong test.

This IDE is used to build the project:

IntelliJ IDEA 2020.3.3 (Community Edition)
Build #IC-203.7717.56, built on March 15, 2021
Runtime version: 11.0.10+8-b1145.96 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.15.7
GC: ParNew, ConcurrentMarkSweep
Memory: 3939M
Cores: 16
Registry: documentation.show.toolbar=true, external.system.auto.import.disabled=true, debugger.watches.in.variables=false, ide.balloon.shadow.size=0

And this IDE is used as development instance:

Android Studio 4.2 Beta 6
Build #AI-202.7660.26.42.7188722, built on March 6, 2021
Runtime version: 11.0.8+10-b944.6916264 x86_64
VM: OpenJDK 64-Bit Server VM by N/A
macOS 10.15.7
GC: G1 Young Generation, G1 Old Generation
Memory: 8192M
Cores: 16
Registry: documentation.show.toolbar=true, external.system.auto.import.disabled=true, debugger.watches.in.variables=false, ide.balloon.shadow.size=0
Non-Bundled Plugins: AceJump, Key Promoter X, com.weirddev.testme, org.jetbrains.kotlin, com.chrisrm.idea.MaterialThemeUI, izhangzhihao.rainbow.brackets, org.intellij.plugins.markdown

It is important that Android SDK is downloaded and development instance is configured to see that SDK. As many SDK platforms are downloaded, that many platforms will leak. For example, if I have android-28 and android-29 downloaded, I get the following error:

java.lang.AssertionError: Leaked SDKs: [Android API 29 Platform (~/Library/Android/sdk), Android API 28 Platform (~/Library/Android/sdk)]. Please remove leaking SDKs by e.g. ProjectJdkTable.getInstance().removeJdk() or by disposing the ProjectJdkImpl
0

Please sign in to leave a comment.