// 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);
variantScope
.getArtifacts()
.appendArtifact(
InternalArtifactType.AAR_LIBS_DIRECTORY,
ImmutableList.of(libsDirectory),
taskName);
},
null,
null);
// now add a transform that will take all the native libs and package
// them into the libs folder of the bundle. This processes both the PROJECT
// and the LOCAL_PROJECT scopes
final File jniLibsFolder =
variantScope.getIntermediateDir(InternalArtifactType.LIBRARY_AND_LOCAL_JARS_JNI);
LibraryJniLibsTransform jniTransform =
new LibraryJniLibsTransform(
“syncJniLibs”,
jniLibsFolder,
TransformManager.SCOPE_FULL_LIBRARY_WITH_LOCAL_JARS);
transformManager.addTransform(
taskFactory,
variantScope,
jniTransform,
taskName ->
variantScope
.getArtifacts()
.appendArtifact(
InternalArtifactType.LIBRARY_AND_LOCAL_JARS_JNI,
ImmutableList.of(jniLibsFolder),
taskName),
null,
null);
createLintTasks(variantScope);
createBundleTask(variantScope);
}
}
自定义Transform和其他系统Transform执行的顺序
而且上述方法我们可以看出,任务还是会根据DAG
(有向无环图)生成Task
,其中会包含一些系统的Transform
,其顺序有可能会被插入到自定义的Transform
之前,而有一些则会被放置在所有的Tranform
执行之后。比如LibraryJniLibsTransform
。
Transform和Task的关系
从这部分源代码其实我们就可以看出,我们注册到AppExtension
里面的Transform
,最后会createTasksForVariantScope
方法调用到。
@NonNull
public Optional<TaskProvider> addTransform(
@NonNull TaskFactory taskFactory,
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
尾声
以薪资待遇为基础,以发展为最终目标,要在高薪资的地方,谋求最好的发展!
下面是有几位Android行业大佬对应上方技术点整理的一些进阶资料。
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)**
[外链图片转存中…(img-7MiZ6cxk-1712691869402)]
尾声
以薪资待遇为基础,以发展为最终目标,要在高薪资的地方,谋求最好的发展!
下面是有几位Android行业大佬对应上方技术点整理的一些进阶资料。
[外链图片转存中…(img-IEpeT49b-1712691869402)]
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-pmIIaTLZ-1712691869403)]