From e528f7079a58262e8896861206ed36eea3fbf884 Mon Sep 17 00:00:00 2001 From: typ0520 Date: Mon, 27 Nov 2017 16:28:52 +0800 Subject: [PATCH] 0.8.3 --- CHANGELOG.md | 6 +++ README.md | 2 +- .../groovy/fastdex/build/FastdexPlugin.groovy | 29 +++++++++-- .../FastdexDexMergerTransform.groovy | 1 + .../transform/FastdexDexTransform.groovy | 42 +++++++--------- gradle.properties | 2 +- sample/.gitignore | 2 + sample/app/build.gradle | 49 ++++++++++++------- .../src/main/res/layout/activity_login.xml | 1 + sample/build.gradle | 4 +- sample/common-group/common2/build.gradle | 4 +- sample/common/build.gradle | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- sample/javalib/build.gradle | 2 +- sample/kotlinlib/build.gradle | 4 +- 15 files changed, 97 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d037bf9a..8f12e0a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.8.3 (2017-11-27) + +Bugfixes: + + - 修复dex输出目录和apk中的dex顺序不一样导致补丁应用不上的问题 + ## 0.8.2 (2017-11-22) Features: diff --git a/README.md b/README.md index 11e51884..908b1917 100644 --- a/README.md +++ b/README.md @@ -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' } } ```` diff --git a/fastdex-gradle/src/main/groovy/fastdex/build/FastdexPlugin.groovy b/fastdex-gradle/src/main/groovy/fastdex/build/FastdexPlugin.groovy index 80d3f25a..e649d082 100644 --- a/fastdex-gradle/src/main/groovy/fastdex/build/FastdexPlugin.groovy +++ b/fastdex-gradle/src/main/groovy/fastdex/build/FastdexPlugin.groovy @@ -35,14 +35,17 @@ class FastdexPlugin implements Plugin { 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 { @@ -439,7 +442,7 @@ class FastdexPlugin implements Plugin { } //禁掉aapt2 - def reflectAapt2Flag() { + def reflectAapt2Flag(Project project) { try { def booleanOptClazz = Class.forName('com.android.build.gradle.options.BooleanOption') def enableAAPT2Field = booleanOptClazz.getDeclaredField('ENABLE_AAPT2') @@ -453,6 +456,22 @@ class FastdexPlugin implements Plugin { } } + //禁止掉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 { diff --git a/fastdex-gradle/src/main/groovy/fastdex/build/transform/FastdexDexMergerTransform.groovy b/fastdex-gradle/src/main/groovy/fastdex/build/transform/FastdexDexMergerTransform.groovy index 1149a243..e82b481a 100644 --- a/fastdex-gradle/src/main/groovy/fastdex/build/transform/FastdexDexMergerTransform.groovy +++ b/fastdex-gradle/src/main/groovy/fastdex/build/transform/FastdexDexMergerTransform.groovy @@ -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) { diff --git a/fastdex-gradle/src/main/groovy/fastdex/build/transform/FastdexDexTransform.groovy b/fastdex-gradle/src/main/groovy/fastdex/build/transform/FastdexDexTransform.groovy index 967905eb..828ec6ce 100644 --- a/fastdex-gradle/src/main/groovy/fastdex/build/transform/FastdexDexTransform.groovy +++ b/fastdex-gradle/src/main/groovy/fastdex/build/transform/FastdexDexTransform.groovy @@ -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()) { @@ -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, diff --git a/gradle.properties b/gradle.properties index 24c5e048..99a83f36 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/sample/.gitignore b/sample/.gitignore index 5c692756..3a7392ab 100644 --- a/sample/.gitignore +++ b/sample/.gitignore @@ -55,3 +55,5 @@ javalib/build/ javalib-group/javalib2/build/ javalib-group/javalib3/build/ common4 + +output.txt \ No newline at end of file diff --git a/sample/app/build.gradle b/sample/app/build.gradle index 01f297af..92ebe0af 100644 --- a/sample/app/build.gradle +++ b/sample/app/build.gradle @@ -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 { @@ -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' @@ -44,7 +53,7 @@ android { applicationId "com.github.typ0520.fastdex.sample" versionCode 1 versionName "1.0.0" - multiDexEnabled false + multiDexEnabled true } signingConfigs { @@ -70,13 +79,19 @@ 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 @@ -84,10 +99,6 @@ android { } } -//retrolambda { -// javaVersion JavaVersion.VERSION_1_7 -//} - dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) @@ -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' @@ -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" diff --git a/sample/app/src/main/res/layout/activity_login.xml b/sample/app/src/main/res/layout/activity_login.xml index d5feed03..e8373759 100644 --- a/sample/app/src/main/res/layout/activity_login.xml +++ b/sample/app/src/main/res/layout/activity_login.xml @@ -7,6 +7,7 @@ tools:context="fastdex.sample.LoginActivity">