实体框架核心无法在Android三星设备

时间:2017-03-13 10:11:38

标签: android entity-framework xamarin.android

我们有一个用xamarin编写的应用程序,用于使用Entity Framework Core的android。它适用于我们的测试设备,包括Wiko(Android 6.0),HTC(Android 7.1)和Sony(6.0)。但在三星设备(6.0)上,我们在启动时遇到以下异常:

Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1294: 'unable to open database file'.

完成例外:

    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    ... 1 more
Caused by: android.runtime.JavaProxyThrowable: Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1294: 'unable to open database file'.
  at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists () [0x00000] in <f97b8874924247a39fca91e98b024cf6>:0 
  at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate (System.String targetMigration) [0x00030] in <f97b8874924247a39fca91e98b024cf6>:0 
  at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate (Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade) [0x00010] in <f97b8874924247a39fca91e98b024cf6>:0 
  at FriendsAppDate.Business.AppStart.Start (System.Object hint) [0x0001b] in <c1a86397b9cc451297593cc8cc1289f7>:0 
  at MvvmCross.Droid.Views.MvxSplashScreenActivity.TriggerFirstNavigate () [0x00005] in <f6aebf863dc84be7b380cfec8d459508>:0 
  at MvvmCross.Droid.Views.MvxSplashScreenActivity.InitializationComplete () [0x00009] in <f6aebf863dc84be7b380cfec8d459508>:0 
  at MvvmCross.Droid.Platform.MvxAndroidSetupSingleton.InitializeFromSplashScreen (MvvmCross.Droid.Views.IMvxAndroidSplashScreenActivity splashScreen) [0x00029] in <f6aebf863dc84be7b380cfec8d459508>:0 
  at MvvmCross.Droid.Views.MvxSplashScreenActivity.OnResume () [0x00018] in <f6aebf863dc84be7b380cfec8d459508>:0 
  at Android.App.Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <fca2c02347db4086aed81b5475a315fd>:0 
  at (wrapper dynamic-method) System.Object:b336e942-d75d-4699-a108-3115233929aa (intptr,intptr)
    at mvvmcross.droid.views.MvxSplashScreenActivity.n_onResume(Native Method)
    at mvvmcross.droid.views.MvxSplashScreenActivity.onResume(MvxSplashScreenActivity.java:39)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1286)
    at android.app.Activity.performResume(Activity.java:6987)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4144)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4245)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1838)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7224)
    ... 3 more

我通过以下方式获取数据库路径:

Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), Constants.DB_NAME);

并且在所有设备上都是一样的。

/data/user/0/[AppID]/files/[DbName]

我们使用当前版本的Entity Framework Core 1.1.1 这可能有什么问题?

1 个答案:

答案 0 :(得分:0)

这是在三星设备上实施SQLite的问题,应该用2.0修复。 EF团队在这个问题上有一个解决方法。见这里:https://github.com/aspnet/EntityFramework/issues/7870

另外,对我们有用的是创建db over raw SQL语句。 SQlite数据库浏览器会生成它们,因此您只需复制并粘贴它们即可。