Skip to content

Commit

Permalink
support android gradle plugin 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
typ0520 committed Nov 2, 2017
1 parent 03ae8bb commit 2b74ab4
Show file tree
Hide file tree
Showing 51 changed files with 1,471 additions and 4,068 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.8.0 (2017-11-2)

Features:

- 支持android gradle plugin 3.0

Bugfixes:

- 修复assets目录为空时生成资源补丁出错的问题

## 0.7.4 (2017-10-20)

Bugfixes:
Expand Down
4 changes: 2 additions & 2 deletions 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.7.4'
classpath 'com.github.typ0520:fastdex-gradle:0.8.0'
}
}
````
Expand Down Expand Up @@ -95,7 +95,7 @@ Android API 9(2.3)+ ; android-gradle-build 2.0.0+
classes.dex => classes2.dex
classes2.dex => classes3.dex
然后运行期在入口Application(fastdex.runtime.FastdexApplication)使用MultiDex把所有的dex加载进来
- @see [fastdex.build.transform.FastdexTransform](https://github.com/typ0520/fastdex/blob/master/fastdex-gradle/src/main/groovy/fastdex/build/transform/FastdexTransform.groovy)
- @see [fastdex.build.transform.FastdexDexTransform](https://github.com/typ0520/fastdex/blob/master/fastdex-gradle/src/main/groovy/fastdex/build/transform/FastdexTransform.groovy)
- 7、保存资源映射表,为了保持id的值一致,详情看
- @see [fastdex.build.task.FastdexResourceIdTask](https://github.com/typ0520/fastdex/blob/master/fastdex-gradle/src/main/groovy/fastdex/build/task/FastdexResourceIdTask.groovy)

Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
buildscript {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'http://dl.bintray.com/jetbrains/intellij-plugin-service' }
}

Expand All @@ -17,6 +18,7 @@ buildscript {
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}

Expand Down
260 changes: 199 additions & 61 deletions fastdex-gradle/src/main/groovy/fastdex/build/FastdexPlugin.groovy

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fastdex.build.extension
/**
* Created by tong on 17/10/3.
*/
public class FastdexExtension {
class FastdexExtension {
/**
* 是否可用
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import org.gradle.api.tasks.TaskAction
* 清空指定variantName的缓存,如果variantName == null清空所有缓存
* Created by tong on 17/3/12.
*/
public class FastdexCleanTask extends DefaultTask {
class FastdexCleanTask extends DefaultTask {
FastdexVariant fastdexVariant

FastdexCleanTask() {
group = 'fastdex'
}

@TaskAction
void clean() {
def clean() {
if (fastdexVariant == null) {
FastdexUtils.cleanAllCache(project)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import org.gradle.api.tasks.TaskAction
* 所以这个任务就没有存在的意义了,禁止掉这个任务以提高打包速度,但是transformClassesWithDexFor${variantName}会使用这个任务输出的txt文件,所以需要生成一个空文件防止报错
* Created by tong on 17/3/12.
*/
public class FastdexCreateMaindexlistFileTask extends DefaultTask {
class FastdexCreateMaindexlistFileTask extends DefaultTask {
FastdexVariant fastdexVariant

FastdexCreateMaindexlistFileTask() {
group = 'fastdex'
}

@TaskAction
void createFile() {
def createFile() {
if (fastdexVariant.androidVariant != null) {
File maindexlistFile = fastdexVariant.androidVariant.getVariantData().getScope().getMainDexListFile()
File parentFile = maindexlistFile.getParentFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import java.nio.file.attribute.BasicFileAttributes
*
* Created by tong on 17/3/12.
*/
public class FastdexCustomJavacTask extends DefaultTask {
class FastdexCustomJavacTask extends DefaultTask {
FastdexVariant fastdexVariant
Task javaCompile
Task javacIncrementalSafeguard
Expand Down Expand Up @@ -60,7 +60,7 @@ public class FastdexCustomJavacTask extends DefaultTask {
}

@TaskAction
void compile() {
def compile() {
if (!fastdexVariant.hasDexCache) {
project.logger.error("==fastdex miss dex cache, just ignore")
return
Expand Down Expand Up @@ -248,8 +248,8 @@ public class FastdexCustomJavacTask extends DefaultTask {
project.logger.error("==fastdex apply class to ${destFile}")

String classRelativePath = relativePath.toString()
classRelativePath = classRelativePath.substring(0, classRelativePath.length() - ShareConstants.CLASS_SUFFIX.length());
classRelativePath = classRelativePath.replaceAll(Os.isFamily(Os.FAMILY_WINDOWS) ? "\\\\" : File.separator,"\\.");
classRelativePath = classRelativePath.substring(0, classRelativePath.length() - ShareConstants.CLASS_SUFFIX.length())
classRelativePath = classRelativePath.replaceAll(Os.isFamily(Os.FAMILY_WINDOWS) ? "\\\\" : File.separator,"\\.")

int index = classRelativePath.indexOf("\$")
if (index != -1) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import org.gradle.api.tasks.TaskAction
/**
* Created by tong on 17/3/12.
*/
public class FastdexInstantRunMarkTask extends DefaultTask {
class FastdexInstantRunMarkTask extends DefaultTask {
FastdexVariant fastdexVariant

FastdexInstantRunMarkTask() {
group = 'fastdex'
}

@TaskAction
void mark() {
def mark() {
fastdexVariant.fastdexInstantRun.fromFastdexInstantRun = true
project.logger.error("==fastdex fromFastdexInstantRun: true")

Expand All @@ -27,11 +27,6 @@ public class FastdexInstantRunMarkTask extends DefaultTask {
} catch (Throwable e) {

}
// try {
// fastdexVariant.fastdexInstantRun.startTransparentActivity(true)
// } catch (Throwable e) {
//
// }
}
}).start()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import org.gradle.api.tasks.TaskAction
/**
* Created by tong on 17/3/12.
*/
public class FastdexInstantRunTask extends DefaultTask {
class FastdexInstantRunTask extends DefaultTask {
FastdexVariant fastdexVariant

FastdexInstantRunTask() {
group = 'fastdex'
}

@TaskAction
void instantRun() {
def instantRun() {
FastdexInstantRun fastdexInstantRun = fastdexVariant.fastdexInstantRun

if (!fastdexInstantRun.isInstallApk()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.gradle.api.tasks.TaskAction
*
* Created by tong on 17/3/11.
*/
public class FastdexManifestTask extends DefaultTask {
class FastdexManifestTask extends DefaultTask {
static final String FASTDEX_ORIGIN_APPLICATION_CLASSNAME = "FASTDEX_ORIGIN_APPLICATION_CLASSNAME"
static final String FASTDEX_BOOT_ACTIVITY_CLASSNAME = "FASTDEX_BOOT_ACTIVITY_CLASSNAME"
static final String MIDDLEWARE_ACTIVITY = "fastdex.runtime.MiddlewareActivity"
Expand All @@ -34,7 +34,7 @@ public class FastdexManifestTask extends DefaultTask {

def application = xml.application[0]
if (application) {
QName nameAttr = new QName("http://schemas.android.com/apk/res/android", 'name', 'android');
QName nameAttr = new QName("http://schemas.android.com/apk/res/android", 'name', 'android')
def applicationName = application.attribute(nameAttr)
if (applicationName == null || applicationName.isEmpty()) {
applicationName = "android.app.Application"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.gradle.api.tasks.TaskAction
/**
* Created by tong on 17/3/12.
*/
public class FastdexPatchTask extends DefaultTask {
class FastdexPatchTask extends DefaultTask {
FastdexVariant fastdexVariant

FastdexPatchTask() {
Expand Down Expand Up @@ -59,7 +59,7 @@ public class FastdexPatchTask extends DefaultTask {
try {
runtimeMetaInfo = serviceCommunicator.talkToService(fastdexInstantRun.device, new Communicator<MetaInfo>() {
@Override
public MetaInfo communicate(DataInputStream input, DataOutputStream output) throws IOException {
MetaInfo communicate(DataInputStream input, DataOutputStream output) throws IOException {
output.writeInt(ProtocolConstants.MESSAGE_PING_AND_SHOW_TOAST)

MetaInfo info = new MetaInfo()
Expand Down Expand Up @@ -106,7 +106,6 @@ public class FastdexPatchTask extends DefaultTask {

} catch (Throwable e) {
if (!(e instanceof FastdexRuntimeException)) {
e.printStackTrace()
fastdexVariant.project.logger.error("==fastdex ping installed app fail: " + e.message)
}
return
Expand Down Expand Up @@ -140,7 +139,7 @@ public class FastdexPatchTask extends DefaultTask {
try {
boolean result = serviceCommunicator.talkToService(fastdexInstantRun.device, new Communicator<Boolean>() {
@Override
public Boolean communicate(DataInputStream input, DataOutputStream output) throws IOException {
Boolean communicate(DataInputStream input, DataOutputStream output) throws IOException {
output.writeInt(ProtocolConstants.MESSAGE_PATCHES)
output.writeLong(ShareConstants.MESSAGE_TOKEN)
output.writeInt(changeCount)
Expand Down Expand Up @@ -184,7 +183,7 @@ public class FastdexPatchTask extends DefaultTask {
}
}
})
long end = System.currentTimeMillis();
long end = System.currentTimeMillis()
project.logger.error("==fastdex send patch data success. use: ${end - start}ms")

//app不在后台、补丁发送失败、补丁中包含dex并且有设置使用命令强制重启
Expand All @@ -195,7 +194,9 @@ public class FastdexPatchTask extends DefaultTask {
}
fastdexInstantRun.setInstallApk(false)
} catch (Throwable e) {
e.printStackTrace()
if (!(e instanceof FastdexRuntimeException)) {
fastdexVariant.project.logger.error("==fastdex send patch fail: " + e.message)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import org.gradle.api.tasks.TaskAction
* 准备上下文环境
* Created by tong on 17/4/18.
*/
public class FastdexPrepareTask extends DefaultTask {
class FastdexPrepareTask extends DefaultTask {
FastdexVariant fastdexVariant

FastdexPrepareTask() {
group = 'fastdex'
}

@TaskAction
void prepareContext() {
def prepareContext() {
fastdexVariant.prepareEnv()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import fastdex.build.util.FastdexUtils
*
* Created by tong on 17/3/11.
*/
public class FastdexResourceIdTask {
class FastdexResourceIdTask {
Project project
FastdexVariant fastdexVariant
String resDir
Expand All @@ -43,8 +43,8 @@ public class FastdexResourceIdTask {
File idsXmlFile = FastdexUtils.getIdxXmlFile(project,fastdexVariant.variantName)
File publicXmlFile = FastdexUtils.getPublicXmlFile(project,fastdexVariant.variantName)

String idsXml = resDir + "/values/ids.xml";
String publicXml = resDir + "/values/public.xml";
String idsXml = resDir + "/values/ids.xml"
String publicXml = resDir + "/values/public.xml"
File resDirIdsXmlFile = new File(idsXml)
File resDirPublicXmlFile = new File(publicXml)

Expand All @@ -61,8 +61,9 @@ public class FastdexResourceIdTask {
return
}

FileUtils.deleteFile(idsXml);
FileUtils.deleteFile(publicXml);
FileUtils.deleteFile(idsXml)
FileUtils.deleteFile(publicXml)

List<String> resourceDirectoryList = new ArrayList<String>()
resourceDirectoryList.add(resDir)

Expand All @@ -72,7 +73,6 @@ public class FastdexResourceIdTask {
AaptResourceCollector aaptResourceCollector = AaptUtil.collectResource(resourceDirectoryList, rTypeResourceMap)
PatchUtil.generatePublicResourceXml(aaptResourceCollector, idsXml, publicXml)
File publicFile = new File(publicXml)

if (publicFile.exists()) {
FileUtils.copyFileUsingStream(publicFile, publicXmlFile)
project.logger.error("==fastdex gen resource public.xml in ${Constants.RESOURCE_PUBLIC_XML}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import org.gradle.api.tasks.TaskAction
* 恢复对apt目录的扫描
* Created by tong on 17/10/13.
*/
public class FastdexScanAptOutputTask extends DefaultTask {
class FastdexScanAptOutputTask extends DefaultTask {
FastdexVariant fastdexVariant

FastdexScanAptOutputTask() {
group = 'fastdex'
}

@TaskAction
void scan() {
def scan() {
//如果没有使用自定义的编译任务需要拿老的apt快照与当前的对比
boolean needDiff = fastdexVariant.hasDexCache && !fastdexVariant.compiledByCustomJavac
//开启自定义的javac任务正常是不需要在扫描apt目录的,但是如果执行了dex merge会在保存一次当前快照,所以这种情况下要重新加回去
Expand Down Expand Up @@ -60,16 +60,16 @@ public class FastdexScanAptOutputTask extends DefaultTask {
project.logger.error("==fastdex not find old apt snapshoot")

//add
JavaDirectoryDiffResultSet resultSet = aptDirectorySnapshoot.createEmptyResultSet();
JavaDirectoryDiffResultSet resultSet = aptDirectorySnapshoot.createEmptyResultSet()
for (FileNode node : aptDirectorySnapshoot.nodes) {
resultSet.add(new JavaFileDiffInfo(Status.ADDED,node,null));
resultSet.add(new JavaFileDiffInfo(Status.ADDED,node,null))
project.logger.error("==fastdex find new apt file: " + node.uniqueKey)
}
diffResultSet.mergeJavaDirectoryResultSet(sourceSetSnapshoot.path,resultSet);
diffResultSet.mergeJavaDirectoryResultSet(sourceSetSnapshoot.path,resultSet)
}
else {
//diff
JavaDirectoryDiffResultSet resultSet = (JavaDirectoryDiffResultSet) aptDirectorySnapshoot.diff(oldAptJavaDirectorySnapshoot);
JavaDirectoryDiffResultSet resultSet = (JavaDirectoryDiffResultSet) aptDirectorySnapshoot.diff(oldAptJavaDirectorySnapshoot)
for (JavaFileDiffInfo diffInfo : resultSet.changedDiffInfos) {
if (diffInfo.status == Status.ADDED) {
project.logger.error("==fastdex find new apt file: " + diffInfo.uniqueKey)
Expand All @@ -78,7 +78,7 @@ public class FastdexScanAptOutputTask extends DefaultTask {
project.logger.error("==fastdex find changed apt file: " + diffInfo.uniqueKey)
}
}
diffResultSet.mergeJavaDirectoryResultSet(sourceSetSnapshoot.path,resultSet);
diffResultSet.mergeJavaDirectoryResultSet(sourceSetSnapshoot.path,resultSet)
}
}
}
Expand Down
Loading

0 comments on commit 2b74ab4

Please sign in to comment.