-
Notifications
You must be signed in to change notification settings - Fork 562
[Xamarin.Android.Build.Tasks] Generate JNI marshal methods #2153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c332b74
fb19053
995247a
e006138
c2beb80
33e49a9
8459475
ffc42de
348ec67
8d2b906
d85923a
df7ba0c
0b0dfb2
f166d06
82c8d0c
e349d60
4fee750
0b8e786
f924ac2
dcf6421
f5ff71c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.ReplaceFileContents" /> | ||
| <Target Name="_CreateJavaInteropDllConfigs" | ||
| Inputs="$(XAInstallPrefix)xbuild\Xamarin\Android\Java.Interop.dll;$(JavaInteropSourceDirectory)\src\Java.Runtime.Environment\Java.Runtime.Environment.dll.config" | ||
| Outputs="$(XAInstallPrefix)xbuild\Xamarin\Android\Java.Interop.dll.config;$(XAInstallPrefix)xbuild\Xamarin\Android\Java.Runtime.Environment.dll.config"> | ||
| <ReadLinesFromFile | ||
| File="$(MSBuildThisFileDirectory)java-interop.dllmap"> | ||
| <Output TaskParameter="Lines" ItemName="_JavaInteropDllMapContent" /> | ||
| </ReadLinesFromFile> | ||
| <WriteLinesToFile | ||
| File="$(XAInstallPrefix)xbuild\Xamarin\Android\Java.Interop.dll.config" | ||
| Lines="<configuration>;@(_JavaInteropDllMapContent);</configuration>" | ||
| Overwrite="True" | ||
| /> | ||
| <PropertyGroup> | ||
| <_DllMaps>@(_JavaInteropDllMapContent->'%(Identity)', '%0a ')</_DllMaps> | ||
| </PropertyGroup> | ||
| <ReplaceFileContents | ||
| Condition="Exists('$(JavaInteropSourceDirectory)\src\Java.Runtime.Environment\Java.Runtime.Environment.dll.config')" | ||
| SourceFile="$(JavaInteropSourceDirectory)\src\Java.Runtime.Environment\Java.Runtime.Environment.dll.config" | ||
| DestinationFile="$(XAInstallPrefix)xbuild\Xamarin\Android\Java.Runtime.Environment.dll.config" | ||
| Replacements="<configuration>=<configuration>%0a $(_DllMaps)" | ||
| /> | ||
| </Target> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using System.Linq.Expressions; | ||
| using System.Reflection; | ||
|
|
||
| using Java.Interop; | ||
| using Java.Interop.Expressions; | ||
|
|
||
| namespace Android.Runtime | ||
| { | ||
| sealed class IJavaObjectValueMarshaler : JniValueMarshaler<IJavaObject> { | ||
|
|
||
| internal static IJavaObjectValueMarshaler Instance = new IJavaObjectValueMarshaler (); | ||
|
|
||
| public override IJavaObject CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type targetType) | ||
| { | ||
| throw new NotImplementedException (); | ||
| } | ||
|
|
||
| public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IJavaObject value, ParameterAttributes synchronize) | ||
| { | ||
| throw new NotImplementedException (); | ||
| } | ||
|
|
||
| public override void DestroyGenericArgumentState (IJavaObject value, ref JniValueMarshalerState state, ParameterAttributes synchronize) | ||
| { | ||
| throw new NotImplementedException (); | ||
| } | ||
|
|
||
| public override Expression CreateReturnValueFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue) | ||
| { | ||
| return Expression.Call ( | ||
| typeof (JNIEnv), | ||
| "ToLocalJniHandle", | ||
| null, | ||
| sourceValue); | ||
| } | ||
|
|
||
| public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type targetType) | ||
| { | ||
| var r = Expression.Variable (targetType, sourceValue.Name + "_val"); | ||
| context.LocalVariables.Add (r); | ||
| context.CreationStatements.Add ( | ||
| Expression.Assign (r, | ||
| Expression.Call ( | ||
| typeof (JavaConvert), | ||
| "FromJniHandle", | ||
| new[]{targetType}, | ||
| sourceValue, | ||
| Expression.Field (null, typeof (JniHandleOwnership), "DoNotTransfer")))); | ||
| return r; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| using Microsoft.Build.Utilities; | ||
| using System; | ||
| using System.IO; | ||
| using System.Linq; | ||
|
|
||
| namespace Xamarin.Android.Tasks | ||
| { | ||
|
|
@@ -49,6 +50,9 @@ public class ResolveSdks : Task | |
| [Output] | ||
| public string JavaSdkPath { get; set; } | ||
|
|
||
| [Output] | ||
| public string JdkJvmPath { get; set; } | ||
|
|
||
| [Output] | ||
| public string MonoAndroidToolsPath { get; set; } | ||
|
|
||
|
|
@@ -92,12 +96,38 @@ public override bool Execute () | |
| return false; | ||
| } | ||
|
|
||
| try { | ||
| Log.LogDebugMessage ($"JavaSdkPath: {JavaSdkPath}"); | ||
| Xamarin.Android.Tools.JdkInfo info = null; | ||
| try { | ||
| info = new Xamarin.Android.Tools.JdkInfo (JavaSdkPath); | ||
| } catch { | ||
| info = Xamarin.Android.Tools.JdkInfo.GetKnownSystemJdkInfos (this.CreateTaskLogger ()).FirstOrDefault (); | ||
| } | ||
|
|
||
| JdkJvmPath = info.JdkJvmPath; | ||
|
|
||
| if (string.IsNullOrEmpty (JdkJvmPath)) { | ||
| Log.LogCodedError ("XA5300", $"{nameof (JdkJvmPath)} is blank"); | ||
| return false; | ||
| } | ||
|
|
||
| if (!File.Exists (JdkJvmPath)) { | ||
| Log.LogCodedError ("XA5300", $"JdkJvmPath not found at {JdkJvmPath}"); | ||
| return false; | ||
| } | ||
| } catch (Exception e) { | ||
| Log.LogCodedError ("XA5300", $"Unable to find {nameof (JdkJvmPath)}{Environment.NewLine}{e}"); | ||
| return false; | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @radekdoulik quick question about this task. There is a Visual Studio team very focused on the performance of "solution create", which is basically the initial design-time build from our targets. Since looking up
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is now only used by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, cool. I might look at making those changes ^^ I'll have you review. Might not happen this week, though. 😃 |
||
| MonoAndroidHelper.TargetFrameworkDirectories = ReferenceAssemblyPaths; | ||
|
|
||
| Log.LogDebugMessage ($"{nameof (ResolveSdks)} Outputs:"); | ||
| Log.LogDebugMessage ($" {nameof (AndroidSdkPath)}: {AndroidSdkPath}"); | ||
| Log.LogDebugMessage ($" {nameof (AndroidNdkPath)}: {AndroidNdkPath}"); | ||
| Log.LogDebugMessage ($" {nameof (JavaSdkPath)}: {JavaSdkPath}"); | ||
| Log.LogDebugMessage ($" {nameof (JdkJvmPath)}: {JdkJvmPath}"); | ||
| Log.LogDebugMessage ($" {nameof (MonoAndroidBinPath)}: {MonoAndroidBinPath}"); | ||
| Log.LogDebugMessage ($" {nameof (MonoAndroidToolsPath)}: {MonoAndroidToolsPath}"); | ||
|
|
||
|
|
||
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.
@radekdoulik do you know if these calls to find java take a while?
ResolveSdksruns on every project, every build. I might have to add some caching logic to this task after we merge this, I think this task takes ~20ms before these changes on my machine.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 believe that this should be cached in the
AppDomain, as we cache other constructs.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.
Yeah @radekdoulik you could do similar to what we have here, using the incoming
JavaSdkPathas part of the key: https://github.com/xamarin/xamarin-android/blob/9e21b1d07aa6dc7b0caa2cf3ea6124d26e4cfd57/src/Xamarin.Android.Build.Tasks/Tasks/ValidateJavaVersion.cs#L102-L108I will do this as part of finding the Android SDK, too; in a different PR.
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.
Nice, I will try it. Now it takes about 123ms.