Skip to content
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

Bump to xamarin/Java.Interop/main@8898bc14 #6229

Merged
merged 1 commit into from
Aug 26, 2021

Conversation

jonpryor
Copy link
Member

@jonpryor jonpryor commented Aug 24, 2021

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

This looks OK if it builds. 😄

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

So if a lot of test projects fail to build with:

MainActivity.cs(13,3): error CS1705: Assembly 'Xamarin.Forms.Platform.Android' with identity 'Xamarin.Forms.Platform.Android, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' which has a higher version than referenced assembly 'Java.Interop' with identity 'Java.Interop, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'

Does that mean we shouldn't version Java.Interop.dll? It's actually used by apps, while some of the other assemblies are only used at build time.

@jonpryor
Copy link
Member Author

I suspect that things are nominally more confusing than that! The current version of Java.Interop.dll is 0.1.0.0:

% monodis --assembly /Library/Frameworks/Xamarin.Android.framework//Versions/11.3.0.1/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/Java.Interop.dll
Assembly Table
Name:          Java.Interop
Hash Algoritm: 0x00008004
Version:       0.1.0.0
…

…yet we have a compiler error showing that one of the Java.Interop.dll versions is 0.0.0.0. Meanwhile, xamarin/Java.Interop/GitInfo.txt has the value 0.1.

Where is 0.0.0.0 coming from?!

I believe that it's coming from: https://github.com/xamarin/java.interop/blob/8898bc1402953fdf3a1e1066dd2542fc1818aadf/src/Java.Interop/Java.Interop-MonoAndroid.csproj

which doesn't use the GitInfo NuGet, and -- because of dotnet/java-interop@d16b1e5 -- no longer sets the assembly version to 0.1.0.0 either. Thus it now gets the default value of 0.0.0.0.

I also see that the SetVersion target isn't executed while building bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/Java.Interop.dll, which is built via Java.Interop-MonoAndroid.csproj.

…and behold?

The target "GetAssemblyVersion" listed in a BeforeTargets attribute at "…/xamarin-android/external/Java.Interop/Directory.Build.props (101,29)" does not exist in the project, and will be ignored.

So! Hack up my local Java.Interop tree so that Java.Interop-Mono.Android.csproj once again generates a versioned Java.Interop.dll -- 0.1.1.0 for good measure!

diff --git a/src/Java.Interop/Directory.Build.targets b/src/Java.Interop/Directory.Build.targets
index c91706ab..483b1fe2 100644
--- a/src/Java.Interop/Directory.Build.targets
+++ b/src/Java.Interop/Directory.Build.targets
@@ -31,4 +31,23 @@
     <Exec Command="&quot;$(JavaCPath)&quot; $(_JavacSourceOptions) -d &quot;$(IntermediateOutputPath)ji-classes&quot; @(CompileJavaInteropJar -&gt; '%(Identity)', ' ')" />
     <Exec Command="&quot;$(JarPath)&quot; cf &quot;$(OutputPath)java-interop.jar&quot; -C &quot;$(IntermediateOutputPath)ji-classes&quot; ." />
   </Target>
+  <Target Name="_GenerateAssemblyInfo_cs">
+    <PropertyGroup>
+      <Version>0.1.1.0</Version>
+      <_AssemblyInfoPath>$(IntermediateOutputPath)$(MSBuildProjectFile).cs</_AssemblyInfoPath>
+    </PropertyGroup>
+    <ItemGroup>
+      <_AssemblyInfo Include="// &lt;autogenerated /&gt;" />
+      <_AssemblyInfo Include="using System.Reflection%3b" />
+      <_AssemblyInfo Include="[assembly: AssemblyTitle (&quot;Java.Interop&quot;)]" />
+      <_AssemblyInfo Include="[assembly: AssemblyCompany (&quot;Microsoft Corporation&quot;)]" />
+      <_AssemblyInfo Include="[assembly: AssemblyCopyright (&quot;Microsoft Corporation&quot;)]" />
+      <_AssemblyInfo Include="[assembly: AssemblyTrademark (&quot;Microsoft Corporation&quot;)]" />
+      <_AssemblyInfo Include="[assembly: AssemblyVersion (&quot;$(Version)&quot;)]" />
+    </ItemGroup>
+    <WriteLinesToFile File="$(_AssemblyInfoPath)" Lines="@(_AssemblyInfo)" Overwrite="True" />
+    <ItemGroup>
+      <Compile Include="$(_AssemblyInfoPath)" />
+    </ItemGroup>
+  </Target>
 </Project>
\ No newline at end of file
diff --git a/src/Java.Interop/Java.Interop-MonoAndroid.csproj b/src/Java.Interop/Java.Interop-MonoAndroid.csproj
index 9061a960..0a5d10f8 100644
--- a/src/Java.Interop/Java.Interop-MonoAndroid.csproj
+++ b/src/Java.Interop/Java.Interop-MonoAndroid.csproj
@@ -16,6 +16,7 @@
     <AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
     <LangVersion>8.0</LangVersion>
     <ProduceReferenceAssembly>true</ProduceReferenceAssembly>
+    <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
   </PropertyGroup>
   <Import Project="..\..\Directory.Build.props" />
   <PropertyGroup>
@@ -85,6 +86,7 @@
   <Import Project="Directory.Build.targets" />
   <PropertyGroup>
     <BuildDependsOn>
+      _GenerateAssemblyInfo_cs;
       BuildJniEnvironment_g_cs;
       BuildInteropJar;
       $(BuildDependsOn)
@@ -111,4 +113,5 @@
     <None Include="Documentation\Java.Interop\JniManagedPeerStates.xml" />
     <None Include="Documentation\Java.Interop\JniEnvironment.References.xml" />
   </ItemGroup>
+
 </Project>

and when I replace bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/Java.Interop.dll with this new 0.1.1.0 version, tests/Xamarin.Forms-Performance-Integration is able to build; no CS1705 is produced.

@jonpryor
Copy link
Member Author

@dellis1972: would you be able to take over the above Java.Interop patch and get into a "more useful" approach? The GitVersion target isn't available, presumably because the GitInfo-provided .targets files aren't being imported. How can we fix Java.Interop/src/Java.Interop/Java.Interop-MonoAndroid.csproj so that the GitVersion target exists, so that we can be consistent?

@dellis1972
Copy link
Contributor

@dellis1972: would you be able to take over the above Java.Interop patch and get into a "more useful" approach? The GitVersion target isn't available, presumably because the GitInfo-provided .targets files aren't being imported. How can we fix Java.Interop/src/Java.Interop/Java.Interop-MonoAndroid.csproj so that the GitVersion target exists, so that we can be consistent?

@jonpryor this might do the trick https://github.com/xamarin/java.interop/pull/871/files#diff-8b9952a7fb800961cf74521dd45afaa88095a4e68a641841dbff1b68c789dcc5R20

@jonpryor
Copy link
Member Author

@dellis1972: tried your patch locally, and...i'm uncertain.

Somehow it produced a Java.Interop.dll, but the version is not at all what I expected: 0.1.0.0 (?!):

% monodis --assembly bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/Java.Interop.dll | head -4
Assembly Table
Name:          Java.Interop
Hash Algoritm: 0x00008004
Version:       0.1.0.0

Meanwhile, the net6 version has a more reasonable 0.1.3.0:

% monodis --assembly bin/Debug/lib/xamarin.android/xbuild-frameworks/Microsoft.Android/net6.0/Java.Interop.dll | head -4
Assembly Table
Name:          Java.Interop
Hash Algoritm: 0x00008004
Version:       0.1.3.0

This doesn't make sense to me.

Furthermore, when I try to "manually" build via Java.Interop-MonoAndroid.csproj, it still fails:

% msbuild /v:diag Java.Interop-MonoAndroid.csproj /p:JavaInteropProfile=Net45 \
    /p:XAInstallPrefix=…/xamarin-android/bin/Debug/lib/xamarin.android  \
    /p:TargetFrameworkIdentifier=MonoAndroid \
    /p:TargetFrameworkVersion=v1.0 \
    /p:TargetFrameworkRootPath=…/xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks
…
…/xamarin-android/external/Java.Interop/Directory.Build.props(101,82): error MSB4057: The target "GitVersion" does not exist in the project. 

I'm thus really not sure what to make of this.

@jonpryor jonpryor force-pushed the jonp-bump-ji-a8898bc1 branch from 3a48cb1 to d9da10c Compare August 25, 2021 22:32
@jonpryor
Copy link
Member Author

Cleaned my repo, re-applied dotnet/java-interop#871 locally, and I just get a different set of errors.

make all fails:

  CSC : error CS2001: Source file '…/xamarin-android/src/Microsoft.Android.Sdk.ILLink/../Xamarin.Android.Build.Tasks/obj/Debug/Profile.g.cs' could not be found. […/xamarin-android/src/Microsoft.Android.Sdk.ILLink/Microsoft.Android.Sdk.ILLink.csproj]

Some files are created, but not the MonoAndroid-profile Java.Interop.dll:

