Status Update
Comments
pu...@gmail.com <pu...@gmail.com> #2
EDIT: meant TypedArray#recycle
and not TypedArray#release
ze...@google.com <ze...@google.com>
sg...@google.com <sg...@google.com> #3
Lint should show a warning in this case, as implements AutoClosable
and the use of TypedArray#close()
require API level 31. Consequently the IDE should also not suggest the refactor to try with resources unless minSdk
is at least 31.
Maybe the issue is that api-versions.xml
(from platforms/android-33/data/api-versions.xml
) only mention implements AutoClosable
, and not the close()
method
<class name="android/content/res/TypedArray" since="1">
<extends name="java/lang/Object"/>
<implements name="java/lang/AutoCloseable" since="31"/>
<method name="getBoolean(IZ)Z"/>
<method name="getChangingConfigurations()I" since="21"/>
<method name="getColor(II)I"/>
<method name="getColorStateList(I)Landroid/content/res/ColorStateList;"/>
<method name="getDimension(IF)F"/>
<method name="getDimensionPixelOffset(II)I"/>
<method name="getDimensionPixelSize(II)I"/>
<method name="getDrawable(I)Landroid/graphics/drawable/Drawable;"/>
<method name="getFloat(IF)F"/>
<method name="getFont(I)Landroid/graphics/Typeface;" since="26"/>
<method name="getFraction(IIIF)F"/>
<method name="getIndex(I)I"/>
<method name="getIndexCount()I"/>
<method name="getInt(II)I"/>
<method name="getInteger(II)I"/>
<method name="getLayoutDimension(II)I" since="3"/>
<method name="getLayoutDimension(ILjava/lang/String;)I"/>
<method name="getNonResourceString(I)Ljava/lang/String;"/>
<method name="getPositionDescription()Ljava/lang/String;"/>
<method name="getResourceId(II)I"/>
<method name="getResources()Landroid/content/res/Resources;"/>
<method name="getSourceResourceId(II)I" since="29"/>
<method name="getString(I)Ljava/lang/String;"/>
<method name="getText(I)Ljava/lang/CharSequence;"/>
<method name="getTextArray(I)[Ljava/lang/CharSequence;"/>
<method name="getType(I)I" since="21"/>
<method name="getValue(ILandroid/util/TypedValue;)Z"/>
<method name="hasValue(I)Z"/>
<method name="hasValueOrEmpty(I)Z" since="22"/>
<method name="length()I"/>
<method name="peekValue(I)Landroid/util/TypedValue;"/>
<method name="recycle()V"/>
</class>
Opened TypedArray#close()
to TypedArray#recycle()
, to make try with resources for TypedArray
supported on all API levels.
tn...@google.com <tn...@google.com>
sg...@google.com <sg...@google.com> #4
Checked api-versions.xml
for more occurrences where implements AutoCloseable
was added together with a close
method after 19 where AutoCloseable
was introduced, and found
<class name="android/content/ContentProviderClient" since="5">
<extends name="java/lang/Object"/>
<implements name="java/lang/AutoCloseable" since="24"/>
close
also added in 24, as an alias for release
.
<class name="android/drm/DrmManagerClient" since="11" deprecated="30">
<extends name="java/lang/Object"/>
<implements name="java/lang/AutoCloseable" since="24"/>
close
also added in 24, as an alias for release
.
<class name="android/media/MediaDrm" since="18">
<extends name="java/lang/Object"/>
<implements name="java/lang/AutoCloseable" since="28"/>
close
also added in 28, as an alias for release
.
<class name="android/media/MediaMetadataRetriever" since="10">
<extends name="java/lang/Object"/>
<implements name="java/lang/AutoCloseable" since="29"/>
close
also added in 29, as an alias for release
.
<class name="android/net/wifi/p2p/WifiP2pManager$Channel" since="14">
<extends name="java/lang/Object"/>
<implements name="java/lang/AutoCloseable" since="27"/>
close
also added in 27, but not as an alias, as there was no similar method before (actually close
is the only method).
Opened
tn...@google.com <tn...@google.com> #5
I forgot to mark this bug when this was fixed last week, by this CL:
It's fixed in Giraffe/8.1 but I think we should backport it to Flamingo/8.0 as well.
Søren, it sounds like you want to start desugaring these methods (good idea); maybe there should be a different tracking issue for that.
sg...@google.com <sg...@google.com> #6
Thanks Tor. I have
sa...@google.com <sa...@google.com> #7
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Giraffe Canary 1 (2022.3.1.1)
- Android Gradle Plugin 8.1.0
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
Description
Using: AS 2022.2.1 Canary 9, com.android.tools:desugar_jdk_libs:2.0.0, AGP 8.0.0-alpha09
Code below does not cause AS to show any warning that it is API 31+ only when
TypedArray#close
is invoked as part of a try-with-resources block:In fact, an IDE intention suggested that I converted my classic use to TypedArray (that is, calling
TypedArray#release
after use) to a try-with-resources block, which I did (since I saw no API warning I assumed it was either desugared or properly handled for all API levels by D8) only to see it crash on API < 31.It would be nice to have this call desugared or AS not suggesting to use try-with-resources on minApiSdk < 31 (which is probably pretty much all apps currently).