Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangjingbo committed Jun 29, 2018
1 parent 9e37cb7 commit 44342c4
Show file tree
Hide file tree
Showing 497 changed files with 90,408 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
@@ -0,0 +1,7 @@
*.iml
.gradle
/local.properties
/.idea
.DS_Store
/build
../.DS_Store
209 changes: 209 additions & 0 deletions LICENSE
@@ -0,0 +1,209 @@
Copyright (c) 2018-present, iQIYI, Inc. All rights reserved.

Most source code in dexSplitter are MIT licensed. Some other source code
have Apache License licenses.

A copy of the MIT License is included in this file.

Source code Licensed under the Apache License
===================================================
com.android.*

Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS



Terms of the MIT License
========================

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
65 changes: 64 additions & 1 deletion README.md
@@ -1 +1,64 @@
# dexSplitter
# DexSplitter Solution
As we all know, Google has provided aapt plugin for parsing apk, we can get a list of apk files by using 'aapt l -v '.
We can divide each res file(assets file) into the module project which it belongs to.
But source code of the project can not be divided directly because it will be shrinked optimized and obfuscated.
DexSplitter can help you to divide source code.

[中文文档](/README_CHINESE.md)


# Scenarios
+ Analyze contribution rate of each module to the apk size
+ Diff the size of each module in the apk for every sprint


# Apk Split Result


> #### Android Origin Build Release.apk
> ![SplitDexApk](res/apk_origin_parse.png)
> #### DexSplitter Build Release.apk
> ![SplitDexApk](res/dex_splitter_with_name.png)
> #### splitter_result.txt
> ![SplitDexApk](res/parse_result.png )
> ps:more details:extra/hack_description.txt extra/hook_details.txt
# Demo Introduction
+ The most important purpose of dexSplitter is to build apk which has special dex files
+ You can use extra/dx.jar directly
+ Host app(lib:gson), library module moduleone(lib:GreenDAO), library module moduletwo(lib:universalimageloader)
+ subdexeslist.txt is used for splitting dex, TestClassForMainDex.class is just a test file
+ Third libs will not be obfuscated
+ Android Support library is marked as android_sys
+ subdexeslist.txt should not contain duplicated class files


# Schematic Diagram
![SplitDexApk](res/dex_hack_english.png)


# Implementation

+ Divide the dex files with class files
+ Build apk which has special dex files
+ Python files for collecting class files
+ Obfuscated class list for release version


# Future

+ Signed apk
+ Generate tables about the proportion of module projects
+ Parse changes of dex files by comparing different apk versions
+ Divide the dex files by author, module etc.


# License
+ Copyright (c) 2018-present, iQIYI, Inc. All rights reserved.
Most source code in dexSplitter are MIT licensed. Some other source code have Apache licenses.
Please refer to the LICENSE file for detailed information.



80 changes: 80 additions & 0 deletions README_CHINESE.md
@@ -0,0 +1,80 @@
# 项目简介
为严控apk体积增长,需要精确量化apk中各模块占比大小。针对res文件、so文件(assets)等,Google提供了AAPT套件,通过脚本,可解压分析出各部分大小。
针对源码部分,混淆过的class文件,因经过合并,压缩等操作生成最终dex文件,无法直接分析各模块占比。
dexSplitter 主要针对源码部分,提供了一套彻底的分析APK dex组成的解决方案。

# 应用场景

+ 分析apk包体积各模块贡献率
+ 跟踪版本迭代时,包体积各部分变动量,及变化趋势
+ 详细监控各模块内各子模块占比情况


# Android原生Apk组成

+ apk中dex部分,无法衡量各业务占比情况

> #### 正常生成的apk组成
>![SplitDexApk](res/apk_origin_parse.png)
# dexSplitter方案生成Apk
+ apk中dex部分,可以精确测算各业务占比,辅以python脚本可得出各业务总体占比情况

> #### 最终Apk
> ![SplitDexApk](res/dex_splitter_with_name.png)
> #### 分析结果
> ![SplitDexApk](res/parse_result.png )
> ps:more details:extra/hack_description.txt
# Demo 示例说明:
+ dexSpliter工程,打包生成带有dex分组属性的apk,可认为dex分拆方案已完成。附带的python apk分析脚本,简单划分了module资源文件,仅供参考。
+ extra/dx.jar 为编译好的dx文件,可用来替换系统dx.jar
+ 主工程app(示例lib 为gson),library module moduleone(示例lib为GreenDAO),library module moduletwo( 示例lib为universalimageloader)
+ 实际分组文件为subdexeslist.txt, maindexlist.txt为系统必须文件,无实质内容,增加的测试文件TestClassForMainDex.class(用来绕过系统检查)
+ 为便于对比验证,第三方库未参与混淆
+ dex占比划分中,Android Support库作为独立库(android_sys)示例,单独划分
+ 未明确划分的代码,会被打进unkown.dex
+ subdexeslist.txt为真实apk包含的最终class,不应出现重复类,否则会导致打包错误


# hack的基本原理示意图
![SplitDexApk](res/dex_hack.png)


+ dx.jar编译源码地址: https://android.googlesource.com/platform/dalvik demo基于26.0.2
+ android gradle源码地址:https://android.googlesource.com/platform/tools/base
+ 干预dex生成过程,按需生成dex文件,并对其按模块命名。com.android.dx.command.dexer.Main.java
+ 干预gradle插件packaging阶段重命名过程,使其保持模块命名。com.android.builder.internal.packaging.DexIncrementalRenameManager.java

# SplitDexAPK已支持的功能:

+ 支持class粒度级别拆分各业务模块源码;
+ 支持按需输出apk文件,源码部分占比可直接展示
+ 可定制化脚本,自动收集生成各模块源码文件
+ 支持Release版本,混淆文件分拆分拣
+ 可按工程模块,业务模块等各种维度进行占比分析


# 实际应用:

+ 持续监控IQIYI客户端多个版本apk体积变化,详细分解了如泡泡,基线,播放器,支付模块等业务模块,按照代码与资源相对apk整体贡献比每月出具量化报告。<br>
为科学量化与严格监控客户端包体积变化提供了有效数据支撑。


# 后续扩展

+ demo仅做演示,未增加签名处理,可通过签名文件处理,得到最终版本apk文件
+ 结合aapt分析res,assets目录文件等,可得出综合模块apk贡献率统计表
+ 脚本部署后,可定期跟踪包体积各部分变动量,及变化趋势
+ 可结合git提交记录等,按业务模块,提交作者,工程模块等各种维度进行占比分析


# License
+
Copyright (c) 2018-present, 爱奇艺, Inc. All rights reserved.
dexSplitter中大多数的源码使用 MIT 许可证,另外的一些源码使用 Apache 样式的许可证。
详细信息请查看 LICENSE 文件。


2 changes: 2 additions & 0 deletions app/.gitignore
@@ -0,0 +1,2 @@
/build
*.iml

0 comments on commit 44342c4

Please sign in to comment.