Search in sources :

Example 1 with BadPluginException

use of com.android.build.gradle.internal.BadPluginException 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;
            }
        });
    }
}
Also used : BaseVariantData(com.android.build.gradle.internal.variant.BaseVariantData) BadPluginException(com.android.build.gradle.internal.BadPluginException) Recorder(com.android.builder.profile.Recorder) ThreadRecorder(com.android.builder.profile.ThreadRecorder) ProcessRecorder(com.android.builder.profile.ProcessRecorder) ExternalNativeJsonGenerator(com.android.build.gradle.tasks.ExternalNativeJsonGenerator) StopExecutionException(org.gradle.api.tasks.StopExecutionException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) UnsupportedVersionException(org.gradle.tooling.UnsupportedVersionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BadPluginException(com.android.build.gradle.internal.BadPluginException) GradleException(org.gradle.api.GradleException) ApiObjectFactory(com.android.build.gradle.internal.ApiObjectFactory) VisibleForTesting(com.android.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.android.annotations.VisibleForTesting)1 ApiObjectFactory (com.android.build.gradle.internal.ApiObjectFactory)1 BadPluginException (com.android.build.gradle.internal.BadPluginException)1 BaseVariantData (com.android.build.gradle.internal.variant.BaseVariantData)1 ExternalNativeJsonGenerator (com.android.build.gradle.tasks.ExternalNativeJsonGenerator)1 ProcessRecorder (com.android.builder.profile.ProcessRecorder)1 Recorder (com.android.builder.profile.Recorder)1 ThreadRecorder (com.android.builder.profile.ThreadRecorder)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 GradleException (org.gradle.api.GradleException)1 StopExecutionException (org.gradle.api.tasks.StopExecutionException)1 UnsupportedVersionException (org.gradle.tooling.UnsupportedVersionException)1