Skip to content

Commit eb92c4d

Browse files
committed
Merge branch 'main' into http-compression-fix
* main: [monodroid] Properly process satellite assemblies (#7823) Bump to xamarin/java.interop/main@77800dda (#7824)
2 parents bd862d9 + 922a369 commit eb92c4d

File tree

13 files changed

+72
-90
lines changed

13 files changed

+72
-90
lines changed

build-tools/installers/create-installers.targets

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,6 @@
155155
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)jcw-gen.pdb" />
156156
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)jit-times.exe" />
157157
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)jit-times.pdb" />
158-
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)jnimarshalmethod-gen.exe" />
159-
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)jnimarshalmethod-gen.pdb" />
160-
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)Java.Interop.dll.config" />
161-
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)Java.Runtime.Environment.dll" /> <!-- Required by jnimarshalmethod-gen.exe -->
162-
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)Java.Runtime.Environment.pdb" />
163-
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)Java.Runtime.Environment.dll.config" Condition=" '$(HostOS)' != 'Windows' " />
164158
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)logcat-parse.exe" />
165159
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)logcat-parse.pdb" />
166160
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)Mono.CSharp.dll" /> <!-- Required by logcat-parse.exe -->

build-tools/scripts/JavaInteropDllConfigs.targets

Lines changed: 0 additions & 26 deletions
This file was deleted.

external/Java.Interop

src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ void AddEnvironment ()
265265
HashSet<string> archAssemblyNames = null;
266266
HashSet<string> uniqueAssemblyNames = new HashSet<string> (StringComparer.OrdinalIgnoreCase);
267267
Action<ITaskItem> updateAssemblyCount = (ITaskItem assembly) => {
268-
string assemblyName = Path.GetFileName (assembly.ItemSpec);
268+
// We need to use the 'RelativePath' metadata, if found, because it will give us the correct path for satellite assemblies - with the culture in the path.
269+
string? relativePath = assembly.GetMetadata ("RelativePath");
270+
string assemblyName = String.IsNullOrEmpty (relativePath) ? Path.GetFileName (assembly.ItemSpec) : relativePath;
269271
if (!uniqueAssemblyNames.Contains (assemblyName)) {
270272
uniqueAssemblyNames.Add (assemblyName);
271273
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,12 +807,18 @@ public void MissingSatelliteAssemblyInLibrary ()
807807
new BuildItem ("EmbeddedResource", "Foo.resx") {
808808
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancel</value></data>")
809809
},
810-
new BuildItem ("EmbeddedResource", "Foo.es.resx") {
811-
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancelar</value></data>")
812-
}
813810
}
814811
};
815812

813+
var languages = new string[] {"es", "de", "fr", "he", "it", "pl", "pt", "ru", "sl" };
814+
foreach (string lang in languages) {
815+
lib.OtherBuildItems.Add (
816+
new BuildItem ("EmbeddedResource", $"Foo.{lang}.resx") {
817+
TextContent = () => InlineData.ResxWithContents ($"<data name=\"CancelButton\"><value>{lang}</value></data>")
818+
}
819+
);
820+
}
821+
816822
var app = new XamarinAndroidApplicationProject {
817823
IsRelease = true,
818824
};
@@ -829,7 +835,10 @@ public void MissingSatelliteAssemblyInLibrary ()
829835
var apk = Path.Combine (Root, appBuilder.ProjectDirectory,
830836
app.OutputPath, $"{app.PackageName}-Signed.apk");
831837
var helper = new ArchiveAssemblyHelper (apk);
832-
Assert.IsTrue (helper.Exists ($"assemblies/es/{lib.ProjectName}.resources.dll"), "Apk should contain satellite assemblies!");
838+
839+
foreach (string lang in languages) {
840+
Assert.IsTrue (helper.Exists ($"assemblies/{lang}/{lib.ProjectName}.resources.dll"), $"Apk should contain satellite assembly for language '{lang}'!");
841+
}
833842
}
834843
}
835844

src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsNativeAssemblyGenerator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,8 @@ void WriteHashes<T> () where T: struct
816816
uint index = 0;
817817

