cannot load api descriptions from ../android-sdk/platform-tools/api/api-versions.xml java.io.IOException: Stream closed
Asked Answered
C

4

19

After I update android studio to v2020.3.1 (Arctic Fox). I can't run my project because I always get this error message.

cannot load api descriptions from ../Android/android-sdk/platform-tools/api/api-versions.xml java.io.IOException: Stream closed

I've tried to revert to v4.2.2, still getting the same error.

Note: I am using Ubuntu 20.04

Crocus answered 3/8, 2021 at 10:56 Comment(3)
This error happens intermittently for me--I only see the error pop up occasionally. For me it happens for both command-line builds, and builds in Android Studio on both Arctic Fox and pre-Arctic Fox.Audette
@Audette have you found any solution?Waynewayolle
No. Per issue tracker it will be fixed in a future version of Android Gradle Plugin: issuetracker.google.com/issues/196847367Audette
F
14

I copied the contents of the file of this snippet:

https://gitlab.com/-/snippets/2164806

in the platform-tools directory it complains it can not load the /api/api-versions.xml and the error did not show up anymore.

There is no need to downgrade the platform-tools.

Fulgurite answered 20/8, 2021 at 14:15 Comment(2)
This should be the accepted answer! Btw according to comments at this issue issuetracker.google.com/issues/196847367?pli=1 it should be fixed in AGP 7.1 canary 12.Biannual
Thanks @jeprubio, it helped me a lot!Pub
R
6

I have encountered this problem recently as well and I have further investigated the issue, since I couldn't downgrade the platform-tools version (since it occurred on the build server, where I dont control the platform-tools version, its controlled by Microsoft).

Here are my findings: This issue only arises in large Android projects, probably when there are multiple modules involved.

The cause of the issues are related to class SdkUtils (see the source file). The SdkUtils class has a hard reference to the file platform-tools/api/api-versions.xml, but with the latest platform-tools (31.0.3), this file is no longer there.

The fallback implemented in the SdkUtils class is that it will read the api-versions from the resources (by doing getClass().getClassLoader().getResource("api-versions.xml").openStream();). For small Android projects this is fine. But what I noticed is that with larger Android projects, with multiple modules / tasks being built in parallel, some of these streams get closed (hence the Stream Closed exception).

I raised an issue with google, and they're on it trying to fix it (see the issuetracker link here).

While Google is solving this issue the appropriate way, the easiest solution is to just downgrade your platform-tools 1 version (as stated in another answer).

However, if you, like me, do not control the platform-tools version (since it is managed by AzureDevops in my case), I created a temporary workaround. I added a bash task to my CI/CD pipeline where I copy the api-versions.xml file to platform-tools, so it will use that file instead of the resources. It looks like so:

steps:
  - bash: |
    echo Android sdk location: $ANDROID_SDK_ROOT
    mkdir $ANDROID_SDK_ROOT/platform-tools/api/
    cp $ANDROID_SDK_ROOT/platforms/android-30/data/api-versions.xml $ANDROID_SDK_ROOT/platform-tools/api/

I copy from platforms/android-30/data/api-versions.xml, since that is file they will use in official fix by google as well (but then maybe not hardcoded android-30, but dynamically based on your build settings).

Rickard answered 18/8, 2021 at 12:11 Comment(0)
C
4

I found a solution! Turns out, I just need to downgrade the platform-tools in the SDK folder to v31.0.2.

We can download it on https://androidsdkmanager.azurewebsites.net/Platformtools.

Crocus answered 5/8, 2021 at 3:35 Comment(3)
what do you mean by "downgrade"? unselect the latest, and only select 31.0.2? cmiiwOstia
Is there any official website to download the old version? It will be glad if u can provide itDakar
@Ostia I deleted the platform-tools folder in the sdk folder, then downloaded version one below through the link above to replace the previously deleted platform-tools folder.Crocus
S
1

I am really not sure what caused this issue but Invalidating the caches and restarting AS has fixed the issue for me.

My wild guess is that AS Arctic Fox relies on JDK 11 to run and maybe the IDE was looking in the wrong jdk version

Shirting answered 3/8, 2021 at 12:24 Comment(4)
I've used JDK 11 in android studio, and I've tried Invalidates Caches / Restart, but still no changes. Btw, this case only happens in one project that is quite heavy, I've tried in other projects no problem.Crocus
I have the same issue, tried by invalidating caches and restarting AS and selecting JDK 11 for the project. Still have the issue. Could it be a problem of JDK 11 vs old gradle plugin? My project uses gradle 6.1.1...Theatrical
Also, it doesn't always happen. Building, rebuilding and rebuilding again finally results in a build. I really don't know what's happening...Theatrical
This is frustrating, looks like I have to downgrade ASGerfalcon

© 2022 - 2025 — McMap. All rights reserved.