Java Code Examples for com.android.builder.core.AndroidBuilder

The following examples show how to use com.android.builder.core.AndroidBuilder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: atlas   Author: alibaba   File: AwoInstaller.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * todo how know which app will be debugged?
 * just support taobao.apk now
 */
private static void notifyApppatching(AndroidBuilder androidBuilder, String patchPkg, Logger logger) {
    CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
    executor.setLogger(logger);
    executor.setCaptureStdOut(true);
    executor.setCaptureStdErr(true);
    //        List<String> killCmd = Arrays.asList("shell", "am", "force-stop", packageNameForPatch);
    //        List<String> startCmd = Arrays.asList("shell", "am", "start", packageNameForPatch + "/" +
    // launcherActivityForPatch);
    List<String> patchCmd = Arrays.asList("shell", "am", "broadcast", "-a", "com.taobao.atlas.intent.PATCH_APP",
                                          "-e", "pkg", patchPkg, "-n",
                                          patchPkg + "/com.taobao.atlas.update.AwoPatchReceiver");
    try {
        executor.executeCommand(androidBuilder.getSdkInfo().getAdb().getAbsolutePath(), patchCmd, false);
    } catch (Exception e) {
        throw new RuntimeException("error while restarting app,you can also restart by yourself", e);
    }
}
 
Example #2
Source Project: atlas   Author: alibaba   File: ProcessAwbAndroidResources.java    License: Apache License 2.0 6 votes vote down vote up
private Aapt makeAapt() throws IOException {
    AndroidBuilder builder = getBuilder();
    MergingLog mergingLog = new MergingLog(getMergeBlameLogFolder());
    FileCache fileCache = appVariantContext.getScope().getGlobalScope().getBuildCache();
    ProcessOutputHandler processOutputHandler =
            new ParsingProcessOutputHandler(
                    new ToolOutputParser(
                            aaptGeneration == AaptGeneration.AAPT_V1
                                    ? new AaptOutputParser()
                                    : new Aapt2OutputParser(),
                            getILogger()),
                    new MergingLogRewriter(mergingLog::find, builder.getErrorReporter()));

    return AaptGradleFactory.make(
            aaptGeneration,
            builder,
            processOutputHandler,
            fileCache,
            true,
            FileUtils.mkdirs(new File(getIncrementalFolder(), "awb-aapt-temp/"+awbBundle.getName())),
            aaptOptions.getCruncherProcesses());
}
 
Example #3
Source Project: atlas   Author: alibaba   File: AwbApkPackageTask.java    License: Apache License 2.0 6 votes vote down vote up
public AwbApkPackageTask(FileCollection resourceFiles, VariantContext variantContext, AwbBundle awbBundle, AppVariantOutputContext appVariantOutputContext, FileCollection dexFolders,
                         FileCollection javaResouresFiles, FileCollection assets, FileCollection jniFolders, FileCollection awbManifestFolder, AndroidBuilder androidBuilder,
                         int miniSdkVersion, String taskName) {
    this.packagingScope = new DefaultGradlePackagingScope(variantContext.getScope());
    this.resourceFiles = resourceFiles;
    this.outputScope = variantContext.getScope().getOutputScope();
    this.awbBundle = awbBundle;
    this.appVariantOutputContext = appVariantOutputContext;
    this.outputDirectory = ((AppVariantContext) variantContext).getAwbApkOutputDir();
    this.dexFolders = dexFolders;
    this.javaResouresFiles = javaResouresFiles;
    this.assets = assets;
    this.jniFolders = jniFolders;
    this.awbManifestFolder = awbManifestFolder;
    this.instantRunContext = packagingScope.getInstantRunBuildContext();
    this.signingConfig = packagingScope.getSigningConfig();
    this.androidBuilder = androidBuilder;
    this.miniSdkVersion = miniSdkVersion;
    this.debug = packagingScope.isDebuggable();
    supportAbis = packagingScope.getSupportedAbis();
    this.jniDebug = packagingScope.isJniDebuggable();
    aaptOptionsNoCompress = packagingScope.getAaptOptions().getNoCompress();
    this.taskName = taskName;


}
 
Example #4
Source Project: atlas   Author: alibaba   File: TPatchDiffResAPBuildTask.java    License: Apache License 2.0 6 votes vote down vote up
private Aapt makeAapt(AaptGeneration aaptGeneration) throws IOException {
    AndroidBuilder builder = getBuilder();
    MergingLog mergingLog = new MergingLog(mergeBlameLogFolder);

    ProcessOutputHandler processOutputHandler =
            new ParsingProcessOutputHandler(
                    new ToolOutputParser(
                            aaptGeneration == AaptGeneration.AAPT_V1
                                    ? new AaptOutputParser()
                                    : new Aapt2OutputParser(),
                            getILogger()),
                    new MergingLogRewriter(mergingLog::find, builder.getErrorReporter()));

    return AaptGradleFactory.make(
            aaptGeneration,
            builder,
        processOutputHandler,
        fileCache,
        true,
        com.android.utils.FileUtils.mkdirs(new File(appVariantContext.getScope().getIncrementalDir(getName()),
            "aapt-temp")),
            aaptOptions.getCruncherProcesses());
}
 
Example #5
Source Project: atlas   Author: alibaba   File: AtlasConfigurationHelper.java    License: Apache License 2.0 6 votes vote down vote up
public void createBuilderAfterEvaluate() throws Exception {

        AndroidBuilder androidBuilder = appPluginHook.getAndroidBuilder();

        if (null == androidBuilder) {
            return;
        }

        AndroidBuilder atlasBuilder = new AtlasBuilder(project.equals(project.getRootProject()) ? project
                .getName() : project.getPath(),
                creator,
                new GradleProcessExecutor(project),
                new GradleJavaProcessExecutor(project),
                DefaultGroovyMethods.asType(ReflectUtils.getField(
                        androidBuilder,
                        "mErrorReporter"),
                        ErrorReporter.class),
                LoggerWrapper.getLogger(AtlasBuilder.class),
                DefaultGroovyMethods.asType(ReflectUtils.getField(
                        androidBuilder,
                        "mVerboseExec"), Boolean.class));

        ((AtlasBuilder) atlasBuilder).setDefaultBuilder(androidBuilder);
        ((AtlasBuilder) atlasBuilder).setAtlasExtension(atlasExtension);
        AtlasBuildContext.androidBuilderMap.put(project, (AtlasBuilder) (atlasBuilder));
    }
 
Example #6
Source Project: atlas   Author: alibaba   File: BuildHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static synchronized File doZipAlign(final AndroidBuilder androidBuilder, Project project, final File apkFile) {

        final File zipalignedFile = new File(apkFile.getParent(), apkFile.getName().replace(".apk", "-zipaligned.apk"));

        project.exec(new Action<ExecSpec>() {
            @Override
            public void execute(ExecSpec execSpec) {

                String path = androidBuilder.getTargetInfo()
                        .getBuildTools().getPath(ZIP_ALIGN);
                execSpec.executable(new File(path));
                execSpec.args("-f", "4");
                execSpec.args(apkFile);
                execSpec.args(zipalignedFile);
            }
        });

        return zipalignedFile;
    }
 
Example #7
Source Project: atlas   Author: alibaba   File: ZipAlignUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static synchronized File doZipAlign(final AndroidBuilder androidBuilder, Project project, final File apkFile) {

        final File zipalignedFile = new File(apkFile.getParent(), apkFile.getName().replace(".apk", "-zipaligned.apk"));

        project.exec(new Action<ExecSpec>() {
            @Override
            public void execute(ExecSpec execSpec) {

                String path = androidBuilder.getTargetInfo()
                        .getBuildTools().getPath(ZIP_ALIGN);
                execSpec.executable(new File(path));
                execSpec.args("-f", "4");
                execSpec.args(apkFile);
                execSpec.args(zipalignedFile);
            }
        });

        return zipalignedFile;
    }
 
Example #8
Source Project: javaide   Author: tranleduy2000   File: ProcessManifest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(@NonNull ProcessManifest processManifest) {
    final VariantConfiguration config = scope.getVariantConfiguration();
    final AndroidBuilder androidBuilder = scope.getGlobalScope().getAndroidBuilder();

    // get single output for now.
    final BaseVariantOutputData variantOutputData = scope.getVariantData().getOutputs().get(0);

    variantOutputData.manifestProcessorTask = processManifest;
    processManifest.setAndroidBuilder(androidBuilder);
    processManifest.setVariantName(config.getFullName());

    processManifest.setVariantConfiguration(config);

    final ProductFlavor mergedFlavor = config.getMergedFlavor();
    processManifest.setMinSdkVersion(getMinSdkVersion(androidBuilder, mergedFlavor, processManifest));
    processManifest.setTargetSdkVersion(getTargetSdkVersion(androidBuilder, mergedFlavor, processManifest));
    processManifest.setMaxSdkVersion(getMaxSdkVersion(androidBuilder, mergedFlavor));
    processManifest.setManifestOutputFile(variantOutputData.getScope().getManifestOutputFile());

    processManifest.setAaptFriendlyManifestOutputFile(
            new File(scope.getGlobalScope().getIntermediatesDir(),
                    TaskManager.DIR_BUNDLES + "/" + config.getDirName() + "/aapt/AndroidManifest.xml"));
}
 
Example #9
Source Project: javaide   Author: tranleduy2000   File: AppPlugin.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected TaskManager createTaskManager(
        Project project,
        AndroidBuilder androidBuilder,
        AndroidConfig extension,
        SdkHandler sdkHandler,
        DependencyManager dependencyManager,
        ToolingModelBuilderRegistry toolingRegistry) {
    return new ApplicationTaskManager(
            project,
            androidBuilder,
            extension,
            sdkHandler,
            dependencyManager,
            toolingRegistry);
}
 
Example #10
Source Project: javaide   Author: tranleduy2000   File: ProductFlavor.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds a new field to the generated BuildConfig class.
 * <p>
 * The field is generated as:
 * <p>
 * <type> <name> = <value>;
 * <p>
 * This means each of these must have valid Java content. If the type is a String, then the
 * value should include quotes.
 *
 * @param type  the type of the field
 * @param name  the name of the field
 * @param value the value of the field
 */
public void buildConfigField(
        @NonNull String type,
        @NonNull String name,
        @NonNull String value) {
    ClassField alreadyPresent = getBuildConfigFields().get(name);
    if (alreadyPresent != null) {
        String flavorName = getName();
        if (BuilderConstants.MAIN.equals(flavorName)) {
            logger.info(
                    "DefaultConfig: buildConfigField '{}' value is being replaced: {} -> {}",
                    name, alreadyPresent.getValue(), value);
        } else {
            logger.info(
                    "ProductFlavor({}): buildConfigField '{}' "
                            + "value is being replaced: {} -> {}",
                    flavorName, name, alreadyPresent.getValue(), value);
        }
    }
    addBuildConfigField(AndroidBuilder.createClassField(type, name, value));
}
 
Example #11
Source Project: javaide   Author: tranleduy2000   File: ProductFlavor.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds a new generated resource.
 * <p>
 * <p>This is equivalent to specifying a resource in res/values.
 * <p>
 * <p>See <a href="http://developer.android.com/guide/topics/resources/available-resources.html">Resource Types</a>.
 *
 * @param type  the type of the resource
 * @param name  the name of the resource
 * @param value the value of the resource
 */
public void resValue(
        @NonNull String type,
        @NonNull String name,
        @NonNull String value) {
    ClassField alreadyPresent = getResValues().get(name);
    if (alreadyPresent != null) {
        String flavorName = getName();
        if (BuilderConstants.MAIN.equals(flavorName)) {
            logger.info(
                    "DefaultConfig: resValue '{}' value is being replaced: {} -> {}",
                    name, alreadyPresent.getValue(), value);
        } else {
            logger.info(
                    "ProductFlavor({}): resValue '{}' value is being replaced: {} -> {}",
                    flavorName, name, alreadyPresent.getValue(), value);
        }
    }
    addResValue(AndroidBuilder.createClassField(type, name, value));
}
 
Example #12
Source Project: javaide   Author: tranleduy2000   File: TaskManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
public TaskManager(
        Project project,
        AndroidBuilder androidBuilder,
        AndroidConfig extension,
        SdkHandler sdkHandler,
        DependencyManager dependencyManager,
        ToolingModelBuilderRegistry toolingRegistry) {
    this.project = project;
    this.androidBuilder = androidBuilder;
    this.sdkHandler = sdkHandler;
    this.extension = extension;
    this.toolingRegistry = toolingRegistry;
    this.dependencyManager = dependencyManager;
    logger = Logging.getLogger(this.getClass());

    globalScope = new GlobalScope(
            project,
            androidBuilder,
            checkNotNull((String) project.getProperties().get("archivesBaseName")),
            extension,
            sdkHandler,
            toolingRegistry);
}
 
Example #13
Source Project: javaide   Author: tranleduy2000   File: GlobalScope.java    License: GNU General Public License v3.0 6 votes vote down vote up
public GlobalScope(
        @NonNull Project project,
        @NonNull AndroidBuilder androidBuilder,
        @NonNull String projectBaseName,
        @NonNull AndroidConfig extension,
        @NonNull SdkHandler sdkHandler,
        @NonNull ToolingModelBuilderRegistry toolingRegistry) {
    this.project = project;
    this.androidBuilder = androidBuilder;
    this.projectBaseName = projectBaseName;
    this.extension = extension;
    this.sdkHandler = sdkHandler;
    this.toolingRegistry = toolingRegistry;
    intermediatesDir = new File(getBuildDir(), FD_INTERMEDIATES);
    generatedDir = new File(getBuildDir(), FD_GENERATED);
    reportsDir = new File(getBuildDir(), FD_REPORTS);
    outputsDir = new File(getBuildDir(), FD_OUTPUTS);
}
 
Example #14
Source Project: javaide   Author: tranleduy2000   File: VariantManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
public VariantManager(
        @NonNull Project project,
        @NonNull AndroidBuilder androidBuilder,
        @NonNull AndroidConfig extension,
        @NonNull VariantFactory variantFactory,
        @NonNull TaskManager taskManager,
        @NonNull Instantiator instantiator) {
    this.extension = extension;
    this.androidBuilder = androidBuilder;
    this.project = project;
    this.variantFactory = variantFactory;
    this.taskManager = taskManager;
    this.instantiator = instantiator;

    DefaultAndroidSourceSet mainSourceSet =
            (DefaultAndroidSourceSet) extension.getSourceSets().getByName(extension.getDefaultConfig().getName());

    defaultConfigData = new ProductFlavorData<>(
            extension.getDefaultConfig(), mainSourceSet,
            project);
    signingOverride = createSigningOverride();
}
 
Example #15
Source Project: javafxmobile-plugin   Author: javafxports   File: MergeResources.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Aapt makeAapt(
        BuildToolInfo buildToolInfo,
        AaptGeneration aaptGeneration,
        AndroidBuilder builder,
        boolean crunchPng,
        MergingLog blameLog) {
    ProcessOutputHandler teeOutputHandler =
            new TeeProcessOutputHandler(
                    blameLog != null
                            ? new ParsingProcessOutputHandler(
                            new ToolOutputParser(
                                    aaptGeneration == AaptGeneration.AAPT_V1
                                            ? new AaptOutputParser()
                                            : new Aapt2OutputParser(),
                                    builder.getLogger()),
                            new MergingLogRewriter(blameLog::find, builder.getErrorReporter()))
                            : new LoggedProcessOutputHandler(
                            new AaptGradleFactory.FilteringLogger(builder.getLogger())),
                    new LoggedProcessOutputHandler(new AaptGradleFactory.FilteringLogger(builder.getLogger())));

    return new AaptV1(
            builder.getProcessExecutor(),
            teeOutputHandler,
            buildToolInfo,
            new AaptGradleFactory.FilteringLogger(builder.getLogger()),
            crunchPng ? AaptV1.PngProcessMode.ALL : AaptV1.PngProcessMode.NO_CRUNCH,
            0);
}
 