818818
foreach (string name in uniqueAssemblyNames) {
819-
string clippedName = Path.GetFileNameWithoutExtension (name);
819+
// We must make sure we keep the possible culture prefix, which will be treated as "directory" path here
820+
string clippedName = Path.Combine (Path.GetDirectoryName (name) ?? String.Empty, Path.GetFileNameWithoutExtension (name));
820821
ulong hashFull = HashName (name, is64Bit);
821822
ulong hashClipped = HashName (clippedName, is64Bit);
822823

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,22 +1456,7 @@ because xbuild doesn't support framework reference assemblies.
14561456
DependsOnTargets="_GetReferenceAssemblyPaths;_SetLatestTargetFrameworkVersion"
14571457
Inputs="$(_AndroidBuildPropertiesCache);@(ResolvedUserAssemblies)"
14581458
Outputs="$(_AndroidStampDirectory)_GenerateJniMarshalMethods.stamp">
1459-
<ItemGroup>
1460-
<_JniFrameworkAssembly Include="Mono.Android.dll" />
1461-
<_JniFrameworkAssembly Include="OpenTK.dll" />
1462-
<_JniFrameworkAssembly Include="Xamarin.Android.NUnitLite.dll" />
1463-
<_AssembliesToProcess Include="@(ResolvedUserAssemblies)" />
1464-
<_AssembliesToProcess Include="@(ResolvedFrameworkAssemblies)" Condition=" '%(Filename)' == '@(_JniFrameworkAssembly->'%(Filename)')' " />
1465-
</ItemGroup>
1466-
<RemoveDirFixed Directories="$(_JniMarshalMethodsOutputDir)" />
1467-
<MakeDir Directories="$(_JniMarshalMethodsOutputDir)" />
1468-
<Exec
1469-
Command="DYLD_LIBRARY_PATH=&quot;$(MonoAndroidLibDirectory)&quot; MONO_CONFIG=&quot;$(MonoAndroidBinDirectory)mono.config&quot; MONO_PATH=&quot;$(MonoAndroidBinDirectory)\bcl&quot;:&quot;$(MonoAndroidBinDirectory)\bcl\Facades&quot;:&quot;$(_XATargetFrameworkDirectories)&quot; &quot;$(MonoAndroidBinDirectory)mono&quot; --debug &quot;$(MonoAndroidToolsDirectory)\jnimarshalmethod-gen.exe&quot; --jvm=&quot;$(JdkJvmPath)&quot; @(ResolvedAssemblies->'--r=&quot;%(Identity)&quot;', ' ') --o=&quot;$(_JniMarshalMethodsOutputDir)&quot; $(AndroidGenerateJniMarshalMethodsAdditionalArguments) @(_AssembliesToProcess->'&quot;%(Identity)&quot;', ' ')"
1470-
/>
1471-
<Touch Files="$(_AndroidStampDirectory)_GenerateJniMarshalMethods.stamp" AlwaysCreate="True" />
1472-
<ItemGroup>
1473-
<FileWrites Include="$(_AssembliesToProcess)" />
1474-
</ItemGroup>
1459+
<Error Text="%24(AndroidGenerateJniMarshalMethods)=True is not supported at this time." />
14751460
</Target>
14761461

14771462
<Target Name="_LinkAssembliesNoShrinkInputs">

src/monodroid/jni/xamarin-android-app-context.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ MonodroidRuntime::get_method_name (uint32_t mono_image_index, uint32_t method_to
1313
{
1414
uint64_t id = (static_cast<uint64_t>(mono_image_index) << 32) | method_token;
1515

16-
log_debug (LOG_ASSEMBLY, "Looking for name of method with id 0x%llx, in mono image at index %u", id, mono_image_index);
16+
log_debug (LOG_ASSEMBLY, "MM: looking for name of method with id 0x%llx, in mono image at index %u", id, mono_image_index);
1717
size_t i = 0;
1818
while (mm_method_names[i].id != 0) {
1919
if (mm_method_names[i].id == id) {
@@ -58,19 +58,15 @@ MonodroidRuntime::get_function_pointer (uint32_t mono_image_index, uint32_t clas
5858
// We need to do that, as Mono APIs cannot be invoked from threads that aren't attached to the runtime.
5959
mono_thread_attach (mono_get_root_domain ());
6060

61-
// We don't check for valid return values from image loader, class and method lookup because if any
62-
// of them fails to find the requested entity, they will return `null`. In consequence, we can pass
63-
// these pointers without checking all the way to `mono_method_get_unmanaged_callers_only_ftnptr`, after
64-
// which call we check for errors. This saves some time (not much, but definitely more than zero)
6561
MonoImage *image = MonoImageLoader::get_from_index (mono_image_index);
6662
MarshalMethodsManagedClass &klass = marshal_methods_class_cache[class_index];
6763
if (klass.klass == nullptr) {
68-
klass.klass = mono_class_get (image, klass.token);
64+
klass.klass = image != nullptr ? mono_class_get (image, klass.token) : nullptr;
6965
}
7066

71-
MonoMethod *method = mono_get_method (image, method_token, klass.klass);
67+
MonoMethod *method = klass.klass != nullptr ? mono_get_method (image, method_token, klass.klass) : nullptr;
7268
MonoError error;
73-
void *ret = mono_method_get_unmanaged_callers_only_ftnptr (method, &error);
69+
void *ret = method != nullptr ? mono_method_get_unmanaged_callers_only_ftnptr (method, &error) : nullptr;
7470

7571
if (XA_LIKELY (ret != nullptr)) {
7672
if constexpr (NeedsLocking) {

src/monodroid/monodroid.csproj

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,5 @@
1717

1818
<ItemGroup>
1919
<ProjectReference Include="..\java-runtime\java-runtime.csproj" ReferenceOutputAssembly="False" />
20-
<!--
21-
`jnimarshalmethod-gen.exe` needs to be built first because our
22-
`_CreateJavaInteropDllConfigs` target replaces
23-
`Java.Runtime.Environment.dll.config`, which will be created as
24-
part of the `jnimarshalmethod-gen.exe` build.
25-
26-
We don't want our updated version to be replaced by the
27-
`jnimarshalmethod-gen.exe` build.
28-
-->
29-
<ProjectReference Include="..\..\external\Java.Interop\tools\jnimarshalmethod-gen\Xamarin.Android.Tools.JniMarshalMethodGenerator.csproj" ReferenceOutputAssembly="False" />
3020
</ItemGroup>
3121
</Project>

src/monodroid/monodroid.targets

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<Import Project="..\..\external\Java.Interop\bin\Build$(Configuration)\JdkInfo.props" Condition="Exists('..\..\external\Java.Interop\bin\Build$(Configuration)\JdkInfo.props')"/>
44
<Import Project="..\..\bin\Build$(Configuration)\cmake-config.props" Condition="Exists('..\..\bin\Build$(Configuration)\cmake-config.props')" />
55
<Import Project="monodroid.projitems" />
6-
<Import Project="..\..\build-tools\scripts\JavaInteropDllConfigs.targets" />
76
<UsingTask AssemblyFile="$(BootstrapTasksAssembly)" TaskName="Xamarin.Android.Tools.BootstrapTasks.GenerateMonoDroidIncludes" />
87
<UsingTask AssemblyFile="$(BootstrapTasksAssembly)" TaskName="Xamarin.Android.Tools.BootstrapTasks.RunParallelCmds" />
98
<UsingTask AssemblyFile="$(PrepTasksAssembly)" TaskName="Xamarin.Android.BuildTools.PrepTasks.ReplaceFileContents" />
@@ -207,7 +206,7 @@
207206
</Target>
208207

209208
<Target Name="_BuildHostRuntimes"
210-
DependsOnTargets="_CreateJavaInteropDllConfigs;_BuildHostRuntimesInputs"
209+
DependsOnTargets="_BuildHostRuntimesInputs"
211210
Inputs="@(_BuildHostRuntimesInputs)"
212211
Outputs="@(_BuildHostRuntimesOutputs)">
213212
<Message Text="Building host runtime %(_HostRuntime.Identity) in $(OutputPath)%(_HostRuntime.OutputDirectory)"/>

tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,56 @@ public void Teardown ()
2525
Directory.Delete (builder.ProjectDirectory, recursive: true);
2626

2727
builder?.Dispose ();
28+
builder = null;
2829
proj = null;
2930
}
3031

32+
[Test]
33+
public void NativeAssemblyCacheWithSatelliteAssemblies ()
34+
{
35+
var path = Path.Combine ("temp", TestName);
36+
var lib = new XamarinAndroidLibraryProject {
37+
ProjectName = "Localization",
38+
OtherBuildItems = {
39+
new BuildItem ("EmbeddedResource", "Foo.resx") {
40+
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancel</value></data>")
41+
},
42+
}
43+
};
44+
45+
var languages = new string[] {"es", "de", "fr", "he", "it", "pl", "pt", "ru", "sl" };
46+
foreach (string lang in languages) {
47+
lib.OtherBuildItems.Add (
48+
new BuildItem ("EmbeddedResource", $"Foo.{lang}.resx") {
49+
TextContent = () => InlineData.ResxWithContents ($"<data name=\"CancelButton\"><value>{lang}</value></data>")
50+
}
51+
);
52+
}
53+
54+
proj = new XamarinAndroidApplicationProject {
55+
IsRelease = true,
56+
};
57+
proj.References.Add (new BuildItem.ProjectReference ($"..\\{lib.ProjectName}\\{lib.ProjectName}.csproj", lib.ProjectName, lib.ProjectGuid));
58+
proj.SetAndroidSupportedAbis ("armeabi-v7a", "arm64-v8a", "x86", "x86_64");
59+
60+
using (var libBuilder = CreateDllBuilder (Path.Combine (path, lib.ProjectName))) {
61+
builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName));
62+
Assert.IsTrue (libBuilder.Build (lib), "Library Build should have succeeded.");
63+
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");
64+
65+
var apk = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, $"{proj.PackageName}-Signed.apk");
66+
var helper = new ArchiveAssemblyHelper (apk);
67+
68+
foreach (string lang in languages) {
69+
Assert.IsTrue (helper.Exists ($"assemblies/{lang}/{lib.ProjectName}.resources.dll"), $"Apk should contain satellite assembly for language '{lang}'!");
70+
}
71+
72+
Assert.True (builder.RunTarget (proj, "_Run"), "Project should have run.");
73+
Assert.True (WaitForActivityToStart (proj.PackageName, "MainActivity",
74+
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30), "Activity should have started.");
75+
}
76+
}
77+
3178
[Test]
3279
public void GlobalLayoutEvent_ShouldRegisterAndFire_OnActivityLaunch ([Values (false, true)] bool isRelease)
3380
{

tests/Mono.Android-Tests/Directory.Build.targets

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,4 @@
2424
<Exec Command="&quot;$(NdkBuildPath)&quot;" WorkingDirectory="$(MSBuildThisFileDirectory)"/>
2525
</Target>
2626

27-
<Import Project="$(MSBuildThisFileDirectory)..\..\build-tools\scripts\JavaInteropDllConfigs.targets" />
28-
29-
<!-- Not required when testing against a system installation of XA. -->
30-
<Target Name="EnsureJavaInteropDllConfigs"
31-
Condition="Exists ('$(XAInstallPrefix)xbuild\Xamarin\Android\Java.Interop.dll')"
32-
BeforeTargets="_GenerateJniMarshalMethods"
33-
DependsOnTargets="_CreateJavaInteropDllConfigs">
34-
</Target>
35-
3627
</Project>

tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.targets

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,4 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="Xamarin.Forms.Performance.Integration.Droid.projitems" />
44
<Import Project="$(XamarinAndroidSourcePath)build-tools\scripts\TestApks.targets" />
5-
<Import Project="$(XamarinAndroidSourcePath)build-tools\scripts\JavaInteropDllConfigs.targets" />
6-
<Target Name="EnsureJavaInteropDllConfigs"
7-
Condition="Exists ('$(XAInstallPrefix)xbuild\Xamarin\Android\Java.Interop.dll')"
8-
BeforeTargets="_GenerateJniMarshalMethods"
9-
DependsOnTargets="_CreateJavaInteropDllConfigs">
10-
</Target>
115
</Project>

0 commit comments

Comments
 (0)