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

SQLitePCLRaw.lib.e_sqlite3.android support of .NET Standard 2.0 #615

Open
IvanMurzak opened this issue Dec 11, 2024 · 4 comments
Open

SQLitePCLRaw.lib.e_sqlite3.android support of .NET Standard 2.0 #615

IvanMurzak opened this issue Dec 11, 2024 · 4 comments

Comments

@IvanMurzak
Copy link

IvanMurzak commented Dec 11, 2024

Thank you @ericsink for your incredible work and for the years of maintenance and updates of all these pages, that is very impressive!

I just want to ask to add support of .NET Standard 2.0 to SQLitePCLRaw.lib.e_sqlite3.android package. I hope it won't be too complicated.

The goal

It will let Unity developers to use the package in Unity project. Unity has restrictions to support only .NET Standard 2.0 (and 2.1 in newer versions of Unity).

Prove of concept

I downloaded and unpacked Android libraries from the SQLitePCLRaw.lib.e_sqlite3.android package. Manually included them into Unity project, then combined it with set of SQLitePCLRaw packages. Made builds in Unity for multiple different platforms in combination with EntityFrameworkCore set of packages I earlier added to UnityNuGet (Nuget alternative for Unity, because Unity isn't able to work with original Nuget).
And in the end I proved the functionality in builds for the next platforms:

  • Windows
  • Android
  • iOS

Will do MacOS test later as well, it is less important because statistically it is very low amount of players in the world who plays on MacOS.

Almost done creating the bundle package (inspired by your bundle packages) that will let Unity developers to include "ready to go" bundle with EFCore + SQLitePCLRaw packages that will just work. For now the package contains pure android libs which I grabbed from your package, which is not ideal. They shouldn't be there, that is why I am asking you to add the .NET Standard 2.0 support.

Thanks in advance!

@ericsink
Copy link
Owner

I would need to get more specifics here.

SQLitePCLRaw supports .NET Standard 2.0 already, and has for a long time. Nonetheless, I get a steady stream of people saying it doesn't work well with Unity. And since I'm not a Unity developer, I've never worked through the issues to get it fixed.

In principle, I'd like Unity support to work well. But I'm not sure that "support .NET Standard 2.0" == "good Unity support", unless you have more specific info to explain that.

@IvanMurzak
Copy link
Author

Thanks for the quick reply.

Of course. Let me break it down. But first need to specify, that I am talking specifically about SQLitePCLRaw.lib.e_sqlite3.android. It doesn't have .NET Standard 2.0 in the list of frameworks. Which is needed to be compatible with Unity.

SQLitePCLRaw supports .NET Standard 2.0 already.

It is, no issues with that. But only SQLitePCLRaw.lib.e_sqlite3.android does not.

Short answer

Yes, "support .NET Standard 2.0" == "good Unity support" is True. That is only what I need to make everything to work in a beautiful way.

Detailed answer

Lets break the Unity's world down.

  1. Unity supports only two frameworks. Entire project + dependencies would be compiled based on one of them.
    image

  2. Unity doesn't support NuGet packages out of the box. There is a workaround for that. UnityNuGet project, that simply parses listed NuGet packages periodically and converts them to readable to Unity package format (such as NPM package).

    The project accepts to the listed registry of packages only the packages that support .NET Standard 2.0 and/or .NET Standard 2.1. Looks like there is no critical difference between 2.0 and 2.1, but that is out my knowledge.

    At this point we lost .NET Framework, and only .NET Standard 2.0 is left.

  3. We are adding some great packages from NuGet to UnityNuGet time by time to use them in Unity in simple way - as a dependency. If not to do that, the only option is to grab the NuGet file, unpack it, grab needed files and drop it into Unity's project. And to repeat the process for each dependency the package has in recursive way. Which is ugly. And that is exactly what I did with SQLitePCLRaw.lib.e_sqlite3.android for now, to prove that it would work.

I added some SQLitePCLRaw packages to UnityNuGet in 2022 and used them as a charm in Unity project for Windows. Today I want to make it work for Android and iOS as well. The last lost jigsaw piece is the native android lib files that I manually exported from your android package for now.

image

All what I need is to have SQLitePCLRaw.lib.e_sqlite3.android compatible with .NET Standard 2.0 (or 2.1).
As a bonus, would be super awesome to do the same with SQLitePCLRaw.lib.e_sqlite3.ios.

ericsink added a commit that referenced this issue Dec 13, 2024
@ericsink
Copy link
Owner

I just pushed up a prerelease to nuget.org which contains a little change for this issue.

Does it work?

@PitouGames
Copy link

PitouGames commented Feb 6, 2025

Hi,
I was working on the same thing as @IvanMurzak. I have a desktop Unity application (that uses SQLitePCL.Raw) that I wanted to try on an Android phone.

At first, I tried with the version 2.1.10, using the .net6.0 android provider. Of course I wasn't able to build from Unity, because I got errors during the build...
Then, I found this issue and tried the version 2.1.11-pre20241216174303 that provide .NET Standard 2.0 dll and it worked great @ericsink! Thank you! 😃


Here is a step by step tutorial for anyone that want to add SQLitePCL Raw to a Unity project by hand without using any other tool than Unity:

  • Download the core package, version 2.1.11-pre20241216174303 or later. You will get a sqlitepclraw.core.2.1.xxx.nupkg file. Rename it to replace .nupkg to .zip, and extract the files outside of the Unity project. (7zip allows to extract .nupkg files directly)
  • Do the same for provider.e_sqlite
  • Do the same for bundle_green
  • Do the same for lib.e_sqlite3
  • Do the same for lib.e_sqlite3.android
  • Create a new Unity projet (I was using Unity 6000.0.17f1)
  • In your Assets, create a new Plugins folder, and inside it two sub-folders Android and x86_64
  • From core extracted files, copy dll file lib\netstandard2.0\SQLitePCLRaw.core.dll to the Unity Plugins folder
  • From provider.e_sqlite extracted files, copy dll file lib\netstandard2.0\SQLitePCLRaw.provider.e_sqlite3.dll to the Unity Plugins folder
  • From bundle_green extracted files, copy dll file lib\netstandard2.0\SQLitePCLRaw.batteries_v2.dll to the Unity Plugins folder
  • From lib.e_sqlite3 extracted files, copy dll file runtimes\win-x64\native\e_sqlite3.dll to the Unity Plugins\x86_64 folder. Make sure Unity automatically selected this plugin only for Editor and Standalone.
  • At this step, it should work in the editor (and Windows builds). To verify, create a C# script called InitSQLitePCL containing:
using UnityEngine;

public class InitSQLitePCL : MonoBehaviour
{
    private void Awake()
    {
        SQLitePCL.Batteries_V2.Init();
        Debug.Log("Batteries_V2.Init() done!");
    }
}
  • Place this script on a GameObject in your scene. Save scene and press Play. You should see the log "Batteries_V2.Init() done!" and have no exception/error messages.
  • From the lib.e_sqlite3.android extracted files, copy dll file lib\netstandard2.0\SQLitePCLRaw.lib.e_sqlite3.android.dll to the Unity Plugins\Android folder. Make sure Unity automatically selected this plugin only for Android.
  • From the lib.e_sqlite3.android extracted files go to lib\net6.0-android31.0 and locate SQLitePCLRaw.lib.e_sqlite3.android.aar. Rename it to replace .aar to .zip and extract the files. (7zip allows to extract .aar files directly)
  • Go inside the extracted files, in the jni folder, and copy the 4 folders (arm64-v8a, armeabi-v7a, x86 and x86_64) inside the Unity Plugins\Android folder.

Now you can Build & Run on Android! I tested with an Android 14 phone.

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

No branches or pull requests

3 participants