Example #16
Source Project: atlas   Author: alibaba   File: AwoInstaller.java    License: Apache License 2.0 5 votes vote down vote up
public static void installTPatch(AndroidBuilder androidBuilder, File tPatchFile, File updateInfoFile,
                                 String packageName, Logger logger) {
    try {
        installPatchIfDeviceConnected(androidBuilder, tPatchFile, packageName, logger, tPatchFile.getName());
        installPatchIfDeviceConnected(androidBuilder, updateInfoFile, packageName, logger,
                                      FilenameUtils.getBaseName(tPatchFile.getName()) + ".json");
        notifyApppatching(androidBuilder, packageName, logger);
    } catch (Throwable e) {
        throw new GradleException("install awo error", e);
    }
}
 
Example #17
Source Project: atlas   Author: alibaba   File: AwoInstaller.java    License: Apache License 2.0 5 votes vote down vote up
public static void installAwoSo(AndroidBuilder androidBuilder, File maindexFile, Collection<File> awoSoFiles,
                                String packageName, Logger logger) {
    try {
        if (maindexFile != null) {
            if (!maindexFile.exists()) {
                throw new IllegalArgumentException(
                    "maindexFile file " + maindexFile.getAbsolutePath() + " does not exist.");
            }

            installPatchIfDeviceConnected(androidBuilder, maindexFile, packageName, logger,
                                          "libcom_taobao_maindex.so");
        }
        if (awoSoFiles != null) {
            for (File awoSoFile : awoSoFiles) {
                if (!awoSoFile.exists()) {
                    throw new IllegalArgumentException(
                        "awoSoFile file " + awoSoFile.getAbsolutePath() + " does not exist.");
                }

                installPatchIfDeviceConnected(androidBuilder, awoSoFile, packageName, logger, awoSoFile.getName());
            }
        }
        notifyApppatching(androidBuilder, packageName, logger);
    } catch (Throwable e) {
        throw new GradleException("install awo error", e);
    }
}
 
Example #18
Source Project: atlas   Author: alibaba   File: AwoInstaller.java    License: Apache License 2.0 5 votes vote down vote up
public static void installAwoSo(AndroidBuilder androidBuilder, File awoSoFile, String packageName, Logger logger,
                                String name) {

    try {
        installPatchIfDeviceConnected(androidBuilder, awoSoFile, packageName, logger, name);
        notifyApppatching(androidBuilder, packageName, logger);
    } catch (Throwable e) {
        throw new GradleException("install awo error", e);
    }
}
 
Example #19
Source Project: atlas   Author: alibaba   File: AwoInstaller.java    License: Apache License 2.0 5 votes vote down vote up
protected static AndroidDebugBridge initAndroidDebugBridge(AndroidBuilder androidBuilder) {
    synchronized (ADB_LOCK) {
        if (!adbInitialized) {
            DdmPreferences.setTimeOut(adbConnectionTimeout);
            AndroidDebugBridge.init(false);
            adbInitialized = true;
        }
        AndroidDebugBridge androidDebugBridge = AndroidDebugBridge.createBridge(
            androidBuilder.getSdkInfo().getAdb().getAbsolutePath(), false);
        waitUntilConnected(androidDebugBridge);
        return androidDebugBridge;
    }
}
 
Example #20
Source Project: atlas   Author: alibaba   File: MergeAwbResource.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
private static Aapt makeAapt(
        @NonNull AaptGeneration aaptGeneration,
        @NonNull AndroidBuilder builder,
        @Nullable FileCache fileCache,
        boolean crunchPng,
        @NonNull VariantScope scope,
        @NonNull File intermediateDir,
        @Nullable MergingLog blameLog)
        throws IOException {
    return AaptGradleFactory.make(
            aaptGeneration,
            builder,
            blameLog != null
                    ? new ParsingProcessOutputHandler(
                    new ToolOutputParser(
                            aaptGeneration == AaptGeneration.AAPT_V1
                                    ? new AaptOutputParser()
                                    : new Aapt2OutputParser(),
                            builder.getLogger()),
                    new MergingLogRewriter(blameLog::find, builder.getErrorReporter()))
                    : new LoggedProcessOutputHandler(
                    new AaptGradleFactory.FilteringLogger(builder.getLogger())),
            fileCache,
            crunchPng,
            intermediateDir,
            scope.getGlobalScope().getExtension().getAaptOptions().getCruncherProcesses());
}
 
Example #21
Source Project: atlas   Author: alibaba   File: ProcessAwbAndroidResources.java    License: Apache License 2.0 5 votes vote down vote up
public ConfigAction(VariantScope scope, File symbolLocation, boolean generateResourcePackage, AwbBundle awbBundle, AndroidBuilder androidBuilder, AppVariantOutputContext appVariantOutputContext, BaseVariantOutput variantOutput) {
    this.scope = scope;
    this.symbolLocation = symbolLocation;
    this.generateResourcePackage = generateResourcePackage;
    this.awbBundle = awbBundle;
    this.tAndroidBuilder = androidBuilder;
    this.appVariantOutputContext = appVariantOutputContext;
    this.variantOutput = variantOutput;
}
 
Example #22
Source Project: javaide   Author: tranleduy2000   File: ProcessManifest.java    License: GNU General Public License v3.0 5 votes vote down vote up
private Integer getMaxSdkVersion(AndroidBuilder androidBuilder, ProductFlavor mergedFlavor) {
    if (androidBuilder.isPreviewTarget()) {
        return null;
    }

    return mergedFlavor.getMaxSdkVersion();
}
 
Example #23
Source Project: javaide   Author: tranleduy2000   File: ProcessManifest.java    License: GNU General Public License v3.0 5 votes vote down vote up
private String getTargetSdkVersion(AndroidBuilder androidBuilder, ProductFlavor mergedFlavor, ProcessManifest processManifest) {
    if (androidBuilder.isPreviewTarget()) {
        return androidBuilder.getTargetCodename();
    }

    final ApiVersion version = mergedFlavor.getTargetSdkVersion();
    return (version == null ? null : version.getApiString());
}
 
Example #24
Source Project: javaide   Author: tranleduy2000   File: ProcessManifest.java    License: GNU General Public License v3.0 5 votes vote down vote up
private String getMinSdkVersion(AndroidBuilder androidBuilder, ProductFlavor mergedFlavor, ProcessManifest processManifest) {

            if (androidBuilder.isPreviewTarget()) {
                return androidBuilder.getTargetCodename();
            }

            final ApiVersion version = mergedFlavor.getMinSdkVersion();
            return (version == null ? null : version.getApiString());
        }
 
Example #25
Source Project: javaide   Author: tranleduy2000   File: AppExtension.java    License: GNU General Public License v3.0 5 votes vote down vote up
public AppExtension(@NonNull ProjectInternal project, @NonNull Instantiator instantiator,
                    @NonNull AndroidBuilder androidBuilder, @NonNull SdkHandler sdkHandler,
                    @NonNull NamedDomainObjectContainer<BuildType> buildTypes,
                    @NonNull NamedDomainObjectContainer<ProductFlavor> productFlavors,
                    @NonNull NamedDomainObjectContainer<SigningConfig> signingConfigs,
                    @NonNull ExtraModelInfo extraModelInfo, boolean isLibrary) {
    super(project, instantiator, androidBuilder, sdkHandler, buildTypes, productFlavors,
            signingConfigs, extraModelInfo, isLibrary);
}
 
Example #26
Source Project: javaide   Author: tranleduy2000   File: BaseComponentModelPlugin.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Model(ANDROID_BUILDER)
public AndroidBuilder createAndroidBuilder(Project project, ExtraModelInfo extraModelInfo) {
    String creator = "Android Gradle";
    ILogger logger = new LoggerWrapper(project.getLogger());

    return new AndroidBuilder(project.equals(project.getRootProject()) ? project.getName()
            : project.getPath(), creator, new GradleProcessExecutor(project),
            new GradleJavaProcessExecutor(project),
            extraModelInfo, logger, project.getLogger().isEnabled(LogLevel.INFO));

}
 
