Skip to content

Commit 5ca27f0

Browse files
author
tangxiaolv
committed
init
1 parent 3eff457 commit 5ca27f0

File tree

65 files changed

+2439
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2439
-0
lines changed

DexKnifePlugin/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.gradle
2+
*.iml
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures

DexKnifePlugin/README.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# DexKnife
2+
3+
Update Log
4+
--------
5+
1.5.2: fix the include and exclude path, and supports filtering single class.(修复include和exclude, 并支持过滤单个类)<br/>
6+
1.5.1.exp: Experimentally support android gradle plugin on 2.1.0 (实验性的支持 2.1.0 plugin)<br/>
7+
1.5.1: fix the proguard mode
8+
9+
A simple android gradle plugin to use the patterns of package to smart split the specified classes to second dex.<br/>
10+
11+
- **Notes: Only fully tested less than version 2.0.0.
12+
Because instant-run of 2.0.0 above is disabled when you enable multidex, so no conflict with DexKnife.
13+
14+
Usage
15+
--------
16+
17+
1、In your project's build.gradle, buildscript.repositories add the bintray's maven.<br/>
18+
19+
buildscript {
20+
....
21+
22+
dependencies {
23+
....
24+
classpath 'com.android.tools.build:gradle:2.1.0' // or other
25+
classpath 'com.ceabie.dextools:gradle-dexknife-plugin:1.5.2' // Experimental
26+
}
27+
}
28+
29+
2、Create a 'dexknife.txt' in your App's module, and config the patterns of classes path that wants to put into sencond dex.<br/>
30+
31+
Patterns may include:
32+
33+
'*' to match any number of characters
34+
'?' to match any single character
35+
'**' to match any number of directories or files
36+
Either '.' or '/' may be used in a pattern to separate directories.
37+
Patterns ending with '.' or '/' will have '**' automatically appended.
38+
39+
Also see: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/util/PatternFilterable.html
40+
41+
Other config key:
42+
43+
'#' is the comment.
44+
45+
# this path will to be split to second dex.
46+
android.support.v?.**
47+
48+
# if you want to keep some classes in main dex, use '-keep'.
49+
-keep android.support.v4.view.**
50+
51+
# you can keep single class in main dex, end with '.class', use '-keep'.
52+
-keep android.support.v7.app.AppCompatDialogFragment.class
53+
54+
# do not use suggest of the maindexlist that android gradle plugin generate.
55+
-donot-use-suggest
56+
57+
# Notes: Split dex until the dex's id > 65536. --minimal-main-dex is default.
58+
# -auto-maindex # default is not used.
59+
60+
# log the main dex classes.
61+
-log-mainlist
62+
63+
3、add to your app's build.gradle, add this line:<br/>
64+
65+
apply plugin: 'com.ceabie.dexnkife'
66+
67+
and then, set your app
68+
69+
multiDexEnabled true
70+
71+
- **Notes: You want to set 'multiDexEnabled true' in 'defaultConfig' or 'buildTypes', otherwise ineffective.**
72+
73+
4、run your app
74+
75+
76+
# 中文
77+
78+
更新日志
79+
--------
80+
1.5.2: 修复include和exclude, 并支持过滤单个类<br/>
81+
1.5.1.exp: 实验性的支持 2.1.0 plugin<br/>
82+
1.5.1: fix the proguard mode
83+
84+
一个简单的将指定使用通配符包名分包到第二个dex中gradle插件。
85+
86+
- **注意:只在 android gradle plugin 小于 2.0.0 的版本上进行过完全测试。
87+
由于高于 2.0.0 的 instant-run 特性在启用 multidex 时失效,所以与DexKnife无冲突。
88+
89+
使用方法
90+
--------
91+
92+
1、在你的工程的 build.gradle 中 buildscript.repositories 增加bintray的仓库.<br/>
93+
94+
buildscript {
95+
....
96+
97+
dependencies {
98+
....
99+
classpath 'com.android.tools.build:gradle:2.1.0' // or other
100+
classpath 'com.ceabie.dextools:gradle-dexknife-plugin:1.5.2' // Experimental
101+
}
102+
}
103+
104+
2、在App模块下创建 dexknife.txt,并填写要放到第二个dex中的包名路径的通配符.
105+
106+
Patterns may include:
107+
108+
'*' to match any number of characters
109+
'?' to match any single character
110+
'**' to match any number of directories or files
111+
Either '.' or '/' may be used in a pattern to separate directories.
112+
Patterns ending with '.' or '/' will have '**' automatically appended.
113+
114+
更多参见: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/util/PatternFilterable.html
115+
116+
其他配置:
117+
118+
使用 # 进行注释.
119+
120+
# 如果你想要某个包路径在maindex中,则使用 -keep 选项,即使他已经在分包的路径中.
121+
-keep android.support.v4.view.**
122+
123+
# 这条配置可以指定这个包下类在第二dex中.
124+
android.support.v?.**
125+
126+
# 使用.class后缀,代表单个类.
127+
-keep android.support.v7.app.AppCompatDialogFragment.class
128+
129+
# 不包含Android gradle 插件自动生成的miandex列表.
130+
-donot-use-suggest
131+
132+
# 不进行dex分包, 直到 dex 的id数量超过 65536.
133+
# -auto-maindex
134+
135+
# 显示miandex的日志.
136+
-log-mainlist
137+
138+
139+
3、在你的App模块的build.gradle 增加:
140+
141+
apply plugin: 'com.ceabie.dexnkife'
142+
143+
最后,在app工程中设置:
144+
145+
multiDexEnabled true
146+
147+
- **注意:要在 defaultConfig 或者 buildTypes中打开 multiDexEnabled true,否则不起作用。**
148+
149+
4、编译你的应用
150+
151+

