last day (14 days later) » 

2:27 PM
0
A: Unable to install 'SQLite.Net.Platform.XamarinAndroid'

Avi K.The package you are trying to install is deprecated. For the PCL project, you need to install the SQLite.Net-PCL. The SQLite.Net-PCL is the package that you can use in Xamarin.Android, Xamarin.IOS and PCL projects: https://www.nuget.org/packages/SQLite.Net-PCL/

 
is it SQLite.Net.Platform.XamarinAndriod is exists now? @Avi K.
 
From what I understand, the SQLite.Net-PCL contains the different implementations, including the Android one but there isn't a standalone SQLite.Net.Platform.XamarinAndroid package anymore. You need to install the SQLite.Net-PCL package in each type of project you need the sqlite functionality in.
 
what would be the solution to connect sqlite on specific platform?
 
Install the SQLite.Net-PCL package on that platform - it will automatically install the right implementation for the chosen platform.
 
new SQLite.Net.SQLiteConnection('', dbPath); how we can we give arguments for this ? as platform attribute is not more in latest versions
 
2:27 PM
var conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(), dbPath);
 
but there is no 'SQLite.Net.Platform' exists.. can you please verify yourself.. for SQLite.Net-PCL 3.1.1 . please verify once.
hi
 
I think you are using it wrong. You need to write this code in your Xamarin.Android project.
If you want to use it in the PCL project - you can do it by using DependencyInjection.
 
I am writing on Portable class library
 
That's what I thougth :)
Ok, so the solution is pretty simple.
Just a sec
 
using DependencyInjection.. can you please give some reference?
 
2:30 PM
Basically, you can create a GetConnection method in your Xamarin.Android project and use it in your PCL project by using the dependency service.
 
ok. do you mean creating connection andriod project and should get that connection into the PCL for writing the code further?
 
Exactly.
For example, In your PCL create the following class and interface:
public class Sql
{

public static SQLiteConnection GetConnection()
{
return DependencyService.Get<ISql>().GetConnection();
}
}

public interface ISql
{
SQLiteConnection GetConnection();
}
then, in the android project, create a class that implements this interface and uses the Dependency attribute and connects to the sqlite database.
 
ok how to refer dependency dll into the project?
 
In the android project you need to create a class with the following logic:
[assembly: Xamarin.Forms.Dependency(typeof(Sql_Android))]

namespace AndroidProject.Droid
{
public class Sql_Android: Java.Lang.Object, ISql
{

public SQLiteConnection GetConnection()
{
var sqliteFilename = "yourdb.db3";
dbFolderPath = .... create the directory for your db
var path = Path.Combine(dbFolderPath, sqliteFilename);
var conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(), path);
You don't need to reference the dependency dll because it is contained in your Xamarin.Android project in the same solution. The dependency service knows to search for the right implementation and you will get it in your PCL project.
 
can I know what is the namespace for dependency attribute?
 
2:41 PM
Xamarin.Forms
 
yeah got it
 
The following link is exactly what you need:
https://developer.xamarin.com/guides/xamarin-forms/working-with/databases/#PCL_Android
 
thanks buddy.. :-)
 
3:01 PM
No problem. Will appriciate marking the answer as correct if it was so :)
 
just a question
in
[assembly: Xamarin.Forms.Dependency(typeof(Sql_Android))]
what will be the 'Sql_Android' ?
is it namespace or project assembly?
 
It is the name of the class in the Android project that implements the interface. In the above example, the Sql_Android implements the ISql interface.
 
can you communicate from other source.. like skype or team viewer. my project is created total mess.. please
help me
 
3:18 PM
I am sorry but I have to go.
Just try following the last link I sent you:
https://developer.xamarin.com/guides/xamarin-forms/working-with/databases/#PCL_Android
 

last day (14 days later) »