Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ because xbuild doesn't support framework reference assemblies.
<_AndroidComponentResgenFlagFile>$(IntermediateOutputPath)Component.R.cs.flag</_AndroidComponentResgenFlagFile>
<_AndroidStripFlag>$(IntermediateOutputPath)strip.flag</_AndroidStripFlag>
<_AndroidLinkFlag>$(IntermediateOutputPath)link.flag</_AndroidLinkFlag>
<_AndroidJniMarshalMethodsFlag>$(IntermediateOutputPath)jnimarshalmethods.flag</_AndroidJniMarshalMethodsFlag>
<_AndroidApkPerAbiFlagFile>$(IntermediateOutputPath)android\bin\apk_per_abi.flag</_AndroidApkPerAbiFlagFile>
<_AndroidDebugKeyStoreFlag>$(IntermediateOutputPath)android_debug_keystore.flag</_AndroidDebugKeyStoreFlag>
<_RemoveRegisterFlag>$(MonoAndroidIntermediateAssetsDir)shrunk\shrunk.flag</_RemoveRegisterFlag>
Expand Down Expand Up @@ -2012,7 +2013,7 @@ because xbuild doesn't support framework reference assemblies.
</Target>

<Target Name="_LinkAssemblies"
DependsOnTargets="_ResolveAssemblies;_CreatePackageWorkspace;_LinkAssembliesNoShrink;_LinkAssembliesShrink" />
DependsOnTargets="_ResolveAssemblies;_CreatePackageWorkspace;_GenerateJniMarshalMethods;_LinkAssembliesNoShrink;_LinkAssembliesShrink" />

<Target Name="_LinkAssembliesNoShrink"
Condition="'$(AndroidLinkMode)' == 'None'"
Expand All @@ -2035,6 +2036,19 @@ because xbuild doesn't support framework reference assemblies.
<Touch Files="$(_AndroidLinkFlag)" AlwaysCreate="true" />
</Target>

<Target Name="_GenerateJniMarshalMethods"
Condition="'$(JniMarshalMethods)' == 'True' And '$(Configuration)' == 'Release' And '$(AndroidLinkMode)' != 'None'"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, $(JniMarshalMethods) does appear to control generation as well, wrt #1745 (comment).

Thus, $(AndroidGenerateJniMarshalMethods) seems appropriate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Convention (also not followed consistently, but let's not make it worse):

For XML, attributes are indented one "tab stop" more than child elements. Additionally, prefer spaces over tabs, and use two-space "tab stops". Thus:

<Target Name="_GenerateJniMarshalMethods"
    Condition=" '$(AndroidGenerateJniMarshalMethods)' == 'True' And '$(Configuration)' == 'Release' And '$(AndroidLinkMode)' != 'None' "
    DependsOnTargets="_GetReferenceAssemblyPaths"
    Inputs="@(ResolvedUserAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)')"
    Outputs="$(_AndroidJniMarshalMethodsFlag)">
  <Exec
      Command="MONO_PATH=$(_XATargetFrameworkDirectories) $(MonoAndroidBinDirectory)\mono $(MonoAndroidBinDirectory)\..\jnimarshalmethod-gen.exe @(ResolvedUserAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)')"
  />
</Target>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not use '$(Configuration)' == 'Release'. $(Configuration) values are convention, and developers are able to add arbitrary names. (For example, Java.Interop had a XAIntegrationRelease configuration for quite some time.)

Any check against $(Configuration) is a "code smell." (I think we still have one anyway -- though I can't currently find it -- but, again, we shouldn't make things worse.)

DependsOnTargets="_GetReferenceAssemblyPaths"
Inputs="@(ResolvedUserAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)')"
Outputs="$(_AndroidJniMarshalMethodsFlag)">

<Exec
Command="MONO_PATH=$(_XATargetFrameworkDirectories) $(MonoAndroidBinDirectory)\mono $(MonoAndroidBinDirectory)\..\jnimarshalmethod-gen.exe @(ResolvedUserAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)')"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we also need to update the GetMonoBundleItems target within src/mono-runtimes/mono-runtimes.targets so that mono is included in the bundle*.zip file?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(_XATargetFrameworkDirectories) should be quoted, in case it contains spaces:

Command="MONO_PATH=&quot;$(_XATargetFrameworkDirectories)&quot; ...

Additionally, I believe that $(_XATargetFrameworkDirectories) will be incomplete: it should contain only the directories (directory) for MonoAndroid,Version=v1.0, which will not be a directory which contains Mono.Android.dll.

For example (from a random full xamarin-android build log I have lying around):

Task "ResolveSdks" (TaskId:1387)
...
  Task Parameter:ReferenceAssemblyPaths=/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/ (TaskId:1387)
...
  Output Property: _XATargetFrameworkDirectories=/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/ (TaskId:1387)

If e.g. .../xbuild-frameworks/MonoAndroid/v8.1 isn't included, how will Mono.Android.dll be found?

Alternatively, perhaps MONO_PATH should be set to $(MonoAndroidLinkerInputDir) and called after that directory has been setup, e.g. after _CopyIntermediateAssemblies?

/>
<Touch Files="$(_AndroidJniMarshalMethodsFlag)" AlwaysCreate="True" />

</Target>

<Target Name="_LinkAssembliesShrink"
Condition="'$(AndroidLinkMode)' != 'None'"
Inputs="@(ResolvedUserAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)');$(_AndroidBuildPropertiesCache)"
Expand Down