Overload resolution ambiguity HashMap.get kotlin - android

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
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

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"

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()

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

I ran into the same problem, For now as a workaround I am using the Kotlin extension function getOrElse, which allows you to provide a default value if the map does not contain the given key.

Related

launchImageLibrary function on react-native-image-picker not launching on Android SDK 30

I am facing a problem when calling launchImageLibrary on React Native app.
react-native-image-picker version 4.0.6 - latest
Android compileSdkVersion = 30, targetSdkVersion = 30
It worked well on SDK version 29 and react-native-image-picker 3.4, but Playstore requirement was updated to 30. So, I updated the SDK version and had "Activity error".
So, I thought it is react-native-image-picker version issue, I updated it to 4.0.6
But still, I am having selectionLimit error. Could anyone help me to fix this error?
selectionLimit error
You should set selectionLimit option when calling launchImageLibrary function.
Try this.
launchImageLibrary({
selectionLimit: 0
}, response => {
}
)

How to move to Realm Sync Protocol Version 3 for Android?

I am new to Realm and Android development and am trying to query a document from Atlas. I am able to successfully authenticate users, but when I try to perform a query, I get the following error: E/REALM_JAVA: Session Error[wss://realm.mongodb.com/]: WRONG_PROTOCOL_VERSION(realm::sync::ProtocolError:105): sync client must have a sync protocol version of at least 3 to sync on this application, but found version 2. Please update your application to use a newer SDK
I am currently working on version 10.4.0 of the Android Realm SDK and Android SDK Platform 30. I have tried looking for updates for both and it says that everything is up to date. Here is my code:
app.loginAsync(emailPasswordCredentials, it -> {
if (it.isSuccess()) {
Log.v("AUTH", "Successfully authenticated using an email and password.");
User user = app.currentUser();
String partitionValue = "object_id";
SyncConfiguration config = new SyncConfiguration.Builder(
user,
partitionValue)
.allowQueriesOnUiThread(true)
.allowWritesOnUiThread(true)
.build();
uiThreadRealm = Realm.getInstance(config);
//Debugging - testing Realm Sync queries
Products product = uiThreadRealm.where(Products.class).equalTo("_id", 4).findFirst();
if (product != null) {
Log.v("AUTH", product.toString());
}
Log.v("AUTH", config.toString());
//In-App functions
}
Does anyone have any way to solve this issue?
In my case it was due to selecting UUID as the type of one my fields, which is "at this time is NOT a supported type in the SDK, but it will be in a future version." (from Monogo's support).
For those coming from react-native and get this kind of error
sync client must have a sync protocol version of at least 3 to sync on this application, but found version 2. Please update your application to use a newer SDK
Just do in your terminal
npm install realm
Then
cd ios
pod install
Be careful of breaking changes.
If needed, uninstall your application on your emulator/simulator then
npx react-native run-ios
or
npx react-native run-android
So for Android I guess you have to update your Realm packages as well...

Runtime error using Xamarin Android with F# and ReactiveUI

I have created a Xamarin Android project that is using F# and ReactiveUI.
When loading my Dashboard, I encounter a runtime exception (of type MissingMethodException) on the inherit line of this code snippet:
type DashboardViewModel(?host: IScreen) =
inherit ReactiveViewModel()
let host = LocateIfNone host
member __.Title with get() = "Dashboard"
interface IRoutableViewModel with
member __.HostScreen = host
member __.UrlPathSegment = "Dashboard"
The error message reads
Method 'Microsoft.FSharp.Quotations.FSharpExpr.Deserialize40' not found.
The ReactiveViewModel type is a thin wrapper around ReactiveObject:
type ReactiveViewModel() as this =
inherit ReactiveObject()
let mutable message = noMessage
let uiContext = SynchronizationContext.Current
member __.SyncContext with get() = uiContext
member this.Message
with get() = message
and set(value) =
this.RaiseAndSetIfChanged(&message, value, "Message") |> ignore
if message <> noMessage then this.RaiseAndSetIfChanged(&message, noMessage, "Message") |> ignore
member val MessageSent =
this.WhenAnyValue(toLinq <# fun vm -> vm.Message #>).ObserveOn(RxApp.MainThreadScheduler).Where(fun m -> m <> noMessage) with get
The project is open source: at the moment, it contains very little content. It can be found at https://github.com/SpiegelSoft/Astrid.
I have submitted a bug on the Xamarin bug tracker: https://bugzilla.xamarin.com/show_bug.cgi?id=51000
Are there any known fixes I can implement myself, so that I can close the bug of my own accord?
UPDATE 1
I've been investigating this issue this weekend.
The FSharp.Core version that is loaded is stuck on the obsolete version 2.3.98.1. This corresponds to the FSharp.Core.dll file in
C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework\MonoAndroid\v1.0
I have tried to remove this version and load the NuGet package FSharp.Core; however, when I build the Android project, the path always reverts to the obsolete file in the Reference Assemblies path.
Is there a way to override this behaviour?
UPDATE 2
Replacing the FSharp.Core.dll file in the Reference Assemblies path fixes the issue, but this is a very unsatisfactory sticking plaster, which I can't ask my users to apply. Ideally, I would like to find a way to prevent the .Droid project from loading FSharp.Core from the GAC rather than the NuGet package.
I just ran into a very similar issue the other day. My android app had a reference to a Profile7 F# PCL library, which made use of List.unfold, which I believe was introduced in F# 4. When I used the library in my app, I saw a MissingMethodException similar to what you are seeing. The version of FSharp.Core that Xamarin references by default when creating a new Android app didn't have this newer method. I got around it by editing the .fsproj file for the app to remove the original reference to FSharp.Core, and replaced it with a reference to the newer version ( I copy/pasted the tag from the PCL .fsproj file). It looks something like this:
<Reference Include="FSharp.Core">
<Name>FSharp.Core</Name>
<Private>True</Private>
<AssemblyName>FSharp.Core.dll</AssemblyName>
<HintPath>$(MSBuildExtensionsPath32)\..\Reference Assemblies\Microsoft\FSharp\.NETCore\$(TargetFSharpCoreVersion)\FSharp.Core.dll</HintPath>
</Reference>
I was suprised to find that this seems to have fixed the problem for me. I'm not sure if I'll run into other issues down the line, but it may be worth trying this if you havent already.
UPDATE If this doesn't work immediately, follow the sequence of steps in Rob Lyndon's answer.
It appears that this has been fixed by the GitHub commit
https://github.com/xamarin/xamarin-android/commit/df41af046000556ed82f638e8041b7f718966a92
which removes FSharp.Core from the list of framework assemblies, and allows the project to be built without the NuGet FSharp.Core assembly being replaced.
Until this fix is released into the SDK, there is a workaround. The answer submitted by user3850711 works, but you need to apply the changes in a specific sequence, because otherwise the reference will be overwritten during the build.
Delete the existing reference to FSharp.Core.
Install or reinstall the FSharp.Core NuGet package.
Unload the project and add <HintPath>packages\FSharp.Core.4.0.0.1\lib\portable-net45+monoandroid10+monotouch10+xamarinios10\FSharp.Core.dll</HintPath> to the FSharp.Core project reference.

How to get notified about Android appcompat or support library updates?

I wonder if there is a way to get notified about updates of the Google Android libraries such as com.android.support:support-v4, com.android.support:appcompat-v7 and so on.
I am aware that I could use compile "com.android.support:support-v4:18.0.+" with the + in my gradle build. But it would be nice to get an eMail or have an RSS Feed with the new releses of all the different android libraries by google. This would help a lot to keep the dependencies up to date and publish a new version of my app to the play store.
Edit:
I found this url https://dl.google.com/android/repository/addon.xml which is used to update the local m2repo (which includes the above mentioned librarys).
A real "push" notification solution would require lots of boring details like setting up xmpp or email accounts. However, this is a very valid question and one I have recently solved not just for appcompat libraries but for all my dependencies.
gradle-versions-plugin
This excellent plugin analyzes your depdencies and checks for newer releases. Example console output:
$ gradle dependencyUpdates
...
The following dependencies are using the latest milestone version:
- com.android.support:appcompat-v7:23.1.1
- com.android.support:cardview-v7:23.1.1
- com.android.support:recyclerview-v7:23.1.1
- com.android.support:support-annotations:23.1.1
- com.android.support.test:rules:0.4.1
- com.android.support.test:runner:0.4.1
- com.github.ben-manes:gradle-versions-plugin:0.11.3
The following dependencies have later milestone versions:
- com.android.tools.build:gradle [1.5.0-beta1 -> 2.0.0-alpha1]
- com.google.android.gms:play-services-gcm [7.5.0 -> 8.3.0]
- com.squareup.retrofit:retrofit [1.9.0 -> 2.0.0-beta2]
- net.hockeyapp.android:HockeySDK [3.5.0 -> 3.7.0-beta.2]
- org.hamcrest:hamcrest-library [1.1 -> 1.4-atlassian-1]
- org.mockito:mockito-core [1.10.19 -> 2.0.31-beta]
You can just run this any time you want to check for newer versions. And since it also supports json output format, if you really wanted to script some kind of notification, you could cronjob it and parse the json output and do whatever you'd like at that point.
Your question is interesting and it made me think on how I may address myself the problem to actually find a solution. Here's my thought: I use myself ifttt and alike and the missing point is then the monitoring of the xml data. A Google search later, I've just found this blog post which is a thoroughful description of the steps needed to get notified by mail of a change in a web page. HEY, THAT'S WHAT WE NEED!!!
I've not tested since I need to wait for an actual update but here is the resulting RSS: page2RSS android addon monitoring
Update (May 9): page2rss has been shut down on May 1st, as a consequence other services must be used/tested. Wachete seems to provide similar services, but one needs an account.
I don't know if there is an RSS or something like that, but you can visit periodically this page:
http://developer.android.com/tools/support-library/index.html
Or visit the Android Developers Blog (often Ian Lake, a Google Developer Advocate, update it with pertinent posts):
http://android-developers.blogspot.com/

How do I determine the revision number of an Android build?

I know how to get the API level, android.os.Build.VERSION.SDK_INT, but there are also several revisions of each level release, e.g. for 2.1 there's rev 1 and 2. How do I determine the revision of a build?
The reason i'd like to know this is that I have a workaround for a bug in Android 2.1 (and 2.2), and this workaround will break the moment the corresponding bug is fixed. So right now i'm in the odd position of hoping that the bug won't be fixed (at least not until I can find an answer to above question).
I'm not sure which revision you're reffering to, but the revision you set in your manifest file you can get with the following code:
paramContext is your Context object
PackageManager localPackageManager = paramContext.getPackageManager();
PackageInfo localPackageInfo = localPackageManager.getPackageInfo(paramContext.getPackageName(), 0);
String version = localPackageInfo.versionName;
If you want to extract the build version, use this code:
String version = Build.VERSION.RELEASE;

Categories

Resources