% find bin/Debug -iname Java.Interop.dll
bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/Java.Interop.dll
bin/Debug/lib/xamarin.android/xbuild-frameworks/Microsoft.Android/net6.0/Java.Interop.dll

Running make all after that doesn't fix it.

If I take matters into my own hands and manually build Xamarin.Android.Build.Tasks.csproj, I get a different error:

% msbuild src/Xamarin.Android.Build.Tasks/*.csproj
…
"…/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop-MonoAndroid.csproj" (default target) (18) ->
  …/xamarin-android/external/Java.Interop/Directory.Build.props(101,82): error MSB4057: The target "GitVersion" does not exist in the project. […/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop-MonoAndroid.csproj]

Which is likewise not encouraging.

A manual Java.Interop-MonoAndroid.csproj build likewise fails in a similar manner.

@jonathanpeppers
Copy link
Member

I'm able to build this branch on Windows, but I get a similar failure as CI when I build the test .sln:

> xabuild Xamarin.Android-Tests.sln -r -bl
...
"C:\src\xamarin-android\Xamarin.Android-Tests.sln" (default target) (1:2) ->
"C:\src\xamarin-android\tests\Xamarin.Forms-Performance-Integration\Droid\Xamarin.Forms.Performance.Integration.Droid.csproj" (default target) (20:6) ->
  CSC : error CS1705: Assembly 'Xamarin.Forms.Platform.Android' with identity 'Xamarin.Forms.Platform.Android, Version=2.0.0.0, Culture=neutral, PublicKeyTo
ken=null' uses 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' which has a higher version than referenced assembly 'Java.I
nterop' with identity 'Java.Interop, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' [C:\src\xamarin-android\tests\Xamarin.Forms-Performa
nce-Integration\Droid\Xamarin.Forms.Performance.Integration.Droid.csproj]
  CSC : error CS1705: Assembly 'Xamarin.AndroidX.AppCompat' with identity 'Xamarin.AndroidX.AppCompat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
' uses 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' which has a higher version than referenced assembly 'Java.Interop'
with identity 'Java.Interop, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' [C:\src\xamarin-android\tests\Xamarin.Forms-Performance-Inte
gration\Droid\Xamarin.Forms.Performance.Integration.Droid.csproj]
  CSC : error CS1705: Assembly 'Xamarin.AndroidX.Fragment' with identity 'Xamarin.AndroidX.Fragment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
uses 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' which has a higher version than referenced assembly 'Java.Interop' wi
th identity 'Java.Interop, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' [C:\src\xamarin-android\tests\Xamarin.Forms-Performance-Integr
ation\Droid\Xamarin.Forms.Performance.Integration.Droid.csproj]
  CSC : error CS1705: Assembly 'Xamarin.AndroidX.Activity' with identity 'Xamarin.AndroidX.Activity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
uses 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' which has a higher version than referenced assembly 'Java.Interop' wi
th identity 'Java.Interop, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' [C:\src\xamarin-android\tests\Xamarin.Forms-Performance-Integr
ation\Droid\Xamarin.Forms.Performance.Integration.Droid.csproj]
  CSC : error CS1705: Assembly 'Xamarin.AndroidX.Core' with identity 'Xamarin.AndroidX.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Ja
va.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' which has a higher version than referenced assembly 'Java.Interop' with ident
ity 'Java.Interop, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' [C:\src\xamarin-android\tests\Xamarin.Forms-Performance-Integration\Dr
oid\Xamarin.Forms.Performance.Integration.Droid.csproj]

So I'm wondering... Should we only version the netstandard2.0 Java.Interop.dll? So only the one loaded by MSBuild would change versions for each release?

jonpryor pushed a commit to dotnet/java-interop that referenced this pull request Aug 26, 2021
Context: dotnet/android#6229
Context: dotnet/android#6229 (comment)

This reverts commit d16b1e5.

The problem is `src/Java.Interop/Java.Interop-MonoAndroid.csproj`,
which is [used by the xamarin-android build][0] to create a
"MonoAndroid-profile" assembly (see also 85be94f).  In a d16b1e5
world -- one in which `src/Java.Interop/Properties/AssemblyInfo.cs`
doesn't contain an `[assembly: AssemblyVersion(…)]` custom attribute
-- for reasons not yet known, the `SetVersion` target is never run,
and/or *can't* run, when `Java.Interop-MonoAndroid.csproj` is built:

	% msbuild /v:diag Java.Interop-MonoAndroid.csproj /p:JavaInteropProfile=Net45 \
	    /p:XAInstallPrefix=…/xamarin-android/bin/Debug/lib/xamarin.android  \
	    /p:TargetFrameworkIdentifier=MonoAndroid \
	    /p:TargetFrameworkVersion=v1.0 \
	    /p:TargetFrameworkRootPath=…/xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks

Consequently, the "MonoAndroid-profile" `Java.Interop.dll` winds up
with *no* version set, i.e. version 0.0.0.0, which breaks everything:

	MainActivity.cs(13,3): error CS1705:
	Assembly 'Xamarin.Forms.Platform.Android' with identity 'Xamarin.Forms.Platform.Android, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null'
	uses 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'
	which has a higher version than referenced assembly 'Java.Interop' with identity
	'Java.Interop, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'

In the interests of expediency -- we can't bump Java.Interop within
xamarin-android so long as d16b1e5 is in place -- revert commit
d16b1e5 so that we can un-block repo bumps.

We'll try to figure out how to properly use the `GitInfo` NuGet
package while supporting `Java.Interop-MonoAndroid.csproj` later.

[0]: https://github.com/xamarin/xamarin-android/blob/bcc315857f2cd61351ba469973043d91c902c50e/src/Mono.Android/Mono.Android.targets#L10-L35
Changes: http://github.com/xamarin/Java.Interop/compare/ff2714200107fb616828b9d1013f69605791d2ba...b7982e423952a4c4afe0c33f36ac80eed7fa57a2

  * dotnet/java-interop@b7982e42: Revert "[build] Use GitInfo to generate $(Version) (dotnet#865)" (dotnet#874)
  * dotnet/java-interop@9a878f21: [build] Properly implement "parent directory.override.props" (dotnet#300) (dotnet#873)
  * dotnet/java-interop@0c5d454c: [Java.Interop] fix .NET 6 linker warnings (dotnet#870)
  * dotnet/java-interop@8898bc14: [build] Import $(MSBuildProjectDirectory).override.props (dotnet#872)
  * dotnet/java-interop@d16b1e56: [build] Use GitInfo to generate $(Version) (dotnet#865)
  * dotnet/java-interop@2eb9ff26: [build] .NET 6 P7 Support (dotnet#869)

Set `$(XamarinAndroidToolsDirectory)` for `external/Java.Interop`
so that the Java.Interop build uses `external/xamarin-android-tools`.
@jonpryor jonpryor force-pushed the jonp-bump-ji-a8898bc1 branch from d9da10c to b5066be Compare August 26, 2021 12:23
@jonpryor jonpryor merged commit 21bfc47 into dotnet:main Aug 26, 2021
jpobst pushed a commit to dotnet/java-interop that referenced this pull request Sep 30, 2021
Context: dotnet/android#6229
Context: dotnet/android#6229 (comment)

This reverts commit d16b1e5.

The problem is `src/Java.Interop/Java.Interop-MonoAndroid.csproj`,
which is [used by the xamarin-android build][0] to create a
"MonoAndroid-profile" assembly (see also 85be94f).  In a d16b1e5
world -- one in which `src/Java.Interop/Properties/AssemblyInfo.cs`
doesn't contain an `[assembly: AssemblyVersion(…)]` custom attribute
-- for reasons not yet known, the `SetVersion` target is never run,
and/or *can't* run, when `Java.Interop-MonoAndroid.csproj` is built:

	% msbuild /v:diag Java.Interop-MonoAndroid.csproj /p:JavaInteropProfile=Net45 \
	    /p:XAInstallPrefix=…/xamarin-android/bin/Debug/lib/xamarin.android  \
	    /p:TargetFrameworkIdentifier=MonoAndroid \
	    /p:TargetFrameworkVersion=v1.0 \
	    /p:TargetFrameworkRootPath=…/xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks

Consequently, the "MonoAndroid-profile" `Java.Interop.dll` winds up
with *no* version set, i.e. version 0.0.0.0, which breaks everything:

	MainActivity.cs(13,3): error CS1705:
	Assembly 'Xamarin.Forms.Platform.Android' with identity 'Xamarin.Forms.Platform.Android, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null'
	uses 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'
	which has a higher version than referenced assembly 'Java.Interop' with identity
	'Java.Interop, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'

In the interests of expediency -- we can't bump Java.Interop within
xamarin-android so long as d16b1e5 is in place -- revert commit
d16b1e5 so that we can un-block repo bumps.

We'll try to figure out how to properly use the `GitInfo` NuGet
package while supporting `Java.Interop-MonoAndroid.csproj` later.

[0]: https://github.com/xamarin/xamarin-android/blob/bcc315857f2cd61351ba469973043d91c902c50e/src/Mono.Android/Mono.Android.targets#L10-L35
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants