All Projects → lizhangqu → android-gradle-plugin-transform-patch

lizhangqu / android-gradle-plugin-transform-patch

Licence: other
android gradle plugin transform patch

Programming Languages

groovy
2714 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to android-gradle-plugin-transform-patch

Ngx Dynamic Form Builder
FormBuilder + class-transformer + class-validator = dynamic form group builder for Angular10+
Stars: ✭ 93 (+232.14%)
Mutual labels:  class, transform
Classanalyzer
A Java Class File Disassembler
Stars: ✭ 148 (+428.57%)
Mutual labels:  class
Class Logger
Boilerplate-free decorator-based class logging
Stars: ✭ 64 (+128.57%)
Mutual labels:  class
Papers Notebook
📄 🇨🇳 📃 论文阅读笔记(分布式系统、虚拟化、机器学习)Papers Notebook (Distributed System, Virtualization, Machine Learning), created by @gaocegege
Stars: ✭ 1,678 (+5892.86%)
Mutual labels:  class
Jsoncsharpclassgenerator
JsonCSharpClassGenerator from http://jsonclassgenerator.codeplex.com/
Stars: ✭ 70 (+150%)
Mutual labels:  class
Python And Oop
Object-Oriented Programming concepts in Python
Stars: ✭ 123 (+339.29%)
Mutual labels:  class
Nbem
💎 nbem is for intuitively write the class name of BEM method. React and others.
Stars: ✭ 28 (+0%)
Mutual labels:  class
Bigint
Arbitrary-sized integer class for C++
Stars: ✭ 189 (+575%)
Mutual labels:  class
React Universal Hooks
🎉 React Universal Hooks : just use****** everywhere (Functional or Class Component). Support React DevTools!
Stars: ✭ 148 (+428.57%)
Mutual labels:  class
Markor
Text editor - Notes & ToDo (for Android) - Markdown, todo.txt, plaintext, math, ..
Stars: ✭ 1,394 (+4878.57%)
Mutual labels:  class
Generators
Laravel File Generators with config and publishable stubs
Stars: ✭ 102 (+264.29%)
Mutual labels:  class
Not Awesome Es6 Classes
A curated list of resources on why ES6 (aka ES2015) classes are NOT awesome
Stars: ✭ 1,185 (+4132.14%)
Mutual labels:  class
Interview Series
iOS从入门到进阶 - 技术合集
Stars: ✭ 129 (+360.71%)
Mutual labels:  class
Ddd Base
DDD base class library for JavaScript application.
Stars: ✭ 66 (+135.71%)
Mutual labels:  class
Dumpclass
Dump classes from running JVM process.
Stars: ✭ 156 (+457.14%)
Mutual labels:  class
Polytype
Dynamic multiple inheritance for JavaScript and TypeScript. Without mixins.
Stars: ✭ 40 (+42.86%)
Mutual labels:  class
Struct2ts
Generate Typescript classes/interfaces out of Go structs
Stars: ✭ 116 (+314.29%)
Mutual labels:  class
Ring.js
Ring.js - JavaScript Class System with Multiple Inheritance
Stars: ✭ 223 (+696.43%)
Mutual labels:  class
Object Oriented Programming Using Python
Python is a multi-paradigm programming language. Meaning, it supports different programming approach. One of the popular approach to solve a programming problem is by creating objects. This is known as Object-Oriented Programming (OOP).
Stars: ✭ 183 (+553.57%)
Mutual labels:  class
Cohesion
A tool for measuring Python class cohesion.
Stars: ✭ 129 (+360.71%)
Mutual labels:  class

android gradle plugin transform patch

背景

分析文章见 治治这个 google 一年没修的 agp transform bug

在android gradle plugin 3.2.0以上版本,增量编译时如果aar发生了改变,则会出现类重复,典型的两个场景如下

  • A、以project依赖进行全量构建后,将project发布到远程,再将project依赖修改成aar远程依赖,再进行增量构建,此时会出现类重复。
  • B、全量构建完成后,此时更新任意一个aar,再进行增量构建,此时会出现类重复。

问题产生原因

@NonNull
TransformOutputProvider asOutput(boolean isIncremental) throws IOException {
    if (!isIncremental) {
        FileUtils.deleteIfExists(new File(getRootLocation(), SubStream.FN_FOLDER_CONTENT));
    }
    init();
    return new TransformOutputProviderImpl(folderUtils);
}

在android gradle plugin 3.2.0及以上版本中,如果第一个transform不是增量构建的,则会删除该transform目录下的__content__.json文件,触发文件名命名规则归0递增。当触发背景中的两个场景的时候,导致原先该被remove的文件没有触发removed事件,而是变成了changed事件,出现类重复。

但是在3.2.0以下版本,该文件不会被删除,文件名命名规则从该文件中最大的index开始递增,当触发背景中的两个场景的时候,由于文件名递增没有被清零所以新增文件触发added事件,原先该被remove的文件触发removed事件,不会出现类重复

如何使用修复插件

首先将守护进程杀死

./gradlew --stop

对于工程目录中没有buildSrc模块的工程,可使用如下方式

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath('io.github.lizhangqu:plugin-agp-transform-patch:1.0.6')
    }
}

//在对应模块中应用插件
apply plugin: 'agp-transform-patch'
//或使用提前初始化方式
//apply plugin: 'agp-transform-patch-by-pre-init'

如果工程目录中有buildSrc模块,请不要使用如上的buildscript方式,而是将依赖添加到buildSrc工程的依赖中

dependencies {
    compile('io.github.lizhangqu:plugin-agp-transform-patch:1.0.6') {
        changing = true
    }
    compile "com.android.tools.build:gradle:3.2.1"
}

然后在对应模块中应用插件

apply plugin: 'agp-transform-patch'
//或使用提前初始化方式
//apply plugin: 'agp-transform-patch-by-pre-init'

A复现步骤

首先将守护进程杀死

./gradlew --stop

1, 将app模块中对library模块的依赖修改为project依赖

dependencies {
    implementation("io.github.lizhangqu:library:1.0.0-SNAPSHOT") {
        changing = true
    }
}

修改为


dependencies {
    implementation project(path: ':library')
}

2,应用相应的复现bug用的插件

apply plugin: 'reproduce-agp-transform-bug'

3, clean并且进行app模块的全量构建

./gradlew :app:clean :app:assembleDebug

4, 将library模块clean后发布成aar,此时aar会被发布到工程根目录的repo目录下

./gradlew :library:clean :library:uploadSnapshot

5, 将app模块中对library模块的依赖修改成aar依赖

dependencies {
    implementation project(path: ':library')
}

修改为

dependencies {
    implementation("io.github.lizhangqu:library:1.0.0-SNAPSHOT") {
        changing = true
    }
}

6, 不进行clean再构建app模块,此时会进行增量构建,并出现类重复的问题

./gradlew :app:assembleDebug

B复现步骤

首先将守护进程杀死

./gradlew --stop

1, 将app模块中对library模块的依赖修改为aar依赖

dependencies {
    implementation project(path: ':library')
}

修改为

dependencies {
    implementation("io.github.lizhangqu:library:1.0.0-SNAPSHOT") {
        changing = true
    }
}

2,应用相应的复现bug用的插件

apply plugin: 'reproduce-agp-transform-bug'

3, 将library模块clean后发布成aar,此时aar会被发布到工程根目录的repo目录下

./gradlew :library:clean :library:uploadSnapshot

4, clean并且进行app模块的全量构建

./gradlew :app:clean :app:assembleDebug

5, 修改library模块中任意代码后,重新发布library模块,此时aar会被发布到工程根目录的repo目录下

./gradlew :library:clean :library:uploadSnapshot

6, 不进行clean再构建app模块,此时会进行增量构建,并出现类重复的问题

./gradlew :app:assembleDebug

A修复方案

首先将守护进程杀死

./gradlew --stop

1、应用修复bug用的patch插件

对于工程目录中没有buildSrc模块的工程,可使用如下方式

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath('io.github.lizhangqu:plugin-agp-transform-patch:1.0.5')
    }
}

//在对应模块中应用插件
apply plugin: 'agp-transform-patch'
//或使用提前初始化方式
//apply plugin: 'agp-transform-patch-by-pre-init'

如果工程目录中有buildSrc模块,请不要使用如上的buildscript方式,而是将依赖添加到buildSrc工程的依赖中

dependencies {
    compile('io.github.lizhangqu:plugin-agp-transform-patch:1.0.5') {
        changing = true
    }
    compile "com.android.tools.build:gradle:3.2.1"
}

然后在对应模块中应用插件

apply plugin: 'agp-transform-patch'
//或使用提前初始化方式
//apply plugin: 'agp-transform-patch-by-pre-init'

2、重复A复现步骤,类重复问题已经被修复

B修复方案1

首先将守护进程杀死

./gradlew --stop

1、将buildSrc工程下的BaseTransform中的getContentLocation调用第一个入参进行修改

transformInvocation.outputProvider.getContentLocation(it.getName(), it.contentTypes, it.scopes, Format.JAR)
transformInvocation.outputProvider.getContentLocation(it.getName(), it.contentTypes, it.scopes, Format.DIRECTORY)

修改为

transformInvocation.outputProvider.getContentLocation(it.getFile().toString(), it.contentTypes, it.scopes, Format.JAR)
transformInvocation.outputProvider.getContentLocation(it.getFile().toString(), it.contentTypes, it.scopes, Format.DIRECTORY)

2、重复B复现步骤,类重复问题已经被修复

但是此修复方式对第三方插件无效,只对自己写的transform可以修改,因此完美的解决方案请看B修复方案2

B修复方案2

首先将守护进程杀死

./gradlew --stop

1、应用修复bug用的patch插件

对于工程目录中没有buildSrc模块的工程,可使用如下方式

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath('io.github.lizhangqu:plugin-agp-transform-patch:1.0.6')
    }
}

//在对应模块中应用插件
apply plugin: 'agp-transform-patch'

如果工程目录中有buildSrc模块,请不要使用如上的buildscript方式,而是将依赖添加到buildSrc工程的依赖中

dependencies {
    compile('io.github.lizhangqu:plugin-agp-transform-patch:1.0.6') {
        changing = true
    }
    compile "com.android.tools.build:gradle:3.2.1"
}

然后在对应模块中应用插件

apply plugin: 'agp-transform-patch'
//或使用提前初始化方式
//apply plugin: 'agp-transform-patch-by-pre-init'

2、重复B复现步骤,类重复问题已经被修复

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].