Status Update
Comments
ap...@google.com <ap...@google.com> #2
Branch: main
commit 2d2a166471b7a50f374167b625f18d8e39080f06
Author: Søren Gjesse <sgjesse@google.com>
Date: Mon Apr 19 12:53:20 2021
Backport android.util.SparseArray#set
For Android S android.util.SparseArray#set was added as an alias for
android.util.SparseArray#put.
Bug: 185547135
Change-Id: I6b3558921a14fc3e0ac7766db8c6b6e614d0c236
M src/main/java/com/android/tools/r8/graph/DexItemFactory.java
M src/main/java/com/android/tools/r8/ir/desugar/BackportedMethodRewriter.java
A src/main/java/com/android/tools/r8/ir/desugar/backports/SparseArrayMethodRewrites.java
M src/test/java/com/android/tools/r8/desugar/backports/AbstractBackportTest.java
A src/test/java/com/android/tools/r8/desugar/backports/SparseArrayBackportTest.java
sg...@google.com <sg...@google.com>
sg...@google.com <sg...@google.com> #3
Just did a sanity check with Android Studio compiling the following code:
val sa = SparseArray<String>(1)
sa[0] = "Hello, world!"
println("Value is ${sa[0]}")
Using compileSdkVersion "android-S"
with this change:
invoke-virtual {v5, v4, v3}, Landroid/util/SparseArray;->put(ILjava/lang/Object;)V
Using compileSdkVersion "android-S"
without this change:
invoke-virtual {v5, v4, v3}, Landroid/util/SparseArray;->set(ILjava/lang/Object;)V
Using import androidx.core.util.set
with either compileSdkVersion "android-S"
or compileSdkVersion 30
:
invoke-virtual {v5, v4, v3}, Landroid/util/SparseArray;->put(ILjava/lang/Object;)V
With compileSdkVersion "android-S"
import androidx.core.util.set
is also marked as unused import.
al...@gmail.com <al...@gmail.com> #4
Hi Googler,
Does this fix apply to the unit test build?
When I build and run my App on a device with API level 25, it works properly.
But my test fails by NoSuchMethedError
.
'void android.util.SparseArray.set(int, java.lang.Object)'
java.lang.NoSuchMethodError: 'void android.util.SparseArray.set(int, java.lang.Object)'
The attached is a sample project.
If you run the test SparseArrayIssueTest#addItemWithSet
, you will find this error.
Could you have a look? Thank you.
sg...@google.com <sg...@google.com> #5
Units tests running via Robolectric will not get the backport rewrite from set
method is not rewritten to put
.
The good news is that Android S support is landing in Robolectric, so if you update the dependency to
testImplementation 'org.robolectric:robolectric:4.7-alpha-2'
and also add the following to the app build.gradle
(see
android {
testOptions {
unitTests.includeAndroidResources true
}
}
The you can run the test for API level 31, by either annotating the test with @org.robolectric.annotation.Config(sdk = [31])
or setting sdk=31
in robolectric.properties
. Alternatively set targetSdk
to 31
in build.gradle
and then you don't need neither the annotation nor robolectric.properties
as by default Robolectric will run on targetSdk
.
sg...@google.com <sg...@google.com> #6
Opened
Description
SparseArray.set was added as an alias for SparseArray.put in Android S.
Consider backporting that by rewriting
SparseArray.set
toSparseArray.put
.Context: