Android + SQLITE + Unity3D Stepping Introduction


The full text is longer, but I wrote about many problems I encountered thoroughly, I hope I can help you


Foreword:

Recently, I have been discussing with the teacher the need The first step for launching the mobile phone platform is the Android platform. Because the WeChat applet does not show that kind of realism, we continue to develop with Unity3D. Although I have several years of development experience for unity3d, I have never really touched the mobile platform, all on the PC and web. Next are the pits that have been stepped on, and more are related to sqlite.

Finally, the problem that stuck me was this android-Unity SQLite conection unable to open database file-Stack Overflow. I was stuck on this problem for a long time, and it was almost a day. Fortunately, it was finally solved. These efforts have been made for nothing, and I have used these time to understand many things. Next one by one:


First, how many dll and so files are needed to release Android

The first thing to know is what the dll file is for. Chinese is a dynamic link library. Simply put, some functions prepared in advance are placed in it, and then the program can be called from it. The problem is that the dll is actually windows. The concept under the platform, that is to say, if it runs well under the PC, and there is a problem with Android, then it must be the problem of the so file, not the dll file.

Then, what is the so file? It is for Android. Whether or not it is in the PC environment, it has no effect on the results of the Editor. The so file can actually be understood as a dynamic link library of Linux. Because the architectures of Android and Linux are the same, so files are used.

  • For sqlite3, we need these files: Mono.Data.Sqlite.dll (from the unity directory of the corresponding version Unity\Editor\Data\MonoBleedingEdge\lib\mono\2.0 Copy) and sqlite3.dll (download from the official website https://www.sqlite.org/download.html the version suitable for development computers, not the Android version)
  • For the release of the Android platform, we These files need to be added: System.Data.dll (copied from the unity directory of the corresponding version Unity\Editor\Data\MonoBleedingEdge\lib\mono\2.0) and libsqlite3.so (download here)
  • < /ul>


    Second, the configuration problem of dll file and so file

    The first problem is to download the correct version, which has been discussed in the previous section, and now what needs to be done is in Unity Configure the related properties, one thing that needs to be mentioned here is the version! The version of Unity3D! Not all versions are stable. For example, the issue of web GL release mentioned in my previous essays: IL2CPP issue is a version issue, but the latest stable version of Android is definitely the most Easy to use. I am now at version 2019.2.0 and the exported APK is correct.

    The configuration of Mono.Data.Sqlite.dll and sqlite3.dll files are the same:

    share picture

    System.Data.dll file configuration: because this is only for Android , Need to be packaged in the package, but not in the PC environment, so only choose the Android platform. If the whole platform, there will be a red bug. In the 2017 version, there is no such bug, but there is in the 2019 version. I encountered this problem after the upgrade. This is to tell you the meaning of this file. Don’t do it at this time. Delete, although the unity editor test is very good, but there is no such file after the apk, the program is still GG, please configure as follows.

    share picture

    libsqlite3.so file Configuration: As I mentioned above, the so file corresponds to the platform. In the old unity version, Android is released for all platforms. That is to say, unity3d defaults that your so is also suitable for all platforms, but it is downloaded online The so file here only corresponds to the armv7 platform (that is, the mainstream platform, v8 is downward compatible), so it should be configured like this.

    share picture

    if so file configuration Not good, it is easy to have the following problem Database is not open ******balabala

    share picture


    Three, matters needing attention when publishing

    Two common packaging problems are mentioned in another essay One is the problem of packaging location, the other is the problem of net 2.0, and then there is another problem: you must tick off the unneeded platforms in the configuration of the other setting in the Player setting of the Project setting. This is where:

    Share pictures


    Four. These four are required Where should I put my files?

    Most of the statements on the Internet are actually being copied, and there is no explanation for why. In fact, the dll file and the so file must be placed in a Plugins folder, and the files that need to be packaged and need to be configured must be placed in it, and then the .db database file does not need to be as complicated, you can put it like me Under the assets under Asset/Android, it can also be placed under the StreamingAssets created by Assets. It is ok, as long as it can be obtained and copied to the Android platform.

    share picture

    It is still under development, and there will definitely be other problems, to be continued. . .

Leave a Comment

Your email address will not be published.