Omar Rodriguez Omar Rodriguez - 1 year ago 105
Android Question

How do I share a sqlite database between a Xamarin app and Java Android app

As the title says I am wanting to share a Sqlite database between an Android app written in Java and one written in C# using Xamarin. I can successfully share a database between two Java apps (With the help of this question) but when I try the same thing in Xamarin I am getting the following error:

Android.Database.Sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database

I think I have two problems.

  1. I am not correctly setting the Shared UserId. Currently I am placing the following attribute above my main activity.


    I tried using the
    in the Manifest file but that was throwing errors and wouldn't deploy to my device.

  2. I don't know how the whole signing of the app works. So maybe my device sees the two apps as coming from a different publisher for each device and is not allowing the two to share context.


Just wanted to add how I signed both applications with the same certificate for future refrence.

The Android cert is noramlly
and the Xamarin cert is noramlly in
"C:\Users\userName\AppData\Local\Xamarin\Mono for Android\debug.keystore"
. I built the Xamarin app first so I copied the debug.keystore file from the xamarin folder to the android one. (I'm sure it would work the other way around but haven't tested it)

Answer Source

Xamarin.Android does not support SharedUserId via an ApplicationAttribute. (I guess no one every filed an issue about it)

Ref: Android.App.ApplicationAttribute

Add your shared user id via the manifest and it will work fine:


<application android:allowBackup="true" android:sharedUserId="com.sushihangover" android:icon="@mipmap/icon" android:label="@string/app_name"></application>

Note: Make sure that you manually uninstall both apps, add the sharedUserId, rebuild and reinstall both apps.

Note: Make sure that you are using the same signing certificate for both your Java and Xamarin apps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download