Skip to content

Commit

Permalink
add jcenter,add extended parameters for plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
TangXiaoLv committed Sep 29, 2016
1 parent 59d4878 commit ba3fe05
Show file tree
Hide file tree
Showing 60 changed files with 317 additions and 358 deletions.
12 changes: 12 additions & 0 deletions DexKnifePlugin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@
.DS_Store
/build
/captures
local.properties
.idea/compiler.xml
.idea/copyright/
.idea/encodings.xml
.idea/gradle.xml
.idea/misc.xml
.idea/qaplug_profiles.xml
gradle/
gradlew
gradlew.bat
repo/com/ceabie/
repo/com/library/
30 changes: 29 additions & 1 deletion DexKnifePlugin/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'com.ceabie.dexnkife'
apply plugin: 'dexknifePlus'

android {
compileSdkVersion Integer.parseInt(project.COMPILE_SDK_VER)
Expand All @@ -14,6 +14,16 @@ android {
multiDexEnabled true
}

productFlavors{
dev{

}

mock{

}
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -31,6 +41,24 @@ android {
}
}

dexKnife{
//必选参数
enabled true //if false,禁用分包插件
//可选参数
//1.如果没有可选参数,将根据enabled决定是否分包。
//2.如果有可选参数,需满足必选参数和可选参数的条件才允许分包
productFlavor 'mock'
buildType 'debug'

/*
*eg:当前productFlavors = dev,buildType = debug,
*参数组合1:enabled = true,productFlavor = dev,buildType = debug 分包
*参数组合2:enabled = true,productFlavor = mock,buildType = debug 不分包
*参数组合1:enabled = true,buildType = debug 所有buildType = debug分包
*参数组合1:enabled = true,productFlavor = dev 所有productFlavor = dev分包
* */
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.android.support:appcompat-v7:${SUPPORT_VERSION}"
Expand Down
3 changes: 1 addition & 2 deletions DexKnifePlugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
buildscript {
repositories {
maven { url uri('./repo') }
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.ceabie.dextools:gradle-dexknife-plugin:2.0.2'
classpath 'com.library.tangxiaolv:dexknife-plus:1.0.1'
}
}

Expand Down
File renamed without changes.
74 changes: 74 additions & 0 deletions DexKnifePlugin/dexknife-plus/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
buildscript {
repositories {
mavenLocal()
jcenter()
}

dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
}

apply plugin: 'groovy'
apply plugin: 'com.jfrog.bintray'

configurations {
provided {
dependencies.all { dep ->
configurations.default.exclude group: dep.group, module: dep.name
}
}
compile.extendsFrom provided
}

dependencies {
compile gradleApi()
compile localGroovy()
provided 'com.android.tools.build:builder:2.1.3'
provided 'com.android.tools.build:gradle-core:2.1.3'
}

tasks.withType(Javadoc) {
// enabled = false //禁用生成javadoc的任务
options.encoding = "UTF-8"
}

ext {
bintrayRepo = 'maven'
bintrayName = "$LIBRARY_NAME" //maven 仓库中的包名

publishedGroupId = "$GROUP_ID"
libraryName = "$LIBRARY_NAME"
artifact = "$LIBRARY_NAME"//必须跟Model名一样

libraryDescription = 'android multidex plugin'

siteUrl = 'https://github.com/TangXiaoLv/Android-Easy-MultiDex'
gitUrl = 'https://github.com/TangXiaoLv/Android-Easy-MultiDex.git'

libraryVersion = "$PUBLIC_VERSION"

developerId = 'tangxiaolv'
developerName = 'XiaoLv Tang'
developerEmail = 'imbatang@gmail.com'

licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}

// Place it at the end of the file
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'

uploadArchives {
repositories {
mavenDeployer {
repository(url: uri('../repo'))
pom.groupId = "$GROUP_ID"
pom.artifactId = "$LIBRARY_NAME"
pom.version = "$LOCAL_VERSION"
}
}
}
6 changes: 6 additions & 0 deletions DexKnifePlugin/dexknife-plus/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Gradle:groupId:libraryName:publicVersion
LOCAL_VERSION=0.0.5
PUBLIC_VERSION=1.0.1
GROUP_ID=com.library.tangxiaolv
#±ØÐë¸úModelÃûÒ»Ñù
LIBRARY_NAME=dexknife-plus
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ceabie.dexknife

class DexKnifeExtension {
boolean enabled = false
String productFlavor = ""
String buildType = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright (C) 2016 ceabie (https://github.com/ceabie/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ceabie.dexknife

import org.gradle.api.Plugin
import org.gradle.api.Project

/**
* the spilt tools plugin.
*/
public class DexKnifePlugin implements Plugin<Project> {

@Override
void apply(Project project) {

DexKnifeExtension dexKnifeExtension = project.extensions.create('dexKnife', DexKnifeExtension)
project.afterEvaluate {
boolean hasApp = project.plugins.hasPlugin("com.android.application")
print("-hasApp = ${hasApp}\n")
if (!hasApp) {
throw new IllegalStateException("'android' plugin required.")
}

final def variants = project.android.applicationVariants
variants.each{variant ->
if (dexKnifeExtension.enabled) {
boolean checkProductFlavor = dexKnifeExtension.productFlavor == "" || dexKnifeExtension.productFlavor.equalsIgnoreCase(variant.flavorName)
boolean checkBuildType = dexKnifeExtension.buildType == "" || dexKnifeExtension.buildType.equalsIgnoreCase(variant.buildType.name)
if (checkProductFlavor && checkBuildType) {
printf "-DexKnifePlugin Enable = true\n";
printf "-DexKnifePlugin checkProductFlavor = ${checkProductFlavor}\n";
printf "-DexKnifePlugin checkBuildType = ${checkBuildType}\n";
printf "-DexKnifePlugin buildType.name = ${variant.buildType.name}\n";
printf "-DexKnifePlugin flavorName = ${variant.flavorName}\n";

filterActivity(project);

if (isMultiDexEnabled(variant)) {
if (SplitToolsFor130.isCompat(variant)) {
System.err.println("DexKnife: Compat 1.3.0.");
SplitToolsFor130.processSplitDex(project, variant)
} else if (SplitToolsFor150.isCompat()) {
SplitToolsFor150.processSplitDex(project, variant)
} else {
System.err.println("DexKnife Error: DexKnife is not compatible your Android gradle plugin.");
}
} else {
System.err.println("DexKnife : MultiDexEnabled is false, it's not work.");
}
}
}
printf "-DexKnifePlugin Enable = false\n";
}
}
}

//filter Activity
private static void filterActivity(Project project) {
File file = project.file(DexSplitTools.DEX_KNIFE_CFG_TXT)
if (file != null) {
def justActivitys = [];
file.eachLine { line ->
//printf "read line ${line}\n";
if (line.startsWith('-just activity')) {
line = line.replaceAll('-just activity', '').trim();
justActivitys.add(line)
}
}
printf "-just activity size = ${justActivitys.size()}\n";
if (justActivitys.size() != 0) {
project.tasks.each { task ->
if (task.name.startsWith('collect') && task.name.endsWith('MultiDexComponents')) {
println "main-dex-filter: found task $task.name"
task.filter { name, attrs ->
String componentName = attrs.get('android:name')
if ('activity'.equals(name)) {
def result = justActivitys.find {
componentName.endsWith("${it}")
}
def bool = result != null;
if (bool) {
printf "main-dex-filter: keep ${componentName}\n"
}
return bool
}
return true
}
}
}
}
}
}

private static boolean isMultiDexEnabled(variant) {
def is = variant.buildType.multiDexEnabled
if (is != null) {
return is;
}

is = variant.mergedFlavor.multiDexEnabled
if (is != null) {
return is;
}

return false
}

}
Loading

0 comments on commit ba3fe05

Please sign in to comment.