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 (3.8.4.3) 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=3.8.4.3”):
“The processor architecture of the project being built “Any CPU” is not supported by the referenced SDK “SQLite.WinRT81, Version=3.8.4.3”. 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.
Happy coding!
Pedro
May 1, 2014
Hi,
Thanks to this tutorial I was able to get the extension added to my Windows Phone 8.1 project, thanks!
The problem is that although the reference is there, I cannot access the SQLite namespace:
The type or namespace name ‘SQLite’ could not be found (are you missing a using directive or an assembly reference?)
Any ideas? Thanks for your help!
Muhammad Saifullah
May 1, 2014
Hi,
Thanks very nice and well explanatory artical. It is what I was looking for. I have tried this in my MVVM light universal app it works fine in emulator. But when i try to deploy the app to windows phone device it gives following compile time error.
The name “ViewModelLocator” does not exist in the namespace “using:App3.ViewModel”.
any idea
Marcos Martins
Mar 11, 2015
I know its a long time ago..but did you solve this ViewModelLocator issue?
I have the same problem here, just cant make it run at the device.
Nathan Carroll
May 7, 2014
Have you gotten to point of common object library with SQLite references that is accessible for a WP universal app and a Win 8 universal app?
Universal App with SQLite – Part 1 | GUIDO MAGRIN
May 7, 2014
[…] http://blog.tpcware.com/2014/04/universal-app-with-sqlite-part-1/ […]
Universal App with SQLite – Part 1 | A developer’s blog | CompkSoft
Jun 1, 2014
[…] http://blog.tpcware.com/2014/04/universal-app-with-sqlite-part-1/ […]
Windows Phone 8.0, Phone 8.1, Windows 8.1–Experiments Accessing SQLite - Mike Taulty's Blog - Mike Taulty's Blog
Jun 4, 2014
[…] Universal App with SQLite – Part 1 […]
Universal App with SQLite – Part 1 | World Wide Code
Jun 6, 2014
[…] This post is from Nicolò Carandini‘s blog post Universal App with SQLite – Part 1 […]
mike wiegand
Jun 24, 2014
Thank u so very much!!! Awesome writeup!
Tim Gabrhel
Jul 2, 2014
SQLite for Windows Phone 8.1 is available. Tim updated his blog post to include this link
http://visualstudiogallery.msdn.microsoft.com/5d97faf6-39e3-4048-a0bc-adde2af75d1b
Jim
Aug 9, 2014
It appears that the WP version of the library isn’t available anymore. Could you point us in the direction where we could find it? Thanks.
bhaskar
Aug 15, 2014
Does anyone have a working SQLite sample on how to read existing SQLite database using a Universal App? Please help me..
ErikEJ
Aug 17, 2014
Time to update the blogpost, as the official Windows Phone 8.1 SQLite package is available: http://visualstudiogallery.msdn.microsoft.com/5d97faf6-39e3-4048-a0bc-adde2af75d1b
Using SQLite as local database with Universal Apps | I Love Windows Phone
Oct 7, 2014
[…] Universal App With Sqlite Part -1 […]
Himanshu Mittal
Oct 12, 2014
Thank You!! I needed this so badly, though this is missing in the blog “await conn.CreateTableAsync();”
Himanshu Mittal
Oct 12, 2014
Thank You!! I needed this so badly, though this is missing in the blog
“await conn.CreateTableAsync();”
Universal App with SQLite – Part 2 – ThinkWP
Nov 6, 2014
[…] the first post, I briefly introduced the new “Universal App” Visual Studio project type, and explained how to […]
Mona Mehta
Nov 14, 2014
Hi..
Thanks for this lovely blog post.It helps a lot
Angelo
Dec 12, 2014
thanks!thanks!!!!!
Gopi Soni
Dec 19, 2014
Hi, Thanks for your post
How can I develop with “Any CPU” ? Is there any way to develop Universal app with any cpu ?
Elly
Jan 17, 2015
Thank you so much for this post!
Finally I manage to make it work! 😀
Hantsaniala
Apr 22, 2015
Hi everyone!
I have some problème with the extention manager. I have all of these extension but there is no SQLite Windows Phone 8.1 when I want to add the reference.. Help me please.
Thanks for all!!
Visual Studio Toolbox | Martin Kašpar
Aug 24, 2015
[…] Tutorial zde: http://blog.tpcware.com/2014/04/universal-app-with-sqlite-part-1/ […]
Siddhant
Aug 24, 2015
After adding the references I get an error related to MakePri.exe .
Indexer and Scaling error just upon building it after adding references.
Please help.
Juan pablo
Dec 19, 2015
Thats ok for win 8.1 universal. But What about W10 Universal app?
I’m trying to add Winphone reference but it only shows Windows library. even booth of them are allready installed.
Any tutorial about SQLite and w10 UWP?
Copyright © 2013 Nicolò Carandini - This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License