Android Multichannel shell Script

Source: Internet
Author: User

Background

Multi-channel packaging This is not difficult, but in accordance with the official practice is generally to recompile apk, when the apk is very large, it will be very time-consuming, the United States has provided a solution, please click here to view the idea of the United States, before a group of students want me to write the Python code inside the shell, For a long time did not write shell also want to add a bit of proficiency, so readily agreed.

Function

Copy the APK in the specified apk folder under the working directory and create an empty file in the Meta-info directory of the new apk, named after the channel specified in Channel.txt

Code
#!/usr/bin/Bashmodel=$1Channel_file=$2# Empty file facilitates writing this empty file into the APK package as a channel file Src_empty_file='Czt.txt'# Create an empty file (created if not present)if[-e $src _empty_file]; Then    RM-I $src _empty_filefiTouch$src _empty_fileif[! $?-eq0]; ThenExit1;fi# Get all the APK source packages in the current directory Src_apks=()
If ["$model" = ""];then
File_path= "."
else File_path="./$model"
Fi
for file inch$ (CD $file _path |ls); Do if[-F $file]; Then basename$file|grep '\.apk$'&& src_apks= ("${src_apks[@]}" "$file") fi Done# Get a list of channelsif["$channel _file" =""]; ThenChannel_file='Channel.txt' fiF=$(Cat$channel _file)functioncopy () {if[!-E $1]; Thenreturn1 fi CP$1$2} forsrc_apkinch${src_apks[@]}; Do # filename (with extension) Src_apk_file_name=$(basename$src _apk) # split file name and suffix src_apk_name=${src_apk_file_name%. apk} # Suffix name, contains. For example:". apk"src_apk_extension=${src_apk_file_name##*.} # Create a build directory, associated with file name Output_dir='output-'${src_apk_name}/if[-e $output _dir]; Then RM-R $output _dirfi mkdir-P $output _dir # traverse the channel number and create the APK file corresponding to the channel number forLineinch$f; DoTarget_channel=$line target_apk=${output_dir}${src_apk_name}-${target_channel}${src_apk_extension}Echo "${output_dir}=======>${src_apk_name}=======>, ${target_channel} =======>, ${src_apk_extension} ===== ==>"# Copy to create a new apkCP$src _apk $target _apk # Initialize channel information Empty_channel_file="Meta-inf/cztchannel_${target_channel}"# write Channel informationif[!-E $ (dirname$empty _channel_file)]; Then mkdir-P $ (dirname$empty _channel_file)fi Touch$empty _channel_file Jar-UVF $target _apk-C. $empty _channel_file Done Done

Android Multichannel shell Script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.