You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Microsoft Visual Studio Community 2022
Version 17.6.2
VisualStudio.17.Release/17.6.2+33723.286
Microsoft .NET Framework
Version 4.8.09032
Gestionnaire de package NuGet 6.6.0
Xamarin 17.6.0.251 (d17-6@318364c)
Xamarin Designer 17.6.6.0 (remotes/origin/d17-6@cb430751d1)
Xamarin Templates 17.6.32 (98c12a2)
Xamarin.Android SDK 13.2.0.6 (d17-5/a200af1)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: 6dd9def
Java.Interop: xamarin/java.interop/d17-5@149d70fe
SQLite: xamarin/sqlite@68c69d8
Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@9f02d77"
Building the binding library gives below error:
warning BG8605: The Java type 'java.time.LocalDate' could not be found (are you missing a Java reference jar/aar or a Java binding library NuGet?)
Related methods are then removed from the bindings:
The method '[Method] <package>.CalendarDay copy(java.time.LocalDate date, com.kizitonwose.calendar.core.DayPosition position)' was removed because the Java parameter type 'java.time.LocalDate' could not be found.
changed the title [-]Bind library that uses Java 8+ API desugaring support - not fixed[/-][+]`java.time` package not bound in `Mono.Android`[/+]on May 29, 2023
@jpobst I'm facing a similar issue, I wonder if there is a work around for this for the time being? Is there some way to bind methods that take Instant or LocalDateTime (which both come from java.time) as arguments? In my case these API's are necessary for use of the library.
I think the only thing you can do is write a new Java API that wraps the existing API without exposing Instant or LocalDateTime, and then bind that API.
@jpobst Thanks for your response on this, I was thinking something similar, but I was hoping I would not have to rewite the Java API. Do you know of a way I can add a method to the Additions that will do something like this, but on the C# level.
So something like:
pubic void doThing(string localDateTime)
{
// Make a call to LocalDateTime.parse here, but do it with C# (not have to write Java Code)
var dt = LocalDateTime.parse(string)
// Make a call to Java code here to do the real thing but from C#
JavaCall.doRealThing(dt);
}
I don't know if the above makes sense? Do you think this is possible?
I don't have access to edit the java source code for the AAR I am trying to bind, that's why I'd prefer a C# based solution.
Let me know what you think, and thanks for your respose! :)
There is no way to do it in C#, unless you try to bind it by hand yourself. (I can't help with that.)
If you are using .NET 7+, you can add a loose .java file to your application that wraps the API as a AndroidJavaSource file and it will automatically get compiled and bound:
Thanks for the response @jpobst, I'm trying to do this now but it's not too clear to he how. Would I add the java file to my Xamarin Android Binding project? Or would I add it to the Xamarin-Android application?
If there is a way to do this is in the Android Binding project, do I just add the java file to the Additions folder in that project? it doesn't seem too clear to me what the best way to do it.
Activity
xpfr commentedon May 28, 2023
To reproduce:
Create a binding library with TargetFramework=net6-android over a .aar having desugaring support (https://developer.android.com/studio/write/java8-support) using:
"Microsoft Visual Studio Community 2022
Version 17.6.2
VisualStudio.17.Release/17.6.2+33723.286
Microsoft .NET Framework
Version 4.8.09032
Gestionnaire de package NuGet 6.6.0
Xamarin 17.6.0.251 (d17-6@318364c)
Xamarin Designer 17.6.6.0 (remotes/origin/d17-6@cb430751d1)
Xamarin Templates 17.6.32 (98c12a2)
Xamarin.Android SDK 13.2.0.6 (d17-5/a200af1)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: 6dd9def
Java.Interop: xamarin/java.interop/d17-5@149d70fe
SQLite: xamarin/sqlite@68c69d8
Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@9f02d77"
Building the binding library gives below error:
Tried a few things without success:
Thank you for the support
jpobst commentedon May 29, 2023
The
java.timepackage is not bound, and thus no API that relies on it can be bound:https://github.com/xamarin/xamarin-android/blob/main/src/Mono.Android/metadata#L1340-L1342
The commit from 6 years ago doesn't say why it wasn't bound. I guess we could try it and see what the issues are.
Note that this issue is:
[-]Bind library that uses Java 8+ API desugaring support - not fixed[/-][+]`java.time` package not bound in `Mono.Android`[/+]Kikanye commentedon Jun 23, 2023
@jpobst I'm facing a similar issue, I wonder if there is a work around for this for the time being? Is there some way to bind methods that take
InstantorLocalDateTime(which both come fromjava.time) as arguments? In my case these API's are necessary for use of the library.jpobst commentedon Jun 23, 2023
I think the only thing you can do is write a new Java API that wraps the existing API without exposing
InstantorLocalDateTime, and then bind that API.Something like:
Kikanye commentedon Jun 23, 2023
@jpobst Thanks for your response on this, I was thinking something similar, but I was hoping I would not have to rewite the Java API. Do you know of a way I can add a method to the Additions that will do something like this, but on the C# level.
So something like:
I don't know if the above makes sense? Do you think this is possible?
I don't have access to edit the java source code for the AAR I am trying to bind, that's why I'd prefer a C# based solution.
Let me know what you think, and thanks for your respose! :)
jpobst commentedon Jun 23, 2023
There is no way to do it in C#, unless you try to bind it by hand yourself. (I can't help with that.)
If you are using .NET 7+, you can add a loose
.javafile to your application that wraps the API as aAndroidJavaSourcefile and it will automatically get compiled and bound:https://learn.microsoft.com/en-us/xamarin/android/deploy-test/building-apps/build-items#androidjavasource
Note that it will not show up in Intellisense which is quite annoying, but it does work when you run your application:
#7692
Kikanye commentedon Jun 23, 2023
Thanks for the response @jpobst, I'm trying to do this now but it's not too clear to he how. Would I add the java file to my Xamarin Android Binding project? Or would I add it to the Xamarin-Android application?
If there is a way to do this is in the Android Binding project, do I just add the java file to the Additions folder in that project? it doesn't seem too clear to me what the best way to do it.
[Mono.Android] Bind `java.time` and `java.time.chrono` packages. (#8088