Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overload resolution ambiguity HashMap.get kotlin

I just updated the Android Q SDK to revision 2 in android studio and now I get an error with getting values from a hashmap

enter image description here

it is HashMap<String,String> and this code was fine until I did the update in android studio to Q revision 2.

This is where my HashMap comes from

val map = HashMap<String,String>()
map["owner"] = shipment.owner
map["current"] = signedInUser
shipmentOwnedLiveData.postValue(map)

I found a question similar to this but non-android related and its a few years old

Anyone know what the issue is or how to fix it?

Edit:

Seems like it also broke ArrayLists too as calling .contains or .remove on a collection also throws an ambiguity error.

it looks like there are duplicate methods for all of these

Edit 2:

Looks like I am not the only person with this issue

https://issuetracker.google.com/issues/139041608#comment3

like image 222
tyczj Avatar asked Aug 07 '19 18:08

tyczj


3 Answers

It was a bug with the latest Android SDK 29 release until Google rolled back the update. See https://issuetracker.google.com/issues/139041608.

If you were unfortunate enough to install platforms;android-29 revision 2 before they rolled it back, you'll have to downgrade back to revision 1. You can do this by first uninstalling the package using the $ANDROID_HOME/tools/bin/sdkmanager tool.

sdkmanager --uninstall "platforms;android-29"

Then remove revision 2 from the cache by removing the "platforms;android-29" element containing <major>2</major> from $HOME/.android/cache/sdkbin-1_b735609c-repository2-1_xml:

<remotePackage path="platforms;android-29">
  <!--Generated from bid:5747142, branch:qt-release-->
  <type-details xsi:type="sdk:platformDetailsType">
    <api-level>29</api-level>
    <codename></codename>
    <layoutlib api="15"/>
  </type-details>
  <revision>
    <major>2</major>
  </revision>
  <display-name>Android SDK Platform 29</display-name>
  <uses-license ref="android-sdk-license"/>
  <channelRef ref="channel-0"/>
  <archives>
    <archive>
      <!--Built on: Tue Jul 23 11:56:59 2019.-->
      <complete>
        <size>78259143</size>
        <checksum>c8b1361cc03309a8113de92f93471524fa0c36f7</checksum>
        <url>platform-29_r02.zip</url>
      </complete>
    </archive>
  </archives>
</remotePackage>

Keep the other "platforms;android-29" element with <major>1</major> and then re-install the package:

sdkmanager --install "platforms;android-29"
like image 193
James Wald Avatar answered Nov 19 '22 01:11

James Wald


I ran into the same problem and found a workaround for HashMap and ArrayList: You can instantiate the map as

val map: MutableMap<String, String> = HashMap()

For ArrayList

val list: MutableList<String> = ArrayList()
like image 41
Justin Dunscombe Avatar answered Nov 19 '22 00:11

Justin Dunscombe


As per the bug report in the issue tracker, google has reverted r2 back to r1

API 29 r2 has been rolled back from Studio SDK Manager for now until the root cause is identified and fixed.

So just uninstall/reinstall Q from the adk manager and you should be back on r1

like image 2
tyczj Avatar answered Nov 19 '22 01:11

tyczj