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
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With