mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Moved customapp embedded android ZIMs from lib to assets directory
Avoids duplicate embedded ZIMs for each CPU architecture:
This commit is contained in:
parent
ef9afffcae
commit
fbed97fa10
@ -334,25 +334,6 @@ def step_update_xml_nodes(jsdata, **options):
|
||||
flushxml(soup, 'RelativeLayout', toolbar_xml, head=False)
|
||||
|
||||
|
||||
def step_update_gradle(jsdata, **options):
|
||||
''' uncomment compiling the content-libs.jar file into the APK '''
|
||||
|
||||
if not jsdata.get('embed_zim'):
|
||||
return
|
||||
|
||||
move_to_android_placeholder()
|
||||
|
||||
# rename settings.SliderPreference node in res/xml/preferences.xml
|
||||
fpath = os.path.join(ANDROID_PATH, 'build.gradle')
|
||||
lines = open(fpath, 'r').readlines()
|
||||
for idx, line in enumerate(lines):
|
||||
if 'content-libs.jar' in line:
|
||||
lines[idx] = (" {}\n"
|
||||
.format(re.sub(r'^//', '', line.strip()).strip()))
|
||||
with open(fpath, 'w') as f:
|
||||
f.write(''.join(lines))
|
||||
|
||||
|
||||
def step_update_android_manifest(jsdata, **options):
|
||||
''' update AndroidManifest.xml to set package, name, version
|
||||
|
||||
@ -446,23 +427,8 @@ def step_embed_zimfile(jsdata, **options):
|
||||
|
||||
move_to_android_placeholder()
|
||||
|
||||
# create content-libs.jar
|
||||
tmpd = tempfile.mkdtemp()
|
||||
archs = os.listdir('libs')
|
||||
for arch in archs:
|
||||
os.makedirs(os.path.join(tmpd, 'lib', arch))
|
||||
# shutil.copy(os.path.join('libs', arch, 'libkiwix.so'),
|
||||
# os.path.join(tmpd, 'lib', arch, 'libkiwix.so'))
|
||||
copy_to(jsdata.get('zim_file'),
|
||||
os.path.join(tmpd, 'lib', archs[0], jsdata.get('zim_name')))
|
||||
for arch in archs[1:]:
|
||||
os.chdir(os.path.join(tmpd, 'lib', arch))
|
||||
os.link('../{}/{}'.format(archs[0], jsdata.get('zim_name')),
|
||||
jsdata.get('zim_name'))
|
||||
os.chdir(tmpd)
|
||||
syscall('zip -r -0 -y {} lib'
|
||||
.format(os.path.join(ANDROID_PATH, 'content-libs.jar')))
|
||||
shutil.rmtree(tmpd)
|
||||
os.path.join('assets', jsdata.get('zim_name')))
|
||||
|
||||
def step_build_apk(jsdata, **options):
|
||||
''' build the actual APK '''
|
||||
@ -524,7 +490,6 @@ ARGS_MATRIX = OrderedDict([
|
||||
('jni', step_update_kiwix_c),
|
||||
('libkiwix', step_compile_libkiwix),
|
||||
('embed', step_embed_zimfile),
|
||||
('gradle', step_update_gradle),
|
||||
('build', step_build_apk),
|
||||
('move', step_move_apk_to_destination),
|
||||
('list', step_list_output_apk),
|
||||
@ -576,7 +541,7 @@ def main(jspath, **options):
|
||||
jsdata.update({'zim_size': str(get_file_size(jsdata.get('zim_file')))})
|
||||
jsdata.update({'zim_name': zim_name_from_path(jsdata.get('zim_file'))})
|
||||
if jsdata.get('embed_zim'):
|
||||
jsdata.update({'zim_name': 'libcontent.so'})
|
||||
jsdata.update({'zim_name': 'content.zim'})
|
||||
|
||||
# greetings
|
||||
logger.info("Your are now building {app_name} version {version_name} "
|
||||
|
@ -1116,7 +1116,7 @@ public class KiwixMobileActivity extends AppCompatActivity
|
||||
|
||||
String filePath;
|
||||
if (Constants.CUSTOM_APP_HAS_EMBEDDED_ZIM) {
|
||||
filePath = String.format("/data/data/%s/lib/%s", Constants.CUSTOM_APP_ID,
|
||||
filePath = String.format("/data/data/%s/files/zim/%s", Constants.CUSTOM_APP_ID,
|
||||
Constants.CUSTOM_APP_ZIM_FILE_NAME);
|
||||
} else {
|
||||
String fileName = FileUtils.getExpansionAPKFileName(true);
|
||||
|
@ -181,6 +181,33 @@ public class ZimContentProvider extends ContentProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private static String loadZIMData(Context context, File workingDir) {
|
||||
String zimFileName = "content.zim";
|
||||
try {
|
||||
File zimDir = new File(workingDir, "zim");
|
||||
if (!zimDir.exists()) {
|
||||
zimDir.mkdirs();
|
||||
}
|
||||
File zimDataFile = new File(zimDir, zimFileName);
|
||||
if (!zimDataFile.exists()) {
|
||||
InputStream in = context.getAssets().open(zimFileName);
|
||||
OutputStream out = new FileOutputStream(zimDataFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
in.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
return zimDir.getAbsolutePath();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG_KIWIX, "Error copying ZIM data file", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getFilePath(Uri articleUri) {
|
||||
String filePath = articleUri.toString();
|
||||
int pos = articleUri.toString().indexOf(CONTENT_URI.toString());
|
||||
@ -200,6 +227,7 @@ public class ZimContentProvider extends ContentProvider {
|
||||
public boolean onCreate() {
|
||||
jniKiwix = new JNIKiwix();
|
||||
setIcuDataDirectory();
|
||||
setZIMDataDirectory();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -317,6 +345,11 @@ public class ZimContentProvider extends ContentProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private void setZIMDataDirectory() {
|
||||
File workingDir = this.getContext().getFilesDir();
|
||||
loadZIMData(this.getContext(), workingDir);
|
||||
}
|
||||
|
||||
static class TransferThread extends Thread {
|
||||
|
||||
Uri articleUri;
|
||||
|
Loading…
x
Reference in New Issue
Block a user