content-libs.jar now only created and added to APK for custom builds. Also adapted to new menu resource file name

This commit is contained in:
renaud gaudin 2015-06-06 18:38:29 +02:00
parent cdac651791
commit bc157a4f6d
3 changed files with 43 additions and 31 deletions

View File

@ -542,17 +542,6 @@ for arch in ARCHS:
'arch_short': arch_short, 'arch_short': arch_short,
'curdir': curdir}) 'curdir': curdir})
if COMPILE_LIBKIWIX:
# create content-libs.jar
tmpd = tempfile.mkdtemp()
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'))
os.chdir(tmpd)
syscall('zip -r -0 -y {} lib'
.format(os.path.join(curdir, 'content-libs.jar')))
os.chdir(curdir) os.chdir(curdir)
change_env(ORIGINAL_ENVIRON) change_env(ORIGINAL_ENVIRON)

View File

@ -21,7 +21,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:22.2.0' compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0' compile 'com.android.support:support-v4:22.2.0'
compile files("$buildDir/native-libs/native-libs.jar") compile files("$buildDir/native-libs/native-libs.jar")
//compile fileTree(dir: '.', include: 'content-libs.jar') // compile fileTree(dir: '.', include: 'content-libs.jar') // DO NOT REMOVE !!
} }
android { android {

View File

@ -286,7 +286,7 @@ def step_update_main_menu_xml(jsdata, **options):
move_to_android_placeholder() move_to_android_placeholder()
# Parse and edit res/menu/main.xml # Parse and edit res/menu/main.xml
menu_xml = os.path.join(ANDROID_PATH, 'res', 'menu', 'main.xml') menu_xml = os.path.join(ANDROID_PATH, 'res', 'menu', 'menu_main.xml')
soup = soup = BeautifulSoup(open(menu_xml, 'r'), soup = soup = BeautifulSoup(open(menu_xml, 'r'),
'xml', from_encoding='utf-8') 'xml', from_encoding='utf-8')
for elem in soup.findAll('item'): for elem in soup.findAll('item'):
@ -311,6 +311,25 @@ def step_update_preferences_xml(jsdata, **options):
flushxml(soup, 'PreferenceScreen', preferences_xml, head=False) flushxml(soup, 'PreferenceScreen', preferences_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): def step_update_android_manifest(jsdata, **options):
''' update AndroidManifest.xml to set package, name, version ''' update AndroidManifest.xml to set package, name, version
@ -392,26 +411,27 @@ def step_compile_libkiwix(jsdata, **options):
def step_embed_zimfile(jsdata, **options): def step_embed_zimfile(jsdata, **options):
''' prepare a content-libs.jar file with ZIM file for inclusion in APK ''' ''' prepare a content-libs.jar file with ZIM file for inclusion in APK '''
if not jsdata.get('embed_zim'):
return
move_to_android_placeholder() move_to_android_placeholder()
if jsdata.get('embed_zim'): # create content-libs.jar
# create content-libs.jar tmpd = tempfile.mkdtemp()
tmpd = tempfile.mkdtemp() archs = os.listdir('libs')
archs = os.listdir('libs') for arch in archs:
for arch in archs: os.makedirs(os.path.join(tmpd, 'lib', arch))
os.makedirs(os.path.join(tmpd, 'lib', arch)) # shutil.copy(os.path.join('libs', arch, 'libkiwix.so'),
# shutil.copy(os.path.join('libs', arch, 'libkiwix.so'), # os.path.join(tmpd, 'lib', arch, 'libkiwix.so'))
# os.path.join(tmpd, 'lib', arch, 'libkiwix.so')) copy_to(jsdata.get('zim_file'),
copy_to(jsdata.get('zim_file'), os.path.join(tmpd, 'lib', archs[0], jsdata.get('zim_name')))
os.path.join(tmpd, 'lib', archs[0], jsdata.get('zim_name'))) for arch in archs[1:]:
for arch in archs[1:]: os.chdir(os.path.join(tmpd, 'lib', arch))
os.chdir(os.path.join(tmpd, 'lib', arch)) os.symlink('../{}/{}'.format(archs[0], jsdata.get('zim_name')),
os.symlink('../{}/{}'.format(archs[0], jsdata.get('zim_name')), jsdata.get('zim_name'))
jsdata.get('zim_name')) os.chdir(tmpd)
os.chdir(tmpd) syscall('zip -r -0 -y {} lib'
syscall('zip -r -0 -y {} lib' .format(os.path.join(ANDROID_PATH, 'content-libs.jar')))
.format(os.path.join(ANDROID_PATH, 'content-libs.jar')))
os.chdir(ANDROID_PATH)
def step_build_apk(jsdata, **options): def step_build_apk(jsdata, **options):
@ -474,6 +494,7 @@ ARGS_MATRIX = OrderedDict([
('jni', step_update_kiwix_c), ('jni', step_update_kiwix_c),
('libkiwix', step_compile_libkiwix), ('libkiwix', step_compile_libkiwix),
('embed', step_embed_zimfile), ('embed', step_embed_zimfile),
('gradle', step_update_gradle),
('build', step_build_apk), ('build', step_build_apk),
('move', step_move_apk_to_destination), ('move', step_move_apk_to_destination),
('clean', step_remove_android_placeholder), ('clean', step_remove_android_placeholder),
@ -538,7 +559,9 @@ def main(jspath, **options):
# loop through each step and execute if requested by command line # loop through each step and execute if requested by command line
for step_name, step_func in ARGS_MATRIX.items(): for step_name, step_func in ARGS_MATRIX.items():
if options.get('do_{}'.format(step_name), False): if options.get('do_{}'.format(step_name), False):
move_to_android_placeholder()
step_func(jsdata, **options) step_func(jsdata, **options)
move_to_current_folder()
if __name__ == '__main__': if __name__ == '__main__':