当我们在编写一个Transform
的plugin
的时候,其实是对安卓的AppExtension
进行了一个注册Transform
的操作而已,那么Transform
的本质到底是什么呢?
高能预警,下面的源代码比较长,可以考虑直接跳过看结论,但是看得懂的同学最好可以学习下。
public class LibraryTaskManager extends TaskManager {
@Override
public void createTasksForVariantScope(@NonNull final VariantScope variantScope) {
…
// ----- External Transforms -----
// apply all the external transforms.
List customTransforms = extension.getTransforms();
List<List> customTransformsDependencies = extension.getTransformsDependencies();
for (int i = 0, count = customTransforms.size(); i < count; i++) {
Transform transform = customTransforms.get(i);
// Check the transform only applies to supported scopes for libraries:
// We cannot transform scopes that are not packaged in the library
// itself.
Sets.SetView<? super Scope> difference =
Sets.difference(transform.getScopes(), TransformManager.PROJECT_ONLY);
if (!difference.isEmpty()) {
String scopes = difference.toString();
globalScope
.getAndroidBuilder()
.getIssueReporter()
.reportError(
Type.GENERIC,
new EvalIssueException(
String.format(
“Transforms with scopes ‘%s’ cannot be applied to library projects.”,
scopes)));
}
List deps = customTransformsDependencies.get(i);
transformManager.addTransform(
taskFactory,
variantScope,
transform,
null,
task -> {
if (!deps.isEmpty()) {
task.dependsOn(deps);
}
},
taskProvider -> {
// if the task is a no-op then we make assemble task
// depend on it.
if (transform.getScopes().isEmpty()) {
TaskFactoryUtils.dependsOn(
variantScope.getTaskContainer().getAssembleTask(),
taskProvider);
}
});
}
// Now add transforms for intermediate publishing (projects to projects).
File jarOutputFolder = variantScope.getIntermediateJarOutputFolder();
File mainClassJar = new File(jarOutputFolder, FN_CLASSES_JAR);
File mainResJar = new File(jarOutputFolder, FN_INTERMEDIATE_RES_JAR);
LibraryIntermediateJarsTransform intermediateTransform =
new LibraryIntermediateJarsTransform(
mainClassJar,
mainResJar,
variantConfig::getPackageFromManifest,
extension.getPackageBuildConfig());
excludeDataBindingClassesIfNecessary(variantScope, intermediateTransform);
BuildArtifactsHolder artifacts = variantScope.getArtifacts();
transformManager.addTransform(
taskFactory,
variantScope,
intermediateTransform,
taskName -> {
// publish the intermediate classes.jar
artifacts.appendArtifact(
InternalArtifactType.LIBRARY_CLASSES,
ImmutableList.of(mainClassJar),
taskName);
// publish the res jar
artifacts.appendArtifact(
InternalArtifactType.LIBRARY_JAVA_RES,
ImmutableList.of(mainResJar),
taskName);
},
null,
null);
taskFactory.register(new LibraryDexingTask.CreationAction(variantScope));
// Create a jar with both classes and java resources. This artifact is not
// used by the Android application plugin and the task usually don’t need to
// be executed. The artifact is useful for other Gradle users who needs the
// ‘jar’ artifact as API dependency.
taskFactory.register(new ZipMergingTask.CreationAction(variantScope));
// now add a transform that will take all the native libs and package
// them into an intermediary folder. This processes only the PROJECT
// scope.
final File intermediateJniLibsFolder = new File(jarOutputFolder, FD_JNI);
LibraryJniLibsTransform intermediateJniTransform =
new LibraryJniLibsTransform(
“intermediateJniLibs”,
intermediateJniLibsFolder,
TransformManager.PROJECT_ONLY);
transformManager.addTransform(
taskFactory,
variantScope,
intermediateJniTransform,
taskName -> {
// publish the jni folder as intermediate
variantScope
.getArtifacts()
.appendArtifact(
InternalArtifactType.LIBRARY_JNI,
ImmutableList.of(intermediateJniLibsFolder),
taskName);
},
null,
null);
// Now go back to fill the pipeline with transforms used when
// publishing the AAR
// first merge the resources. This takes the PROJECT and LOCAL_DEPS
// and merges them together.
createMergeJavaResTransform(variantScope);
// ----- Minify next -----
maybeCreateJavaCodeShrinkerTransform(variantScope);
maybeCreateResourcesShrinkerTransform(variantScope);
// now add a transform that will take all the class/res and package them
// into the main and secondary jar files that goes in the AAR.
// This transform technically does not use its transform output, but that’s
// ok. We use the transform mechanism to get incremental data from
// the streams.
// This is used for building the AAR.
File classesJar = variantScope.getAarClassesJar();
File libsDirectory = variantScope.getAarLibsDirectory();
LibraryAarJarsTransform transform =
new LibraryAarJarsTransform(
classesJar,
libsDirectory,
artifacts.hasArtifact(InternalArtifactType.ANNOTATIONS_TYPEDEF_FILE)
? artifacts.getFinalArtifactFiles(
-
InternalArtifactType.ANNOTATIONS_TYPEDEF_FILE)
- null,
variantConfig::getPackageFromManifest,
extension.getPackageBuildConfig());
excludeDataBindingClassesIfNecessary(variantScope, transform);
transformManager.addTransform(
taskFactory,
variantScope,
transform,
taskName -> {
variantScope
.getArtifacts()
.appendArtifact(
InternalArtifactType.AAR_MAIN_JAR,
ImmutableList.of(classesJar),
taskName);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
最后
其实要轻松掌握很简单,要点就两个:
- 找到一套好的视频资料,紧跟大牛梳理好的知识框架进行学习。
- 多练。 (视频优势是互动感强,容易集中注意力)
你不需要是天才,也不需要具备强悍的天赋,只要做到这两点,短期内成功的概率是非常高的。
对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。
阿里P7Android高级教程
下面资料部分截图,诚意满满:特别适合有3-5年开发经验的Android程序员们学习。
附送高清脑图,高清知识点讲解教程,以及一些面试真题及答案解析。送给需要的提升技术、近期面试跳槽、自身职业规划迷茫的朋友们。
Android核心高级技术PDF资料,BAT大厂面试真题解析;
一个人可以走的很快,但一群人才能走的更远。如果你从事以下工作或对以下感兴趣,欢迎戳这里加入程序员的圈子,让我们一起学习成长!
AI人工智能、Android移动开发、AIGC大模型、C C#、Go语言、Java、Linux运维、云计算、MySQL、PMP、网络安全、Python爬虫、UE5、UI设计、Unity3D、Web前端开发、产品经理、车载开发、大数据、鸿蒙、计算机网络、嵌入式物联网、软件测试、数据结构与算法、音视频开发、Flutter、IOS开发、PHP开发、.NET、安卓逆向、云计算
一个人可以走的很快,但一群人才能走的更远。如果你从事以下工作或对以下感兴趣,欢迎戳这里加入程序员的圈子,让我们一起学习成长!
AI人工智能、Android移动开发、AIGC大模型、C C#、Go语言、Java、Linux运维、云计算、MySQL、PMP、网络安全、Python爬虫、UE5、UI设计、Unity3D、Web前端开发、产品经理、车载开发、大数据、鸿蒙、计算机网络、嵌入式物联网、软件测试、数据结构与算法、音视频开发、Flutter、IOS开发、PHP开发、.NET、安卓逆向、云计算