Skip to content

Add SQLitePCLRaw.bundle_green dependencies for .NET 6 #383

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

Closed
wants to merge 1 commit into from

Conversation

jonathanpeppers
Copy link

@jonathanpeppers jonathanpeppers commented Dec 3, 2020

Context: dotnet/android#5366

In fixing a test using sqlite-net-pcl in .NET 6 on Android, I found
that SQLitePCLRaw.bundle_green is preferring the netcoreapp3.1
dependencies over the monoandroid8.0 ones.

I could workaround the problem by adding a <PackageReference/>:

<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3.android" Version="2.0.4" />

Then at least some simple C# code that creates a table works in .NET 6
(on Android). If we add more target frameworks for net6.0-android
and net6.0-ios, the existing Xamarin NuGet packages should pretty
much work in .NET 6.

This may not build at all, depending on the NuGet version being used
here, but I thought this could at least get the conversation going.

If you want to try out things in a real app, try:

https://github.com/xamarin/net6-samples

Let me know if you have other thoughts, thanks!

Context: dotnet/android#5366

In fixing test using `sqlite-net-pcl` in .NET 6 on Android, I found
that `SQLitePCLRaw.bundle_green` is preferring the `netcoreapp3.1`
dependencies over the `monoandroid8.0` ones.

I could workaround the problem by adding a `<PackageReference/>`:

    <PackageReference Include="SQLitePCLRaw.lib.e_sqlite3.android" Version="2.0.4" />

Then at least some simple C# code that creates a table works in .NET 6
(on Android). If we add more target frameworks for `net6.0-android`
and `net6.0-ios`, the existing Xamarin NuGet packages should pretty
much work in .NET 6.

This may not build at all, depending on the NuGet version being use
here, but I thought this could at least get the conversation going.

If you want to try out things in a real app, try:

https://github.com/xamarin/net6-samples
jonpryor pushed a commit to dotnet/android that referenced this pull request Dec 4, 2020
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
@ericsink ericsink mentioned this pull request Jan 19, 2021
@ericsink
Copy link
Owner

Is this PR still "fresh" with respect to the .NET 6 previews that have happened since it was submitted?

My goal is to finally do a 2.0.5 release sometime in August, and I want that release to be as ready as possible for .NET 6, keeping in mind that I still have Sep + Oct to do any further net6.0-specific fixes.

@jonathanpeppers
Copy link
Author

The changes here seem valid, but you should probably test. There are behavior changes in NuGet in .NET 6 which might require you to specify net6.0-ios and net6.0-android:

https://github.com/dotnet/designs/blob/main/accepted/2021/net6.0-tfms/net6.0-tfms.md#compatibility-rules

I would try just installing .NET 6 and the Android workload. Then try dotnet new android and playing with that in VS 2022.

Here is an example I had to workaround something with SQLitePCLRaw.bundle_green specifically:

dotnet/android@0e5e06f

@jonathanpeppers
Copy link
Author

Closing this to clear out my list -- but let me know if you need assistance here, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants