Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba3fe05

Browse files
committed
add jcenter,add extended parameters for plugin
1 parent 59d4878 commit ba3fe05

File tree

60 files changed

+317
-358
lines changed

Some content is hidden

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

60 files changed

+317
-358
lines changed

DexKnifePlugin/.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,15 @@
66
.DS_Store
77
/build
88
/captures
9+
local.properties
10+
.idea/compiler.xml
11+
.idea/copyright/
12+
.idea/encodings.xml
13+
.idea/gradle.xml
14+
.idea/misc.xml
15+
.idea/qaplug_profiles.xml
16+
gradle/
17+
gradlew
18+
gradlew.bat
19+
repo/com/ceabie/
20+
repo/com/library/

DexKnifePlugin/app/build.gradle

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apply plugin: 'com.android.application'
2-
apply plugin: 'com.ceabie.dexnkife'
2+
apply plugin: 'dexknifePlus'
33

44
android {
55
compileSdkVersion Integer.parseInt(project.COMPILE_SDK_VER)
@@ -14,6 +14,16 @@ android {
1414
multiDexEnabled true
1515
}
1616

17+
productFlavors{
18+
dev{
19+
20+
}
21+
22+
mock{
23+
24+
}
25+
}
26+
1727
buildTypes {
1828
release {
1929
minifyEnabled false
@@ -31,6 +41,24 @@ android {
3141
}
3242
}
3343

44+
dexKnife{
45+
//必选参数
46+
enabled true //if false,禁用分包插件
47+
//可选参数
48+
//1.如果没有可选参数,将根据enabled决定是否分包。
49+
//2.如果有可选参数,需满足必选参数和可选参数的条件才允许分包
50+
productFlavor 'mock'
51+
buildType 'debug'
52+
53+
/*
54+
*eg:当前productFlavors = dev,buildType = debug,
55+
*参数组合1:enabled = true,productFlavor = dev,buildType = debug 分包
56+
*参数组合2:enabled = true,productFlavor = mock,buildType = debug 不分包
57+
*参数组合1:enabled = true,buildType = debug 所有buildType = debug分包
58+
*参数组合1:enabled = true,productFlavor = dev 所有productFlavor = dev分包
59+
* */
60+
}
61+
3462
dependencies {
3563
compile fileTree(include: ['*.jar'], dir: 'libs')
3664
compile "com.android.support:appcompat-v7:${SUPPORT_VERSION}"

DexKnifePlugin/build.gradle

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
buildscript {
22
repositories {
3-
maven { url uri('./repo') }
43
jcenter()
54
mavenCentral()
65
}
76

87
dependencies {
98
classpath 'com.android.tools.build:gradle:2.2.0'
10-
classpath 'com.ceabie.dextools:gradle-dexknife-plugin:2.0.2'
9+
classpath 'com.library.tangxiaolv:dexknife-plus:1.0.1'
1110
}
1211
}
1312

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
jcenter()
5+
}
6+
7+
dependencies {
8+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
9+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
10+
}
11+
}
12+
13+
apply plugin: 'groovy'
14+
apply plugin: 'com.jfrog.bintray'
15+
16+
configurations {
17+
provided {
18+
dependencies.all { dep ->
19+
configurations.default.exclude group: dep.group, module: dep.name
20+
}
21+
}
22+
compile.extendsFrom provided
23+
}
24+
25+
dependencies {
26+
compile gradleApi()
27+
compile localGroovy()
28+
provided 'com.android.tools.build:builder:2.1.3'
29+
provided 'com.android.tools.build:gradle-core:2.1.3'
30+
}
31+
32+
tasks.withType(Javadoc) {
33+
// enabled = false //禁用生成javadoc的任务
34+
options.encoding = "UTF-8"
35+
}
36+
37+
ext {
38+
bintrayRepo = 'maven'
39+
bintrayName = "$LIBRARY_NAME" //maven 仓库中的包名
40+
41+
publishedGroupId = "$GROUP_ID"
42+
libraryName = "$LIBRARY_NAME"
43+
artifact = "$LIBRARY_NAME"//必须跟Model名一样
44+
45+
libraryDescription = 'android multidex plugin'
46+
47+
siteUrl = 'https://github.com/TangXiaoLv/Android-Easy-MultiDex'
48+
gitUrl = 'https://github.com/TangXiaoLv/Android-Easy-MultiDex.git'
49+
50+
libraryVersion = "$PUBLIC_VERSION"
51+
52+
developerId = 'tangxiaolv'
53+
developerName = 'XiaoLv Tang'
54+
developerEmail = '[email protected]'
55+
56+
licenseName = 'The Apache Software License, Version 2.0'
57+
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
58+
allLicenses = ["Apache-2.0"]
59+
}
60+
61+
// Place it at the end of the file
62+
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
63+
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
64+
65+
uploadArchives {
66+
repositories {
67+
mavenDeployer {
68+
repository(url: uri('../repo'))
69+
pom.groupId = "$GROUP_ID"
70+
pom.artifactId = "$LIBRARY_NAME"
71+
pom.version = "$LOCAL_VERSION"
72+
}
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Gradle:groupId:libraryName:publicVersion
2+
LOCAL_VERSION=0.0.5
3+
PUBLIC_VERSION=1.0.1
4+
GROUP_ID=com.library.tangxiaolv
5+
#±ØÐë¸úModelÃûÒ»Ñù
6+
LIBRARY_NAME=dexknife-plus
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.ceabie.dexknife
2+
3+
class DexKnifeExtension {
4+
boolean enabled = false
5+
String productFlavor = ""
6+
String buildType = ""
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (C) 2016 ceabie (https://github.com/ceabie/)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.ceabie.dexknife
17+
18+
import org.gradle.api.Plugin
19+
import org.gradle.api.Project
20+
21+
/**
22+
* the spilt tools plugin.
23+
*/
24+
public class DexKnifePlugin implements Plugin<Project> {
25+
26+
@Override
27+
void apply(Project project) {
28+
29+
DexKnifeExtension dexKnifeExtension = project.extensions.create('dexKnife', DexKnifeExtension)
30+
project.afterEvaluate {
31+
boolean hasApp = project.plugins.hasPlugin("com.android.application")
32+
print("-hasApp = ${hasApp}\n")
33+
if (!hasApp) {
34+
throw new IllegalStateException("'android' plugin required.")
35+
}
36+
37+
final def variants = project.android.applicationVariants
38+
variants.each{variant ->
39+
if (dexKnifeExtension.enabled) {
40+
boolean checkProductFlavor = dexKnifeExtension.productFlavor == "" || dexKnifeExtension.productFlavor.equalsIgnoreCase(variant.flavorName)
41+
boolean checkBuildType = dexKnifeExtension.buildType == "" || dexKnifeExtension.buildType.equalsIgnoreCase(variant.buildType.name)
42+
if (checkProductFlavor && checkBuildType) {
43+
printf "-DexKnifePlugin Enable = true\n";
44+
printf "-DexKnifePlugin checkProductFlavor = ${checkProductFlavor}\n";
45+
printf "-DexKnifePlugin checkBuildType = ${checkBuildType}\n";
46+
printf "-DexKnifePlugin buildType.name = ${variant.buildType.name}\n";
47+
printf "-DexKnifePlugin flavorName = ${variant.flavorName}\n";
48+
49+
filterActivity(project);
50+
51+
if (isMultiDexEnabled(variant)) {
52+
if (SplitToolsFor130.isCompat(variant)) {
53+
System.err.println("DexKnife: Compat 1.3.0.");
54+
SplitToolsFor130.processSplitDex(project, variant)
55+
} else if (SplitToolsFor150.isCompat()) {
56+
SplitToolsFor150.processSplitDex(project, variant)
57+
} else {
58+
System.err.println("DexKnife Error: DexKnife is not compatible your Android gradle plugin.");
59+
}
60+
} else {
61+
System.err.println("DexKnife : MultiDexEnabled is false, it's not work.");
62+
}
63+
}
64+
}
65+
printf "-DexKnifePlugin Enable = false\n";
66+
}
67+
}
68+
}
69+
70+
//filter Activity
71+
private static void filterActivity(Project project) {
72+
File file = project.file(DexSplitTools.DEX_KNIFE_CFG_TXT)
73+
if (file != null) {
74+
def justActivitys = [];
75+
file.eachLine { line ->
76+
//printf "read line ${line}\n";
77+
if (line.startsWith('-just activity')) {
78+
line = line.replaceAll('-just activity', '').trim();
79+
justActivitys.add(line)
80+
}
81+
}
82+
printf "-just activity size = ${justActivitys.size()}\n";
83+
if (justActivitys.size() != 0) {
84+
project.tasks.each { task ->
85+
if (task.name.startsWith('collect') && task.name.endsWith('MultiDexComponents')) {
86+
println "main-dex-filter: found task $task.name"
87+
task.filter { name, attrs ->
88+
String componentName = attrs.get('android:name')
89+
if ('activity'.equals(name)) {
90+
def result = justActivitys.find {
91+
componentName.endsWith("${it}")
92+
}
93+
def bool = result != null;
94+
if (bool) {
95+
printf "main-dex-filter: keep ${componentName}\n"
96+
}
97+
return bool
98+
}
99+
return true
100+
}
101+
}
102+
}
103+
}
104+
}
105+
}
106+
107+
private static boolean isMultiDexEnabled(variant) {
108+
def is = variant.buildType.multiDexEnabled
109+
if (is != null) {
110+
return is;
111+
}
112+
113+
is = variant.mergedFlavor.multiDexEnabled
114+
if (is != null) {
115+
return is;
116+
}
117+
118+
return false
119+
}
120+
121+
}

0 commit comments

Comments
 (0)