DexKnifePlugin/app/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/build
2+
3+
*.iml

DexKnifePlugin/app/build.gradle

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'com.ceabie.dexnkife'
3+
4+
android {
5+
compileSdkVersion Integer.parseInt(project.COMPILE_SDK_VER)
6+
buildToolsVersion project.BUILD_TOOLS_VER
7+
8+
defaultConfig {
9+
minSdkVersion Integer.parseInt(project.MIN_SDK_VER)
10+
targetSdkVersion Integer.parseInt(project.TARGET_SDK_VERSION)
11+
versionCode 1
12+
versionName "1.0"
13+
14+
multiDexEnabled true
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21+
}
22+
23+
debug {
24+
// minifyEnabled true
25+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26+
}
27+
}
28+
29+
// productFlavors {
30+
// flavor1 {
31+
// versionCode 20
32+
// }
33+
//
34+
// flavor2 {
35+
// minSdkVersion 14
36+
// multiDexEnabled false
37+
// }
38+
// }
39+
40+
packagingOptions {
41+
exclude ".readme"
42+
}
43+
}
44+
45+
dependencies {
46+
compile fileTree(include: ['*.jar'], dir: 'libs')
47+
compile "com.android.support:appcompat-v7:${SUPPORT_VERSION}"
48+
compile "io.reactivex:rxjava:${RX_JAVA}"
49+
compile "io.reactivex:rxandroid:${RX_ANDROID}"
50+
compile 'com.android.support:multidex:1.0.1'
51+
}
52+
53+
// 要放到第二个dex中的包名前缀 second_dex_package_list.txt
54+
// Set the prefix of package's path in second_dex_package_list.txt
55+
/*project.afterEvaluate {
56+
File file = project.file(DexSplitTools.DEX_KNIFE_CFG_TXT)
57+
if (file != null) {
58+
def justActivitys = [];
59+
file.eachLine { line ->
60+
//printf "read line ${line}\n";
61+
if (line.startsWith('-just activity')) {
62+
line = line.replaceAll('-just activity', '').trim();
63+
justActivitys.add(line)
64+
}
65+
}
66+
printf "-just activity size = ${justActivitys.size()}\n";
67+
if (justActivitys.size() != 0) {
68+
project.tasks.each { task ->
69+
if (task.name.startsWith('collect') && task.name.endsWith('MultiDexComponents')) {
70+
println "main-dex-filter: found task $task.name"
71+
task.filter { name, attrs ->
72+
String componentName = attrs.get('android:name')
73+
if ('activity'.equals(name)) {
74+
def result = justActivitys.find {
75+
componentName.endsWith("${it}")
76+
}
77+
def bool = result != null;
78+
if (!bool) {
79+
printf "main-dex-filter: skipping ${componentName}\n"
80+
}
81+
return bool
82+
}
83+
return true
84+
}
85+
}
86+
}
87+
}
88+
}
89+
}*/

DexKnifePlugin/app/dexknife.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#为注释符
2+
3+
#-----------主Dex中必要依赖的脚本配置-----------
4+
#默认保留四大组件中其他三大组件,Activity组件选择性保留(使用-just activity 选项),若为空默认保留所有Activity
5+
-just activity com.ceabie.demo.MainActivity
6+
7+
#-----------附加类-----------
8+
# 如果你想要某个包路径在maindex中,则使用 -keep 选项,即使他已经在分包的路径中.若为空,默认保留所有
9+
10+
# 保留单个类.
11+
#-keep android.support.v7.app.AppCompatDialogFragment.class
12+
13+
# 这条配置可以指定这个包下类在第二及其他dex中.
14+
#android.support.v?.**
15+
#将全部类移除主Dex
16+
-split **.**
17+
18+
# 不包含Android gradle 插件自动生成的miandex列表.(不用系统自带分包策略)
19+
#-donot-use-suggest
20+
21+
# 不进行dex分包, 直到 dex 的id数量超过 65536.(设置自动执行分包策略)
22+
#-auto-maindex
23+
24+
# 显示miandex的日志.
25+
#-log-mainlist

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy