问题描述
我将我的应用程序的只读数据库包含在资产/数据库目录中。所有数据都是事先预先填充的。
I ship a read only database with my app including it in Assets/Database directory. All data is pre-populated beforehand.
与 SQLCipher
集成并加密数据库后,我发现APK的大小从25MB扩大到150MB 。原因是SQLite 数据库文件不再被压缩。
After integrating with SQLCipher
and encrypting the database I noticed that the APK size ballooned from 25MB to 150MB. Reason being is that the SQLite db file no longer gets compressed.
Android Studio通常会压缩资源,但在DB文件被加密后,它似乎被压缩该文件没有任何效果。我试图用外部的常规Zip& 7Zip和它没有区别,压缩文件的大小与原来一样。
Android Studio normally will compress resources but after DB file is encrypted it seems zipping the file has no effect. I tried testing this outside with regular Zip & 7Zip and it makes no difference, zipped file is the same size as the original.
未加密的数据库大约为130MB,压缩后只需18MB,因为大部分文本和字符串拉链很好。压缩加密的数据库文件在大小上没有任何区别。
Un-encrypted database is around 130MB and when zipped takes only 18MB as most of it is text and strings zip very well. Zipping encrypted db file makes no difference in size.
通过服务器填充不是一个可行的选项,因为记录的数量将永远占用。从服务器下载完整的加密数据库文件是下一个选项,但是对于140MB的文件来说仍然需要太慢。
Populating via server isn't a viable option as it would take forever due to amount of records. Downloading a full encrypted DB file from the server is the next option but it would still take too slow with a 140MB file.
需要找到一种将加密数据库与该应用程序仍然将应用程序大小保持为合理的20-30MB 。
Need to find an approach to ship encrypted DB with the app while still keeping the app size to a reasonable 20-30MB.
任何想法?
谢谢。
推荐答案
压缩需要在数据中找到模式。
加密删除所有这些模式。
Compression requires finding patterns in the data.Encryption removes all such patterns.
您需要在加密之前进行压缩。
这不可能与SQLCipher;您必须运送压缩和加密的.sql文件,然后在新的加密数据库上执行。
You need to do the compression before the encryption.This is not possible with SQLCipher; you'd have to ship a compressed and encrypted .sql file, and then execute it on a new, encrypted database.
这篇关于使用SQLCipher加密后,无法将Android SQLite数据库压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!