-
Notifications
You must be signed in to change notification settings - Fork 546
[Xamarin.Android.Build.Tasks] Add Support for AndroidJavaSource to Bindings #5926
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
48deff7
to
91fdc5b
Compare
6e5464d
to
9b911de
Compare
src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.AvailableItems.targets
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Javac.targets
Outdated
Show resolved
Hide resolved
I need to make changes to this anyway to make sure the new targets do not run as part of a DTB. |
src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Javac.targets
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Javac.targets
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Javac.targets
Outdated
Show resolved
Hide resolved
I can't easily answer this from reading the PR, but one thing we should try to ensure is that when A "unit test check" for this would be to check that the C# binding for public string GreetWithQuestion (string name, Java.Util.Date date, string question) This may be "easiest done" by copying all <PropertyGroup>
<_AndroidIntermediateBindingClassesSourceJar>$(IntermediateOutputPath)binding\bin\$(MSBuildProjectName)-source.jar</_AndroidIntermediateBindingClassesSourceJar>
</PropertyGroup> Then adding
|
We had a call today, and made the following decisions:
|
e383c4a
to
8761aef
Compare
9b75cbc
to
cba4afb
Compare
…ndings It would be nice to be able to introduce custom Java code and API's to a binding project. This would allow developers to simplify an API and still expose that to the C# Developer. Using the existing `AndroidJavaSource` ItemGroup we can do exactly that. This ItemGroup now supports the `Bind` metadata which will build and bind the java code *prior* to the main C# compiled running. Historically `AndroidJavaSource` was only available on Application Projects. However this ItemGroup can now be used in any project type. The `Bind` metadata is `true` by default and will cause the Java code to be compiled into a .jar file before the C# compiler is run. It will then be bound using the Java.Interop Java->C# binding system. The final C# apis will be generated an included in the final C# compilation. There are some restrictions on the Java code. You can only use Java types or types which are defined in .jar or .aar files you reference for that project via `AndroidLibrary` or `EmbeddedJar`. It is advised that you DO NOT export types which include Java Generics via this mechanism. Like normal bindings, Java Generics cause significant problems. Try to stuck to normal types if you can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments I had at this point are really minor. 👍
src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Javac.targets
Outdated
Show resolved
Hide resolved
Co-authored-by: Jonathan Peppers <jonathan.peppers@gmail.com>
…n.Android.Javac.targets Co-authored-by: Jonathan Peppers <jonathan.peppers@gmail.com>
@@ -128,6 +128,12 @@ Copyright (C) 2012 Xamarin Inc. All rights reserved. | |||
/> | |||
</CreateProperty> | |||
|
|||
<CreateProperty Value="$(_JavaSdkDirectory)bin"> | |||
<Output TaskParameter="Value" PropertyName="JavacToolPath" | |||
Condition="'$(JavacToolPath)' == ''" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also have And Exists('$(_JavaSdkDirectory)bin')
? Or will we error out earlier if $(_JavaSdkDirectory)
doesn't exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…and shouldn't we start using <PropertyGroup/>
instead of <CreateProperty/>
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this to that it matches what was already there. I can rework this to use PropertyGroup
. Or perhaps we get this in, and then do a PR to remove ALL CreateProperty
references?
Commit message? [Xamarin.Android.Build.Tasks] Add %(AndroidJavaSource.Bind) (#5926)
Update the `@(AndroidJavaSource)` Build action:
1. In .NET 7, all `**\*.java` files are automatically added to the
`@(AndroidJavaSource)` Build action.
2. Add `%(AndroidJavaSource.Bind)` item metadata, a boolean value
(default is True) which controls whether or not the file is
compiled and bound *prior* to the C# build.
The combination of these means that custom Java code can be added to
any .NET Android project, and a binding of that Java code will be
usable by the C# code. Both Java code and bindings will be included
in App builds of referencing apps.
There are some restrictions on the Java code. You can only use Java
types or types which are defined in `.jar` or `.aar` files referenced
by the project via `@(AndroidLibrary)` or `@(EmbeddedJar)`. It is
suggested that you *do not* have `publi` Java types which use Java
generics. As with normal bindings, Java generics can cause
significant problems; try to stuck to normal types if you can. |
@dellis1972: I don't see any way to get useful parameter names into the bindings. We had previous suggested using Alternatively, we could update the However, I don't see either of these options here. Are we doing anything to import parameter names? |
We talked about this and I seem to remember we decided to do this at a later date, cos this PR was large enough already. |
Context: #5926 Fixes: dotnet/maui#8049 There was a bug causing response files to not work when trying to bind Java libraries in a path containing a space, since the CLI argument given to `class-parse`/`generator` was not properly quoted. This has been fixed in 67ce902, however this is a .NET 7 only PR. Pull the fix out of that PR and port it to the `6.0.4xx` branch so it will go into a .NET 6 servicing release.
It would be nice to be able to introduce custom Java code and API's to a
binding project. This would allow developers to simplify an API and
still expose that to the C# Developer.
Using the existing
AndroidJavaSource
ItemGroup we can do exactly that.This ItemGroup now supports the
Bind
metadata which will build andbind the java code prior to the main C# compiled running. Historically
AndroidJavaSource
was only available on Application Projects. Howeverthis ItemGroup can now be used in any project type. The
Bind
metadatais
true
by default and will cause the Java code to be compiled intoa .jar file before the C# compiler is run. It will then be bound using
the Java.Interop Java->C# binding system. The final C# apis will be
generated an included in the final C# compilation.
There are some restrictions on the Java code. You can only use Java types
or types which are defined in .jar or .aar files you reference for that
project via
AndroidLibrary
orEmbeddedJar
.It is advised that you DO NOT export types which include Java Generics
via this mechanism. Like normal bindings, Java Generics cause significant
problems. Try to stuck to normal types if you can.