Skip to content

Commit 481b94a

Browse files
[tests] enable sqlite-net-pcl test in .NET 6 (#5366)
Fixes: #5319 Context: ericsink/SQLitePCL.raw#383 This test was originally failing in 6e3e383 with: android.runtime.JavaProxyThrowable: System.TypeInitializationException: The type initializer for 'SQLite.SQLiteConnection' threw an exception. ---> System.DllNotFoundException: e_sqlite3 at System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName(String libraryName, Assembly assembly, Nullable`1 searchPath, Boolean throwOnError) at System.Runtime.InteropServices.NativeLibrary.Load(String libraryName, Assembly assembly, Nullable`1 searchPath) at SQLitePCL.NativeLibrary.Load(String libraryName, Assembly assy, Int32 flags) at SQLitePCL.Batteries_V2.MakeDynamic(String name, Int32 flags) at SQLitePCL.Batteries_V2.DoDynamic_cdecl(String name, Int32 flags) at SQLitePCL.Batteries_V2.Init() at SQLite.SQLiteConnection..cctor() The problem being one of the transitive dependencies of `sqlite-net-pcl`: [`SQLitePCLRaw.bundle_green`][0]. `SQLitePCLRaw.bundle_green` pulls in even more packages: .NETCoreApp 3.1 SQLitePCLRaw.core (>= 2.0.4) SQLitePCLRaw.lib.e_sqlite3 (>= 2.0.4) SQLitePCLRaw.provider.dynamic_cdecl (>= 2.0.4) MonoAndroid 8.0 SQLitePCLRaw.core (>= 2.0.4) SQLitePCLRaw.lib.e_sqlite3.android (>= 2.0.4) SQLitePCLRaw.provider.e_sqlite3 (>= 2.0.4) `SQLitePCLRaw.lib.e_sqlite3.android` contains the `libe_sqlite3.so` native library for Android. In .NET 6, NuGet is preferring the `.NETCoreApp 3.1` packages over the `MonoAndroid 8.0` ones. This means that the `MonoAndroid 8.0` package contents aren't included in the `.apk`, resulting in the `DllNotFoundException`. To manually workaround the problem we can add an explicit `@(PackageReference)` to [`SQLitePCLRaw.lib.e_sqlite3.android`][1] into the Android head project: <PackageReference Include="SQLitePCLRaw.lib.e_sqlite3.android" Version="2.0.4" /> Then the test works as expected. [Eventually, `SQLitePCLRaw.bundle_green` will need to include][2] dependencies for .NET 6, such as: net6.0-android SQLitePCLRaw.core (>= 2.0.4) SQLitePCLRaw.lib.e_sqlite3.android (>= 2.0.4) SQLitePCLRaw.provider.e_sqlite3 (>= 2.0.4) net6.0-ios SQLitePCLRaw.core (>= 2.0.4) SQLitePCLRaw.provider.dynamic_cdecl (>= 2.0.4) This will solve the problem for customers going forward. [0]: https://www.nuget.org/packages/SQLitePCLRaw.bundle_green/ [1]: https://www.nuget.org/packages/SQLitePCLRaw.lib.e_sqlite3.android/ [2]: ericsink/SQLitePCL.raw#383
1 parent 6c95fb0 commit 481b94a

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

tests/MSBuildDeviceIntegration/Resources/LinkDescTest/MainActivityReplacement.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ protected override void OnCreate(Bundle bundle)
116116
Android.Util.Log.Info(TAG, cldt.TryAccessNonXmlPreservedMethodOfLinkerModeFullClass());
117117
Android.Util.Log.Info(TAG, LinkTestLib.Bug21578.MulticastOption_ShouldNotBeStripped());
118118
Android.Util.Log.Info(TAG, LinkTestLib.Bug21578.MulticastOption_ShouldNotBeStripped2());
119-
#if !NET
120119
Android.Util.Log.Info(TAG, LinkTestLib.Bug35195.AttemptCreateTable());
121-
#endif
122120
Android.Util.Log.Info(TAG, LinkTestLib.Bug36250.SerializeSearchRequestWithDictionary());
123121

124122
Android.Util.Log.Info(TAG, "All regression tests completed.");

tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ public class LinkModeFullClass {
317317
ProjectName = "LinkTestLib",
318318
Sdk = "Microsoft.NET.Sdk",
319319
TargetFramework = "netstandard2.0",
320+
PackageReferences = {
321+
new Package {
322+
Id = "sqlite-net-pcl",
323+
Version = "1.7.335",
324+
}
325+
},
320326
Sources = {
321327
new BuildItem.Source ("Bug21578.cs") {
322328
TextContent = () => {
@@ -330,23 +336,15 @@ public class LinkModeFullClass {
330336
return sr.ReadToEnd ();
331337
},
332338
},
339+
new BuildItem.Source ("Bug35195.cs") {
340+
TextContent = () => {
341+
using (var sr = new StreamReader (typeof (InstallAndRunTests).Assembly.GetManifestResourceStream ("Xamarin.Android.Build.Tests.Resources.LinkDescTest.Bug35195.cs")))
342+
return sr.ReadToEnd ();
343+
},
344+
},
333345
},
334346
};
335347

336-
// sqlite-net-pcl does not work in .NET 6
337-
if (!Builder.UseDotNet) {
338-
lib2.PackageReferences.Add (new Package {
339-
Id = "sqlite-net-pcl",
340-
Version = "1.7.335",
341-
});
342-
lib2.Sources.Add (new BuildItem.Source ("Bug35195.cs") {
343-
TextContent = () => {
344-
using (var sr = new StreamReader (typeof (InstallAndRunTests).Assembly.GetManifestResourceStream ("Xamarin.Android.Build.Tests.Resources.LinkDescTest.Bug35195.cs")))
345-
return sr.ReadToEnd ();
346-
},
347-
});
348-
}
349-
350348
proj = new XamarinFormsAndroidApplicationProject () {
351349
IsRelease = true,
352350
AndroidLinkModeRelease = linkMode,
@@ -373,6 +371,14 @@ public class LinkModeFullClass {
373371
},
374372
},
375373
};
374+
if (Builder.UseDotNet) {
375+
// NOTE: workaround for netcoreapp3.1 dependency preferred over monoandroid8.0
376+
proj.PackageReferences.Add (new Package {
377+
Id = "SQLitePCLRaw.lib.e_sqlite3.android",
378+
Version = "2.0.4",
379+
});
380+
}
381+
376382
proj.AndroidManifest = proj.AndroidManifest.Replace ("</manifest>", "<uses-permission android:name=\"android.permission.INTERNET\" /></manifest>");
377383
proj.SetAndroidSupportedAbis ("armeabi-v7a", "arm64-v8a", "x86", "x86_64");
378384
using (var sr = new StreamReader (typeof (InstallAndRunTests).Assembly.GetManifestResourceStream ("Xamarin.Android.Build.Tests.Resources.LinkDescTest.MainActivityReplacement.cs")))

0 commit comments

Comments
 (0)