In this series of posts, I’ll describe how to build a SQLite Test app that will run on Windows Runtime 8.1 Devices (Windows 8.1 and Windows Phone 8.1).
On this first post, I will briefly introduce the new “Universal Apps” Visual Studio project type, and explain how to add SQLite to the project.
Windows Phone 8.1 is finally out (as a Developer Preview) and the convergence of platforms brought us a new type of Visual Studio project type: the “Universal Apps”:
The idea is simple, yet elegant and powerful. Now that Windows Phone has joined the party, we can have a single project folder that contains three projects, one for the Windows App, one for the Windows Phone Store App and one for all the things that we want to be shared by both the previous projects:
This way we can keep the things we need to do differently for Windows Store app and Windows Phone Store app (typically the UI) and put all the rest in the shared part without any unneeded duplication.
Ok, enough talking, so let’s move on and start creating the app.
First, you need to have Visual Studio 2013 and install the Visual Studio 2013 Update 2 Release Candidate.
Then you can create a new blank Universal App and call it “SQLiteTest”:
Now that you have your wonderful three-part project, you need to add SQLite. Actually, the only way to do so is via SDK extensions of Visual Studio and you need to add two of them, one for Windows Store app and one for Windows Phone Store app.
The first extension is available as a VSIX package built by the official SQLite Development Team from the Visual Studio Extensions Gallery:
It’s worth noting that the current version (220.127.116.11) has a flaw in the package metadata that prevent it to show up in the Visual Studio 2013 “Tools | Extensions and Updates” page. You need to go to the web page, download and install the VSIX package by yourself:
You can directly open it while downloading, authorize installation and click install when ready:
The second extension is also available as a VSIX package but is a preview version built by Tim Heuer of Microsoft as temporary workaround while the official package is still not available (I’ll update this post when it will be available). More info on the Tim Heuer blog: Using SDK/library references in Universal Windows Apps where he has posted the link to his “working on my machine” version of the package, available via OneDrive:
Same as before, you can directly open it while downloading, authorize installation and click install when ready:
To double check that everything is all right, you can open Visual Studio 2013 “Tools | Extensions and Updates” and look for installed SDKs:
Once you have downloaded and installed both VSIX packages, you are finally ready to add the SQLite references to your Universal App project.
First, right click to the References container of the SQLite.Test.Windows (Windows 8.1) project:
Then add the reference to the “SQLite for Windows Runtime (Windows 8.1)” library:
Second, right click to the References container of the “SQLite.Test.WindowsPhone (Windows Phone 8.1)” project:
Then add the reference to the “SQLite for Windows Runtime (Windows Phone 8.1)” library:
When done, you can see that the proper references to SQLite and Visual C++ 2013 Runtime have been added to respective projects:
Problem is, as you may have already noticed, that the references show a warning sign. If you try to build the solution, you will receive the same error for each of the four added references (below I’ve reported the one related to the SDK “SQLite.WinRT81, Version=18.104.22.168”):
“The processor architecture of the project being built “Any CPU” is not supported by the referenced SDK “SQLite.WinRT81, Version=22.214.171.124”. Please consider changing the targeted processor architecture of your project (in Visual Studio this can be done through the Configuration Manager) to one of the architectures supported by the SDK: “x86, x64, ARM”.
Don’t panic! As better explained in the Tim Heuer’s blog, these things are platform-specific and/or native and have dependencies on various native compiler/linker options or have been compiled in such a way that are different for the Phone device versus a tablet device.
The easy solution is to open the Configuration Manager and set the platform to x86 on both projects for Debug and Release configuration. Do not chose x64 or the XAML designer will not be able to show the UI.
This will not prevent you to create the different platform version to be deployed on the store, because when ready you will use the “Create App Packages…” command:
For the Windows Store app:
and the Windows Phone Store app:
Then will be the Store that automagically will deploy the right package for the device platform of the user that is downloading our beloved app from the store.
This conclude my first post on how to create (and successfully build) a Universal App project with SQLite.
On next post, we will see how to use the Universal App project type to avoid unnecessary duplication of code by sharing the things that remain the same for both Windows Store app and Windows Phone Store app, and how to take advantage of SQLite to manage locally stored data.