• 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秒左右,出现库,关停程序

    再次打包,导入

    库出现了!

  • 相关阅读:
    ApachePulsar原理解析与应用实践(学习笔记一)
    Linux aarch64交叉编译之 qlibc 基础C/C++库
    加权平均数
    揭秘神秘的种子:Adobe联合宾夕法尼亚大学发布文本到图像扩散模型大规模种子分析
    转换罗马数字
    内网渗透之内网信息收集(综合)
    会话技术——cookie
    南昌云宸网络发展有限公司-小分类客户可自选
    CRMEB多端多语言系统文件上传0Day代审历程
    leetcode经典面试150题---5.多数元素
  • 原文地址:https://blog.csdn.net/weixin_56537692/article/details/133825265