Small icon indicating copy to clipboard operation
Small copied to clipboard

Support for Android Gradle Plugin 3.0

Open galenlin opened this issue 7 years ago • 9 comments

Android Gradle Plugin (下称 AGP) 3.0 相对于 2.3.0 有了大幅的 API 改动。 导致我们的 gradle-small 编译插件在以下重要环节出现了问题:

  1. 解析 aar 依赖
  2. 分离 class
  3. 分离 arsc
  4. 分离 JNI
  5. 分离 manifest
  6. 分离 assets

为解决该适配问题,Small 决定重新设计编译流程,前置分离过程,减少不必要的后期 transform hook。同时彻底弃用原有对 AGP 私有 API 的引用,为以后兼容性打下基础。

拟采取以下方案(打钩项目已完成):

  • [x] 1. 预处理:解析 aar 依赖,对等构造一批仅包含 res 目录的 aar 文件,提前完成 Jar, JNI, Manifest, Assets 等文件分离
  • [x] 2. 重定向:通过动态构造 flatDir repo,引用上述裁剪版的 aar 依赖
  • [x] 3. 分离三方库:根据 (1) 中依赖,动态 compileOnly 当前插件模块所需的 jar
  • [x] 4. 分离 R.class:通过对 aapt, javac task 的 hook,构造一个仅含当前模块所需的 R.class
  • [x ] 5. 分离 ap_:解压 ap_ 文件,分离非模块自身的 res 资源,并重新构造一个经过剪裁的 arsc 文件
  • [ ] 6. 混淆适配

方案改造后,将完美适配 AGP 3.0。 同时新方案将大量的 I/O 操作前置到预处理过程,并良好地利用 Gradle Task Up-To-Date 设计,预期将大幅提高编译效率。

最新进展

目前已完成初步适配,代码分支 support-android-gradle-3.0

galenlin avatar Dec 05 '17 14:12 galenlin

赞!👍 加油!

podinns avatar Dec 06 '17 01:12 podinns

那如果只是升级Android studio 版本为3.0,不升级Android Gradle Plugin 或 gradle 版本,编译应该不会受影响吧?

navyifanr avatar Dec 09 '17 13:12 navyifanr

@navyifanr 不会

galenlin avatar Dec 09 '17 13:12 galenlin

适配gradle plugin 3.0以上的了吗?

wkable avatar Mar 15 '18 02:03 wkable

@podinns @wkable 已初步适配,见分支 support-android-gradle-3.0

galenlin avatar Jun 26 '18 16:06 galenlin

@galenlin As per your reply to #570 and The initial adaptation has now been completed given in latest update, What it means? If this means that now I can use 3.0.0 Gradle plugin version instead of 2.3.0 in my project. In that case, I made following changes in Application level build.gradle file as below

dependencies { classpath 'com.android.tools.build:gradle:3.0.0' classpath 'net.wequick.tools.build:gradle-small:2.0.0' } then I got following error "could not find net.wequick.tools.build:gradle-small:2.0.0"

When I make changes as below dependencies { classpath 'com.android.tools.build:gradle:3.0.0' classpath 'net.wequick.tools.build:gradle-small:1.3.0-beta6' }

then I got the following error "Could not get unknown property libraries for task :app.*:processDebugManifest"

Please give clarification that,either this adaption work still in progress or am I missing some thing.

kumarswamy-repo avatar Jul 01 '18 12:07 kumarswamy-repo

@kumarswamy-repo Yes, it's incubating, you can checkout the support-android-gradle-3.0 branch and try the DevSample source project.

galenlin avatar Jul 01 '18 14:07 galenlin

@kumarswamy-repo Yes, it's incubating, you can checkout the support-android-gradle-3.0 branch and try the DevSample source project.

support-android-gradle-3.0 DevSample分支跑不起来: 报错:You need to use a Theme.AppCompat theme (or descendant) with this activity。我已经将Theme适配还是不行。 AS:3.0 gradle:3.0.1

lynn01247 avatar May 16 '19 01:05 lynn01247

@kumarswamy-repo Yes, it's incubating, you can checkout the support-android-gradle-3.0 branch and try the DevSample source project.

support-android-gradle-3.0 DevSample分支跑不起来: 报错:You need to use a Theme.AppCompat theme (or descendant) with this activity。我已经将Theme适配还是不行。 AS:3.0 gradle:3.0.1

metoo

tangkoucan avatar Jun 04 '19 06:06 tangkoucan