| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> 移动开发 -> Android开发之玩转 Gradle,你可不能不熟悉 Transform,三面美团Android岗 -> 正文阅读 |
|
[移动开发]Android开发之玩转 Gradle,你可不能不熟悉 Transform,三面美团Android岗 |
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(
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执行的顺序 而且上述方法我们可以看出,任务还是会根据 Transform和Task的关系 从这部分源代码其实我们就可以看出,我们注册到 @NonNull public Optional<TaskProvider> addTransform( @NonNull TaskFactory taskFactory, @NonNull TransformVariantScope scope, @NonNull T transform, @Nullable PreConfigAction preConfigAction, @Nullable TaskConfigAction configAction, @Nullable TaskProviderCallback providerCallback) { if (!validateTransform(transform)) { // validate either throws an exception, or records the problem during sync // so it’s safe to just return null here. return Optional.empty(); } List inputStreams = Lists.newArrayList(); String taskName = scope.getTaskName(getTaskNamePrefix(transform)); // get referenced-only streams List referencedStreams = grabReferencedStreams(transform); // find input streams, and compute output streams for the transform. IntermediateStream outputStream = findTransformStreams( transform, scope, inputStreams, taskName, scope.getGlobalScope().getBuildDir()); if (inputStreams.isEmpty() && referencedStreams.isEmpty()) { // didn’t find any match. Means there is a broken order somewhere in the streams. issueReporter.reportError( Type.GENERIC, new EvalIssueException( String.format( “Unable to add Transform ‘%s’ on variant ‘%s’: requested streams not available: %s+%s / %s”, |
|
移动开发 最新文章 |
Vue3装载axios和element-ui |
android adb cmd |
【xcode】Xcode常用快捷键与技巧 |
Android开发中的线程池使用 |
Java 和 Android 的 Base64 |
Android 测试文字编码格式 |
微信小程序支付 |
安卓权限记录 |
知乎之自动养号 |
【Android Jetpack】DataStore |
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/24 6:16:57- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |