JarJar可以很方便的重新打包并封装到自己的发布中,这样做有两大好处: 便捷的创建一个无依赖的单一文件的发布 避免自身对特定版本包的依赖造成的与其它程序冲突
修改jar
添加规则rule.txt
The rules file is a text file, one rule per line. Leading and trailing whitespace is ignored. There are three types of rules:
rule zap keep
The standard rule (rule) is used to rename classes. All references to the renamed classes will also be updated. If a class name is matched by more than one rule, only the first one will apply.
is a class name with optional wildcards. ** will match against any valid class name substring. To match a single package component (by excluding . from the match), a single * may be used instead.
is a class name which can optionally reference the substrings matched by the wildcards. A numbered reference is available for every * or ** in the , starting from left to right: @1, @2, etc. A special @0 reference contains the entire matched class name.
The zap rule causes any matched class to be removed from the resulting jar file. All zap rules are processed before renaming rules.
The keep rule marks all matched classes as "roots". If any keep rules are defined all classes which are not reachable from the roots via dependency analysis are discarded when writing the output jar. This is the last step in the process, after renaming and zapping.
rule com.xxa.** com.xxb.@1
rule com.xxa.aidl.** com.xxxb.aidl.@1
修改jar字节码
rm -rf jar/xxx_new.jar
java -jar jarjar-1.4.jar process rule.txt jar/xxx.jar jar/xxx_new.jar
cp jar/xxx_new.jar ../libs/xxx_new.jar
修改xxx.aar
# mkdir -p aar/tmpDir
function rename() {
local aar_name=$1
local rule_file=$2
echo "rename aar:${aar_name}"
local tmp_dir=${aar_name}_tmp_dir
rm -rf aar/$tmp_dir
unzip aar/${aar_name}.aar -d aar/${tmp_dir}
mv aar/${tmp_dir}/classes.jar aar/${tmp_dir}/classes_old.jar
java -jar jarjar-1.4.jar process $rule_file aar/${tmp_dir}/classes_old.jar aar/$tmp_dir/classes.jar
rm -rf aar/${tmp_dir}/classes_old.jar
jar cvf aar/${aar_name}_new.aar -C aar/${tmp_dir}/ .
rm -rf aar/$tmp_dir
cp aar/${aar_name}_new.aar ../../aar/${aar_name}_new.aar
}
rename xxx aar/rule.txt
jarjar下载地址 code.google.com/archive/p/j…