• SQLite4Unity3d安卓 在手机上创建sqlite失败解决


    总结

    要在Unity上运行一次出现库,再打包进APK内

    问题

    使用示例代码的创建库 

    1. var dbPath = string.Format(@"Assets/StreamingAssets/{0}", DatabaseName);
    2. #else
    3. // check if file exists in Application.persistentDataPath
    4. var filepath = string.Format("{0}/{1}", Application.persistentDataPath, DatabaseName);
    5. if (!File.Exists(filepath))
    6. {
    7. Debug.Log("Database not in Persistent path");
    8. // if it doesn't ->
    9. // open StreamingAssets directory and load the db ->
    10. #if UNITY_ANDROID
    11. var loadDb = new WWW("jar:file://" + Application.dataPath + "!/assets/" + DatabaseName); // this is the path to your StreamingAssets in android
    12. while (!loadDb.isDone) { } // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check
    13. // then save to Application.persistentDataPath
    14. File.WriteAllBytes(filepath, loadDb.bytes);
    15. #elif UNITY_IOS
    16. var loadDb = Application.dataPath + "/Raw/" + DatabaseName; // this is the path to your StreamingAssets in iOS
    17. // then save to Application.persistentDataPath
    18. File.Copy(loadDb, filepath);
    19. #elif UNITY_WP8
    20. var loadDb = Application.dataPath + "/StreamingAssets/" + DatabaseName; // this is the path to your StreamingAssets in iOS
    21. // then save to Application.persistentDataPath
    22. File.Copy(loadDb, filepath);
    23. #elif UNITY_WINRT
    24. var loadDb = Application.dataPath + "/StreamingAssets/" + DatabaseName; // this is the path to your StreamingAssets in iOS
    25. // then save to Application.persistentDataPath
    26. File.Copy(loadDb, filepath);
    27. #elif UNITY_STANDALONE_OSX
    28. var loadDb = Application.dataPath + "/Resources/Data/StreamingAssets/" + DatabaseName; // this is the path to your StreamingAssets in iOS
    29. // then save to Application.persistentDataPath
    30. File.Copy(loadDb, filepath);
    31. #else
    32. var loadDb = Application.dataPath + "/StreamingAssets/" + DatabaseName; // this is the path to your StreamingAssets in iOS
    33. // then save to Application.persistentDataPath
    34. File.Copy(loadDb, filepath);
    35. #endif
    36. Debug.Log("Database written");
    37. }
    38. var dbPath = filepath;
    39. #endif
    40. connectionSQL = new SQLiteConnection(dbPath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);
    41. Debug.Log("Final PATH: " + dbPath);

    去到指定位置发现库创建失败,或者说没有这个库 

     

    此时无库 

     

    解决

    点击运行后 

    等待5秒左右,出现库,关停程序

    再次打包,导入

    库出现了!

  • 相关阅读:
    加速度速度位移的计算
    ES6新特性
    【花书笔记|PyTorch版】手动学深度学习6:多层感知机
    我也是醉了,Eureka 延迟注册还有这个坑!
    Midjourney竞品Leap免费试用; Google 刚刚发布10门独立AI课程
    leetcode:2478. 完美分割的方案数【预处理 + dp定义 + 前缀和优化】
    mysql中binlog日志
    NetHTTPClient访问https网站出错。
    解决transform带来的z-index失效问题
    SpringSecurity
  • 原文地址:https://blog.csdn.net/weixin_56537692/article/details/133825265