Example #27
Source Project: javaide   Author: tranleduy2000   File: BaseComponentModelPlugin.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void createAndroidComponents(
        ComponentSpecContainer androidSpecs,
        ServiceRegistry serviceRegistry, AndroidConfig androidExtension,
        com.android.build.gradle.AndroidConfig adaptedModel,
        @Path("android.buildTypes") ModelMap<BuildType> buildTypes,
        @Path("android.productFlavors") ModelMap<ProductFlavor> productFlavors,
        @Path("android.signingConfigs") ModelMap<SigningConfig> signingConfigs,
        VariantFactory variantFactory,
        TaskManager taskManager,
        Project project,
        AndroidBuilder androidBuilder,
        SdkHandler sdkHandler,
        ExtraModelInfo extraModelInfo,
        @Path("isApplication") Boolean isApplication) {
    Instantiator instantiator = serviceRegistry.get(Instantiator.class);

    // check if the target has been set.
    TargetInfo targetInfo = androidBuilder.getTargetInfo();
    if (targetInfo == null) {
        sdkHandler.initTarget(androidExtension.getCompileSdkVersion(),
                androidExtension.getBuildToolsRevision(),
                androidExtension.getLibraryRequests(), androidBuilder);
    }

    VariantManager variantManager = new VariantManager(project, androidBuilder,
            adaptedModel, variantFactory, taskManager, instantiator);

    for (BuildType buildType : buildTypes.values()) {
        variantManager.addBuildType(new BuildTypeAdaptor(buildType));
    }

    for (ProductFlavor productFlavor : productFlavors.values()) {
        variantManager.addProductFlavor(new ProductFlavorAdaptor(productFlavor));
    }

    DefaultAndroidComponentSpec spec =
            (DefaultAndroidComponentSpec) androidSpecs.get(COMPONENT_NAME);
    spec.setExtension(androidExtension);
    spec.setVariantManager(variantManager);
}
 
Example #28
Source Project: javaide   Author: tranleduy2000   File: BasePlugin.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected abstract TaskManager createTaskManager(
Project project,
AndroidBuilder androidBuilder,
AndroidConfig extension,
SdkHandler sdkHandler,
DependencyManager dependencyManager,
ToolingModelBuilderRegistry toolingRegistry);
 
Example #29
Source Project: javaide   Author: tranleduy2000   File: BasePlugin.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void configureProject() {
        extraModelInfo = new ExtraModelInfo(project, isLibrary());
        sdkHandler = new SdkHandler(project, getLogger());
        androidBuilder = new AndroidBuilder(
                project == project.getRootProject() ? project.getName() : project.getPath(),
                "Android Gradle Java N-IDE",
                new GradleProcessExecutor(project),
                new GradleJavaProcessExecutor(project),
                extraModelInfo,
                getLogger(),
                isVerbose());

//        project.getPlugins().apply(JavaBasePlugin.class);

        // call back on execution. This is called after the whole build is done (not
        // after the current project is done).
        // This is will be called for each (android) projects though, so this should support
        // being called 2+ times.
        project.getGradle().getTaskGraph().addTaskExecutionGraphListener(
                new TaskExecutionGraphListener() {
                    @Override
                    public void graphPopulated(TaskExecutionGraph taskGraph) {
                        for (Task task : taskGraph.getAllTasks()) {
                            if (task instanceof PreDex) {
                                PreDexCache.getCache().load(
                                        new File(project.getRootProject().getBuildDir(),
                                                FD_INTERMEDIATES + "/dex-cache/cache.xml"));
                                break;
                            }
                        }
                    }
                });
    }
 
Example #30
Source Project: javaide   Author: tranleduy2000   File: BuildType.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds a new generated resource.
 *
 * @param type  the type of the resource
 * @param name  the name of the resource
 * @param value the value of the resource
 */
public void resValue(
        @NonNull String type,
        @NonNull String name,
        @NonNull String value) {
    ClassField alreadyPresent = getResValues().get(name);
    if (alreadyPresent != null) {
        logger.info("BuildType({}): resValue '{}' value is being replaced: {} -> {}",
                getName(), name, alreadyPresent.getValue(), value);
    }
    addResValue(AndroidBuilder.createClassField(type, name, value));
}