use of com.android.build.gradle.internal.ApiObjectFactory in project atlas by alibaba.
the class BasePlugin method createAndroidTasks.
@VisibleForTesting
final void createAndroidTasks(boolean force) {
// Make sure unit tests set the required fields.
checkState(extension.getBuildToolsRevision() != null, "buildToolsVersion is not specified.");
checkState(extension.getCompileSdkVersion() != null, "compileSdkVersion is not specified.");
ndkHandler.setCompileSdkVersion(extension.getCompileSdkVersion());
// get current plugins and look for the default Java plugin.
if (project.getPlugins().hasPlugin(JavaPlugin.class)) {
throw new BadPluginException("The 'java' plugin has been applied, but it is not compatible with the Android plugins.");
}
ensureTargetSetup();
// See AppPluginDslTest
if (!force && (!project.getState().getExecuted() || project.getState().getFailure() != null) && SdkHandler.sTestSdkFolder == null) {
return;
}
if (hasCreatedTasks) {
return;
}
hasCreatedTasks = true;
extension.disableWrite();
ProcessRecorder.getProject(project.getPath()).setBuildToolsVersion(extension.getBuildToolsRevision().toString());
// setup SDK repositories.
sdkHandler.addLocalRepositories(project);
taskManager.addDataBindingDependenciesIfNecessary(extension.getDataBinding());
addDependencies(project);
ThreadRecorder.get().record(ExecutionType.VARIANT_MANAGER_CREATE_ANDROID_TASKS, project.getPath(), null, new Recorder.Block<Void>() {
@Override
public Void call() throws Exception {
variantManager.createAndroidTasks();
ApiObjectFactory apiObjectFactory = new ApiObjectFactory(androidBuilder, extension, variantFactory, instantiator);
for (BaseVariantData variantData : variantManager.getVariantDataList()) {
apiObjectFactory.create(variantData);
}
return null;
}
});
// Create and read external native build JSON files depending on what's happening right
// now.
//
// CREATE PHASE:
// Creates JSONs by shelling out to external build system when:
// - Any one of AndroidProject.PROPERTY_INVOKED_FROM_IDE,
// AndroidProject.PROPERTY_BUILD_MODEL_ONLY_ADVANCED,
// AndroidProject.PROPERTY_BUILD_MODEL_ONLY,
// AndroidProject.PROPERTY_REFRESH_EXTERNAL_NATIVE_MODEL are set.
// - *and* AndroidProject.PROPERTY_REFRESH_EXTERNAL_NATIVE_MODEL is set
// or JSON files don't exist or are out-of-date.
// Create phase may cause ProcessException (from cmake.exe for example)
//
// READ PHASE:
// Reads and deserializes JSONs when:
// - Any one of AndroidProject.PROPERTY_INVOKED_FROM_IDE,
// AndroidProject.PROPERTY_BUILD_MODEL_ONLY_ADVANCED,
// AndroidProject.PROPERTY_BUILD_MODEL_ONLY,
// AndroidProject.PROPERTY_REFRESH_EXTERNAL_NATIVE_MODEL are set.
// Read phase may produce IOException if the file can't be read for standard IO reasons.
// Read phase may produce JsonSyntaxException in the case that the content of the file is
// corrupt.
boolean forceRegeneration = AndroidGradleOptions.refreshExternalNativeModel(project);
if (ExternalNativeBuildTaskUtils.shouldRegenerateOutOfDateJsons(project)) {
ThreadRecorder.get().record(ExecutionType.VARIANT_MANAGER_EXTERNAL_NATIVE_CONFIG_VALUES, project.getPath(), null, new Recorder.Block<Void>() {
@Override
public Void call() throws Exception {
for (BaseVariantData variantData : variantManager.getVariantDataList()) {
ExternalNativeJsonGenerator generator = variantData.getScope().getExternalNativeJsonGenerator();
if (generator != null) {
// This will generate any out-of-date or non-existent JSONs.
// When refreshExternalNativeModel() is true it will also
// force update all JSONs.
generator.build(forceRegeneration);
variantData.getScope().addExternalNativeBuildConfigValues(generator.readExistingNativeBuildConfigurations());
}
}
return null;
}
});
}
}
Aggregations