Skip to content

Commit

Permalink
0.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
typ0520 committed Nov 27, 2017
1 parent 9eeea1d commit e528f70
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 57 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.8.3 (2017-11-27)

Bugfixes:

- 修复dex输出目录和apk中的dex顺序不一样导致补丁应用不上的问题

## 0.8.2 (2017-11-22)

Features:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Android API 9(2.3)+ ; android-gradle-build 2.0.0+
}
dependencies {
classpath 'com.github.typ0520:fastdex-gradle:0.8.2'
classpath 'com.github.typ0520:fastdex-gradle:0.8.3'
}
}
````
Expand Down
29 changes: 24 additions & 5 deletions fastdex-gradle/src/main/groovy/fastdex/build/FastdexPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ class FastdexPlugin implements Plugin<Project> {
FastdexBuildListener.addByProject(project)

def android = project.extensions.android

//close preDexLibraries
android.dexOptions.preDexLibraries = false
//open jumboMode
android.dexOptions.jumboMode = true

try {
if (GradleUtils.getAndroidGradlePluginVersion().compareTo("3.0.0") >= 0) {
//禁止掉aapt2
GradleUtils.addDynamicProperty(project,"android.enableAapt2","false")
reflectAapt2Flag()
} catch (Throwable e) {
reflectAapt2Flag(project)
//禁止掉dex archive任务
reflectDexArchive(project)
}

project.afterEvaluate {
Expand Down Expand Up @@ -439,7 +442,7 @@ class FastdexPlugin implements Plugin<Project> {
}

//禁掉aapt2
def reflectAapt2Flag() {
def reflectAapt2Flag(Project project) {
try {
def booleanOptClazz = Class.forName('com.android.build.gradle.options.BooleanOption')
def enableAAPT2Field = booleanOptClazz.getDeclaredField('ENABLE_AAPT2')
Expand All @@ -453,6 +456,22 @@ class FastdexPlugin implements Plugin<Project> {
}
}

//禁止掉dex archive任务
def reflectDexArchive(Project project) {
try {
def booleanOptClazz = Class.forName('com.android.build.gradle.options.BooleanOption')

def enableDexArchiveField = booleanOptClazz.getDeclaredField('ENABLE_DEX_ARCHIVE')
enableDexArchiveField.setAccessible(true)
def enableDexArchiveObj = enableDexArchiveField.get(null)
def defValField = enableDexArchiveObj.getClass().getDeclaredField('defaultValue')
defValField.setAccessible(true)
defValField.set(enableDexArchiveObj, false)
} catch (Throwable thr) {
project.logger.error("reflectDexArchive error: ${thr.getMessage()}.")
}
}

Task getPackageTask(Project project, String variantName) {
String taskName = "package${variantName}"
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.lang.reflect.Constructor
/**
* Created by tong on 17/10/31.
*/
@Deprecated
class FastdexDexMergerTransform extends TransformProxy {

FastdexDexMergerTransform(Transform base,File streamOutputFolder, FastdexVariant fastdexVariant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ class FastdexDexTransform extends TransformProxy {

@Override
void transform(TransformInvocation transformInvocation) throws TransformException, IOException, InterruptedException {
File mainDexListFile = fastdexVariant.androidVariant.getVariantData().getScope().getMainDexListFile()

if (!mainDexListFile.parentFile.exists()) {
mainDexListFile.parentFile.mkdirs()
}
if (!mainDexListFile.exists()) {
mainDexListFile.createNewFile()
}

if (fastdexVariant.hasDexCache) {
project.logger.error("\n==fastdex patch transform start,we will generate dex file")
if (fastdexVariant.projectSnapshoot.diffResultSet.isJavaFileChanged()) {
Expand Down Expand Up @@ -137,37 +146,22 @@ class FastdexDexTransform extends TransformProxy {
}

static Transform replaceBaseTransform(Transform base, FastdexVariant fastdexVariant) {
// if (GradleUtils.getAndroidGradlePluginVersion().compareTo("3.0") >= 0) {
// Class dexingTypeClass = Class.forName("com.android.builder.dexing.DexingType")
// Object[] values = dexingTypeClass.getMethod("values").invoke(null,null)
//
// //com.android.build.gradle.internal.transforms.DexTransform
// Constructor<?>[] constructors = base.getClass().getConstructors()
// Constructor targetConstructor = constructors[0]
//
// Transform result =
// targetConstructor.newInstance( base.dexOptions
// ,values.find { it.isMultiDex() && it.isPreDex() }
// ,base.preDexEnabled
// ,(FileCollection)null
// ,base.targetInfo
// ,base.dexByteCodeConverter
// , base.errorReporter
// ,21)
//
// return result
// }
// else
if (GradleUtils.getAndroidGradlePluginVersion().compareTo(Constants.MIN_BUILD_CACHE_ENABLED_VERSION) >= 0 && GradleUtils.getAndroidGradlePluginVersion().compareTo("3.0") < 0) {
//在所有的build-type上触发2.2以后的build-cache
//boolean needMerge = !multiDex || mainDexListFile != null;// || !debugMode;
//为了触发dex merge,使mainDexListFile不等于null

//boolean needMerge = !multiDex || mainDexListFile != null;

File mainDexListFile = base.mainDexListFile
if (mainDexListFile == null) {
mainDexListFile = fastdexVariant.androidVariant.getVariantData().getScope().getMainDexListFile()
}

fastdexVariant.project.logger.error("==fastdex android gradle >= ${Constants.MIN_BUILD_CACHE_ENABLED_VERSION} ,replace dex transform")
return new DexTransform(
base.dexOptions,
base.debugMode,
base.multiDex,
null,
mainDexListFile,
base.intermediateFolder,
base.androidBuilder,
base.logger.logger,
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
org.gradle.daemon=true

groupId=com.github.typ0520
version=0.8.2
version=0.8.3

ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=22
Expand Down
2 changes: 2 additions & 0 deletions sample/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ javalib/build/
javalib-group/javalib2/build/
javalib-group/javalib3/build/
common4

output.txt
49 changes: 30 additions & 19 deletions sample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
apply plugin: 'com.android.application'
//3.0.0支持了lambda不需要这个插件了
//apply plugin: 'me.tatarka.retrolambda'
//apply plugin: 'com.jakewharton.butterknife'
//apply plugin: 'com.neenbedankt.android-apt'

if (com.android.builder.model.Version.ANDROID_GRADLE_PLUGIN_VERSION.compareTo("3.0") < 0) {
//3.0.0支持了lambda不需要这个插件了
apply plugin: 'me.tatarka.retrolambda'

retrolambda {
javaVersion JavaVersion.VERSION_1_7
}
}

apply plugin: 'fastdex.app'

fastdex {
Expand All @@ -25,7 +31,10 @@ fastdex {

android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
//buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

if (com.android.builder.model.Version.ANDROID_GRADLE_PLUGIN_VERSION.compareTo("3.0") < 0) {
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
Expand All @@ -44,7 +53,7 @@ android {
applicationId "com.github.typ0520.fastdex.sample"
versionCode 1
versionName "1.0.0"
multiDexEnabled false
multiDexEnabled true
}

signingConfigs {
Expand All @@ -70,24 +79,26 @@ android {
}
}

// productFlavors {
// flavor1 {
// }
//
// flavor2 {
// }
// }
productFlavors {
flavor1 {
if (com.android.builder.model.Version.ANDROID_GRADLE_PLUGIN_VERSION.compareTo("3.0") >= 0) {
flavorDimensions "versionCode"
}
}

flavor2 {
if (com.android.builder.model.Version.ANDROID_GRADLE_PLUGIN_VERSION.compareTo("3.0") >= 0) {
flavorDimensions "versionCode"
}
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

//retrolambda {
// javaVersion JavaVersion.VERSION_1_7
//}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

Expand All @@ -107,8 +118,7 @@ dependencies {
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'org.xutils:xutils:3.3.36'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'de.hdodenhof:circleimageview:2.0.0'
//
compile 'de.hdodenhof:circleimageview:2.0.0'//
// compile 'com.squareup.retrofit:retrofit:1.9.0'
// compile 'info.hoang8f:android-segmented:1.0.6'
// compile 'com.squareup.okio:okio:1.0.1'
Expand All @@ -117,6 +127,7 @@ dependencies {
// compile 'com.squareup.retrofit:retrofit:1.8.0'
// compile 'com.squareup.okhttp:okhttp:2.2.0'
// compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'

//
// compile "org.greenrobot:eventbus:3.0.0"
// compile "org.glassfish:javax.annotation:10.0-b28"
Expand Down
1 change: 1 addition & 0 deletions sample/app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
tools:context="fastdex.sample.LoginActivity">

<TextView
android:id="@+id/tv_login_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login1"
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ buildscript {
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.android.tools.build:gradle:3.0.1'
//classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath "me.tatarka:gradle-retrolambda:3.7.0"
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
classpath 'com.github.typ0520:fastdex-gradle:0.8.2'
classpath 'com.github.typ0520:fastdex-gradle:0.8.3'
}
}

Expand Down
4 changes: 3 additions & 1 deletion sample/common-group/common2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
//buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
if (com.android.builder.model.Version.ANDROID_GRADLE_PLUGIN_VERSION.compareTo("3.0.0") < 0) {
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
}

defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
Expand Down
4 changes: 3 additions & 1 deletion sample/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
//buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
if (com.android.builder.model.Version.ANDROID_GRADLE_PLUGIN_VERSION.compareTo("3.0.0") < 0) {
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
}

defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion sample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Thu Oct 26 13:45:44 CST 2017
#Mon Nov 27 13:29:28 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion sample/javalib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply plugin: 'java-library'
apply plugin: 'java'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
Expand Down
4 changes: 3 additions & 1 deletion sample/kotlinlib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ apply plugin: 'kotlin-android'

android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
if (com.android.builder.model.Version.ANDROID_GRADLE_PLUGIN_VERSION.compareTo("3.0.0") < 0) {
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
}

defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
Expand Down

0 comments on commit e528f70

Please sign in to comment.