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 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,

你可能感兴趣的:(程序员,面试,android,移动开发)