这里只讲tinker命令行方式接入的一些操作和问题,tinker请查看:
tinker:https://github.com/Tencent/tinker/wiki/Tinker-%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97
cli:tinker-patch-cli-1.9.2.jar
下载:https://pan.baidu.com/s/1kW2p55P
cli使用:
java -jar tinker-patch-cli-1.9.2.jar -old ./xxx_signed.apk -new ./xxx_signed.apk -config tinker_config.xml -out out/
tinker_config.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!--command version is not recommended, you must add the tinker proguard file and multiDex keep file yourself-->
<!--further, you must put TINKER_ID in your your AndroidManifest.xml such as <meta-data android:name="TINKER_ID" android:value="b168b32"/>-->
<!--and you'd better use applymapping to build the patch apk-->
<tinkerPatch>
<issue id="property">
<!--there are some cases we may get some warnings, default false-->
<!--if ignoreWarning is true, we would just assert the patch process-->
<!--case 1: minSdkVersion is below 14, but you are using dexMode with raw.-->
<!--it must be crash when load.-->
<!--case 2: newly added Android Component in AndroidManifest.xml,-->
<!--it must be crash when load.-->
<!--case 3: loader classes in dex.loader{} are not keep in the main dex,-->
<!--it must be let tinker not work.-->
<!--case 4: loader classes in dex.loader{} changes,-->
<!--loader classes is ues to load patch dex. it is useless to change them.-->
<!--it won't crash, but these changes can't effect. you may ignore it-->
<ignoreWarning value="false"/>
<!--whether sign the patch file default true-->
<!--if not, you must do yourself. otherwise it can't check success during the patch loading-->
<!--we will use the sign config with your build type-->
<useSign value="true"/>
<!--if you don't set sevenZip path, we just use 7za to try-->
<sevenZipPath value="/usr/bin/7za"/>
<!--Whether tinker should treat the base apk as the one being protected by app-->
<!--protection tools.-->
<!--If this attribute is true, the generated patch package will contain a-->
<!--dex including all changed classes instead of any dexdiff patch-info files.-->
<isProtectedApp value="false"/>
<!--Whether tinker should support component hotplug (add new component dynamically).-->
<!--If this attribute is true, the component added in new apk will be available after-->
<!--patch is successfully loaded. Otherwise an error would be announced when generating patch-->
<!--on compile-time.-->
<!---->
<!--Notice that currently this feature is incubating and only support NON-EXPORTED Activity-->
<supportHotplugComponent value="false"/>
</issue>
<issue id="dex">
<!--only can be 'raw' or 'jar'. for raw, we would keep its original format-->
<!--for jar, we would repack dexes with zip format.-->
<!--if you want to support below 14, you must use jar-->
<!--or you want to save rom or check quicker, you can use raw mode also-->
<dexMode value="jar"/>
<!--what dexes in apk are expected to deal with tinkerPatch-->
<!--it support * or ? pattern.-->
<pattern value="classes*.dex"/>
<pattern value="assets/secondary-dex-?.jar"/>
<!--Warning, it is very very important, loader classes can't change with patch.-->
<!--thus, they will be removed from patch dexes.-->
<!--you must put the following class into main dex.-->
<!--Simply, you should add your own application {@code tinker.sample.android.SampleApplication}-->
<!--own tinkerLoader {@code SampleTinkerLoader}, and the classes you use in them-->
<loader value="com.tencent.tinker.loader.*"/>
<loader value="tinker.sample.android.SampleApplication"/>
</issue>
<issue id="lib">
<!--what library in apk are expected to deal with tinkerPatch-->
<!--it support * or ? pattern.-->
<!--for library in assets, we would just recover them in the patch directory-->
<!--you can get them in TinkerLoadResult with Tinker-->
<pattern value="lib/*/*.so"/>
</issue>
<issue id="resource">
<!--what resource in apk are expected to deal with tinkerPatch-->
<!--it support * or ? pattern.-->
<!--you must include all your resources in apk here-->
<!--otherwise, they won't repack in the new apk resources-->
<pattern value="res/*"/>
<pattern value="assets/*"/>
<pattern value="resources.arsc"/>
<pattern value="AndroidManifest.xml"/>
<!--ignore add, delete or modify resource change-->
<!--Warning, we can only use for files no relative with resources.arsc, such as assets files-->
<!--it support * or ? pattern.-->
<!--Such as I want assets/meta.txt use the base.apk version whatever it is change ir not.-->
<ignoreChange value="assets/sample_meta.txt"/>
<!--default 100kb-->
<!--for modify resource, if it is larger than 'largeModSize'-->
<!--we would like to use bsdiff algorithm to reduce patch file size-->
<largeModSize value="100"/>
</issue>
<issue id="packageConfig">
<!--package meta file gen. path is assets/package_meta.txt in patch file-->
<!--you can use securityCheck.getPackageProperties() in your ownPackageCheck method-->
<!--or TinkerLoadResult.getPackageConfigByName-->
<!--you must add TINKER_ID with the old apk manifest's meta TINKER_ID value-->
<!--other config files (such as patchMessage below)is not necessary-->
<!--For sample project or any projects that copy SamplePatchListener directory,-->
<!--platform config field is necessary, or an error code ERROR_PATCH_CONDITION_NOT_SATISFIED(-10)-->
<!--will be thrown.-->
<configField name="platform" value="all"/>
<configField name="patchMessage" value="classes.dex"/>
</issue>
<!--sign, if you want to sign the apk, and if you want to use 7zip, you must fill in the following data-->
<issue id="sign">
<!--the signature file path, in window use \, in linux use /, and the default path is the running location-->
<path value="keystore/xxx.jks"/>
<!--storepass-->
<storepass value="xxxx"/>
<!--keypass-->
<keypass value="xxxx"/>
<!--alias-->
<alias value="xxxx"/>
</issue>
</tinkerPatch>
1.需要修改的地方:文件最末尾的sing块,修改为自己的证书相关信息.
2.如果7za没有在系统中安装,需要先安装,否则无法打7zip包.
apt install p7zip-full
安装后查看7za文件位置,再修改配置中sevenZipPath指定的位置.
3.如果涉及到代码混淆,multidex等问题,请参考tinker-build项目中的文件.