总结
要在Unity上运行一次出现库,再打包进APK内
问题
使用示例代码的创建库
var dbPath = string.Format(@"Assets/StreamingAssets/{0}", DatabaseName);
#else// check if file exists in Application.persistentDataPathvar filepath = string.Format("{0}/{1}", Application.persistentDataPath, DatabaseName);if (!File.Exists(filepath)){Debug.Log("Database not in Persistent path");// if it doesn't ->// open StreamingAssets directory and load the db ->#if UNITY_ANDROIDvar loadDb = new WWW("jar:file://" + Application.dataPath + "!/assets/" + DatabaseName); // this is the path to your StreamingAssets in androidwhile (!loadDb.isDone) { } // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check// then save to Application.persistentDataPathFile.WriteAllBytes(filepath, loadDb.bytes);
#elif UNITY_IOSvar loadDb = Application.dataPath + "/Raw/" + DatabaseName; // this is the path to your StreamingAssets in iOS// then save to Application.persistentDataPathFile.Copy(loadDb, filepath);
#elif UNITY_WP8var loadDb = Application.dataPath + "/StreamingAssets/" + DatabaseName; // this is the path to your StreamingAssets in iOS// then save to Application.persistentDataPathFile.Copy(loadDb, filepath);#elif UNITY_WINRTvar loadDb = Application.dataPath + "/StreamingAssets/" + DatabaseName; // this is the path to your StreamingAssets in iOS// then save to Application.persistentDataPathFile.Copy(loadDb, filepath);#elif UNITY_STANDALONE_OSXvar loadDb = Application.dataPath + "/Resources/Data/StreamingAssets/" + DatabaseName; // this is the path to your StreamingAssets in iOS// then save to Application.persistentDataPathFile.Copy(loadDb, filepath);
#elsevar loadDb = Application.dataPath + "/StreamingAssets/" + DatabaseName; // this is the path to your StreamingAssets in iOS// then save to Application.persistentDataPathFile.Copy(loadDb, filepath);#endifDebug.Log("Database written");}var dbPath = filepath;
#endifconnectionSQL = new SQLiteConnection(dbPath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);Debug.Log("Final PATH: " + dbPath);
去到指定位置发现库创建失败,或者说没有这个库
此时无库
解决
点击运行后
等待5秒左右,出现库,关停程序
再次打包,导入
库出现了!