Skip to content

Commit 9d03fbd

Browse files
committed
ResolveNativeLibrariesInManagedReferences works
1 parent 6ece18b commit 9d03fbd

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

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

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,20 @@ public TestMe createTestMe () {
304304
}
305305

306306
[Test]
307-
public void ResolveNativeLibrariesInManagedReferences ()
307+
public void ResolveNativeLibrariesInManagedReferences ([Values (AndroidRuntime.MonoVM, AndroidRuntime.CoreCLR)] AndroidRuntime runtime)
308308
{
309+
string abi = runtime switch {
310+
AndroidRuntime.MonoVM => "armeabi-v7a",
311+
AndroidRuntime.CoreCLR => "arm64-v8a",
312+
_ => throw new NotSupportedException ($"Unsupported runtime '{runtime}'")
313+
};
314+
309315
var lib = new XamarinAndroidLibraryProject () {
310316
ProjectName = "Lib",
311317
IsRelease = true,
312318
ProjectGuid = Guid.NewGuid ().ToString (),
313319
OtherBuildItems = {
314-
new BuildItem (AndroidBuildActions.EmbeddedNativeLibrary, "libs/armeabi-v7a/libfoo.so") {
320+
new BuildItem (AndroidBuildActions.EmbeddedNativeLibrary, $"libs/{abi}/libfoo.so") {
315321
TextContent = () => string.Empty,
316322
Encoding = Encoding.ASCII,
317323
}
@@ -332,14 +338,15 @@ public Class1 ()
332338
},
333339
},
334340
};
335-
var so = lib.OtherBuildItems.First (x => x.Include () == "libs/armeabi-v7a/libfoo.so");
341+
lib.SetRuntime (runtime);
342+
var so = lib.OtherBuildItems.First (x => x.Include () == $"libs/{abi}/libfoo.so");
336343

337344
var lib2 = new XamarinAndroidLibraryProject () {
338345
ProjectName = "Lib2",
339346
ProjectGuid = Guid.NewGuid ().ToString (),
340347
IsRelease = true,
341348
OtherBuildItems = {
342-
new BuildItem (AndroidBuildActions.EmbeddedNativeLibrary, "libs/armeabi-v7a/libfoo2.so") {
349+
new BuildItem (AndroidBuildActions.EmbeddedNativeLibrary, $"libs/{abi}/libfoo2.so") {
343350
TextContent = () => string.Empty,
344351
Encoding = Encoding.ASCII,
345352
},
@@ -363,6 +370,7 @@ public Class2 ()
363370
},
364371
},
365372
};
373+
lib2.SetRuntime (runtime);
366374
var path = Path.Combine (Root, "temp", TestName);
367375
using (var libbuilder = CreateDllBuilder (Path.Combine(path, "Lib"))) {
368376

@@ -378,12 +386,27 @@ public Class2 ()
378386
new BuildItem.ProjectReference (@"..\Lib2\Lib2.csproj", "Lib2", lib2.ProjectGuid),
379387
}
380388
};
381-
app.SetAndroidSupportedAbis ("armeabi-v7a");
389+
app.SetRuntime (runtime);
390+
391+
if (runtime == AndroidRuntime.MonoVM) {
392+
// Using `SetRuntimeIdentifier` would change the intermediate path (by adding the RID component to it) and, thus, the way this test used to work.
393+
// Keep it as it was.
394+
app.SetAndroidSupportedAbis (abi);
395+
} else {
396+
app.SetRuntimeIdentifier (abi);
397+
}
398+
382399
using (var builder = CreateApkBuilder (Path.Combine (path, "App"))) {
383400
Assert.IsTrue (builder.Build (app), "app 1st. build failed");
384401

385-
var libfoo = ZipHelper.ReadFileFromZip (Path.Combine (Root, builder.ProjectDirectory, app.OutputPath, app.PackageName + "-Signed.apk"),
386-
"lib/armeabi-v7a/libfoo.so");
402+
// TODO: appending of the RID to the output path should probably be fixed in the project class instead of here (and elsewhere)
403+
string apkFile = Path.Combine (Root, builder.ProjectDirectory, app.OutputPath);
404+
if (runtime == AndroidRuntime.CoreCLR) {
405+
apkFile = Path.Combine (apkFile, MonoAndroidHelper.AbiToRid (abi));
406+
}
407+
apkFile = Path.Combine (apkFile, app.PackageName + "-Signed.apk");
408+
409+
var libfoo = ZipHelper.ReadFileFromZip (apkFile, $"lib/{abi}/libfoo.so");
387410
Assert.IsNotNull (libfoo, "libfoo.so should exist in the .apk");
388411

389412
so.TextContent = () => "newValue";
@@ -394,11 +417,9 @@ public Class2 ()
394417

395418
Assert.IsNotNull (libfoo, "libfoo.so should exist in the .apk");
396419

397-
libfoo = ZipHelper.ReadFileFromZip (Path.Combine (Root, builder.ProjectDirectory, app.OutputPath, app.PackageName + "-Signed.apk"),
398-
"lib/armeabi-v7a/libfoo.so");
420+
libfoo = ZipHelper.ReadFileFromZip (apkFile, $"lib/{abi}/libfoo.so");
399421
Assert.AreEqual (so.TextContent ().Length, libfoo.Length, "compressed size mismatch");
400-
var libfoo2 = ZipHelper.ReadFileFromZip (Path.Combine (Root, builder.ProjectDirectory, app.OutputPath, app.PackageName + "-Signed.apk"),
401-
"lib/armeabi-v7a/libfoo2.so");
422+
var libfoo2 = ZipHelper.ReadFileFromZip (apkFile, $"lib/{abi}/libfoo2.so");
402423
Assert.IsNotNull (libfoo2, "libfoo2.so should exist in the .apk");
403424
Directory.Delete (path, recursive: true);
404425
}

0 commit comments

Comments
 (0)