简体   繁体   English

SQLiteAssetHelper数据库文件大小

[英]SQLiteAssetHelper database file size

I have an app that includes a pre-populated sqlite database, encoded in UTF-8. 我有一个包含以UTF-8编码的预填充sqlite数据库的应用程序。 DB file size is 170 MB. 数据库文件大小为170 MB。 I am using SQLiteAssetHelper to manage the database 我正在使用SQLiteAssetHelper来管理数据库

Considering most Android Apps are less than 50MB, it is quite large. 考虑到大多数Android应用程序小于50MB,因此它非常大。 My current app size according to the Settings is 238MB. 根据设置,我当前的应用大小为238MB。

Is there any way to make the downloadable app size smaller when user downloads it from Store? 用户从商店下载可下载应用程序时,有什么方法可以减小它的尺寸? I have read that you can zip the sqlite database, but I haven't tried that yet. 我读过您可以压缩sqlite数据库,但是我还没有尝试过。 Will that make the app's download size smaller? 这会使应用程序的下载大小变小吗? Are there any other better options? 还有其他更好的选择吗?

I am concerned about the app's download size, not the storage space. 我担心应用程序的下载大小,而不是存储空间。 I do need the app to work offline, so web service is not an option. 我确实需要该应用程序脱机工作,因此无法选择Web服务。

Is there any way to make the downloadable app size smaller when user downloads it from Store? 用户从商店下载可下载应用程序时,有什么方法可以减小它的尺寸?

Have a smaller database. 有一个较小的数据库。

Will that make the app's download size smaller? 这会使应用程序的下载大小变小吗?

Since the APK is already a ZIP file, no, as ZIPping an entry in a ZIP file will not reduce its size further. 由于APK已经是一个ZIP文件,因此不能,因为ZIP压缩ZIP文件中的条目不会进一步减小其大小。

Are there any other better options? 还有其他更好的选择吗?

You could not use SQLiteAssetHelper , and download the database on the first run of your app. 您不能使用SQLiteAssetHelper ,并且在应用程序的第一次运行时下载数据库。 Or, you could not use SQLiteAssetHelper and look into using APK expansion files. 或者,您无法使用SQLiteAssetHelper并考虑使用APK扩展文件。 Neither of those will change the number of bytes to be downloaded, but they will reduce the overall disk space your app takes up a bit. 这些都不会改变要下载的字节数,但是它们会减少应用程序占用的总磁盘空间。 You can use tools like command-line unzip to see how much space your database file is taking up in the APK (my one test app's database is 89% compressed and so takes up 568 bytes instead of the uncompressed 5120 bytes). 您可以使用命令行unzip类的工具查看数据库文件在APK中占用的空间(我的一个测试应用的数据库已压缩89%,因此占用568个字节,而不是未压缩的5120个字节)。 This space is non-recoverable, insofar as you have no way of deleting a database from assets/ . 只要您无法从assets/删除数据库,该空间就不可恢复。 Assuming a similar compression ratio, your 170MB database will take up an extra ~17MB on disk from the copy in assets/ . 假设压缩率相近,您的170MB数据库将在assets/的副本上额外占用〜17MB磁盘空间。

You could also not have the 170MB database on the device at all, and have your app work with some Web service to access a hosted copy of the database. 您也根本无法在设备上拥有170MB的数据库,并且您的应用程序可以与某些Web服务一起使用来访问数据库的托管副本。 This won't work offline, of course. 当然,这将无法离线使用。

I ended up using text files for the major lookup tables in my database. 我最终将文本文件用于数据库中的主要查找表。 I added them in the assets folder, along with the smaller sqlite db. 我将它们和较小的sqlite数据库一起添加到了Assets文件夹中。 I kept only the small tables that I needed to do inserts/adds in the sqlite db. 我只将需要插入/添加的小表保留在sqlite db中。

And I was also able to easily encrypt the data in the file (which is not easy to do in sqlite) 而且我还能够轻松加密文件中的数据(在sqlite中不容易做到)

I had to create indexes to index the file data, and used binary search to find by key or value. 我必须创建索引来索引文件数据,并使用二进制搜索按键或值查找。

That shortened the apk size, and it's about 30 MB now. 这缩短了apk的大小,现在约为30 MB。 Before it was about 76MB. 之前大约是76MB。 and the app size was > 200 MB. 并且应用程序大小> 200 MB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM