Java Code Examples for com.android.sdklib.BuildToolInfo#getPath()

The following examples show how to use com.android.sdklib.BuildToolInfo#getPath() . 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 File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Compiles the given aidl file.
 *
 * @param aidlFile                the AIDL file to compile
 * @param sourceOutputDir         the output dir in which to generate the source code
 * @param importFolders           all the import folders, including the source folders.
 * @param dependencyFileProcessor the dependencyFileProcessor to record the dependencies
 *                                of the compilation.
 * @throws IOException
 * @throws InterruptedException
 * @throws LoggedErrorException
 */
public void compileAidlFile(@NonNull File sourceFolder,
                            @NonNull File aidlFile,
                            @NonNull File sourceOutputDir,
                            @Nullable File parcelableOutputDir,
                            @NonNull List<File> importFolders,
                            @Nullable DependencyFileProcessor dependencyFileProcessor,
                            @NonNull ProcessOutputHandler processOutputHandler)
        throws IOException, InterruptedException, LoggedErrorException, ProcessException {
    checkNotNull(aidlFile, "aidlFile cannot be null.");
    checkNotNull(sourceOutputDir, "sourceOutputDir cannot be null.");
    checkNotNull(importFolders, "importFolders cannot be null.");
    checkState(mTargetInfo != null,
            "Cannot call compileAidlFile() before setTargetInfo() is called.");

    IAndroidTarget target = mTargetInfo.getTarget();
    BuildToolInfo buildToolInfo = mTargetInfo.getBuildTools();

    String aidl = buildToolInfo.getPath(BuildToolInfo.PathId.AIDL);
    if (aidl == null || !new File(aidl).isFile()) {
        throw new IllegalStateException("aidl is missing");
    }

    AidlProcessor processor = new AidlProcessor(
            aidl,
            target.getPath(IAndroidTarget.ANDROID_AIDL),
            importFolders,
            sourceOutputDir,
            parcelableOutputDir,
            dependencyFileProcessor != null ?
                    dependencyFileProcessor : sNoOpDependencyFileProcessor,
            mProcessExecutor,
            processOutputHandler);

    processor.processFile(sourceFolder, aidlFile);
}
 
Example 2
Source File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public Set<String> createMainDexList(
        @NonNull File allClassesJarFile,
        @NonNull File jarOfRoots) throws ProcessException {

    BuildToolInfo buildToolInfo = mTargetInfo.getBuildTools();
    ProcessInfoBuilder builder = new ProcessInfoBuilder();

    String dx = buildToolInfo.getPath(BuildToolInfo.PathId.DX_JAR);
    if (dx == null || !new File(dx).isFile()) {
        throw new IllegalStateException("dx.jar is missing");
    }

    builder.setClasspath(dx);
    builder.setMain("com.android.multidex.ClassReferenceListBuilder");

    builder.addArgs(jarOfRoots.getAbsolutePath());
    builder.addArgs(allClassesJarFile.getAbsolutePath());

    CachedProcessOutputHandler processOutputHandler = new CachedProcessOutputHandler();

    mJavaProcessExecutor.execute(builder.createJavaProcess(), processOutputHandler)
            .rethrowFailure()
            .assertNormalExitValue();

    String content = processOutputHandler.getProcessOutput().getStandardOutputAsString();

    return Sets.newHashSet(Splitter.on('\n').split(content));
}
 
Example 3
Source File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Compiles all the aidl files found in the given source folders.
 *
 * @param sourceFolders           all the source folders to find files to compile
 * @param sourceOutputDir         the output dir in which to generate the source code
 * @param importFolders           import folders
 * @param dependencyFileProcessor the dependencyFileProcessor to record the dependencies
 *                                of the compilation.
 * @throws IOException
 * @throws InterruptedException
 * @throws LoggedErrorException
 */
public void compileAllAidlFiles(@NonNull List<File> sourceFolders,
                                @NonNull File sourceOutputDir,
                                @Nullable File parcelableOutputDir,
                                @NonNull List<File> importFolders,
                                @Nullable DependencyFileProcessor dependencyFileProcessor,
                                @NonNull ProcessOutputHandler processOutputHandler)
        throws IOException, InterruptedException, LoggedErrorException, ProcessException {
    checkNotNull(sourceFolders, "sourceFolders cannot be null.");
    checkNotNull(sourceOutputDir, "sourceOutputDir cannot be null.");
    checkNotNull(importFolders, "importFolders cannot be null.");
    checkState(mTargetInfo != null,
            "Cannot call compileAllAidlFiles() before setTargetInfo() is called.");

    IAndroidTarget target = mTargetInfo.getTarget();
    BuildToolInfo buildToolInfo = mTargetInfo.getBuildTools();

    String aidl = buildToolInfo.getPath(BuildToolInfo.PathId.AIDL);
    if (aidl == null || !new File(aidl).isFile()) {
        throw new IllegalStateException("aidl is missing");
    }

    List<File> fullImportList = Lists.newArrayListWithCapacity(
            sourceFolders.size() + importFolders.size());
    fullImportList.addAll(sourceFolders);
    fullImportList.addAll(importFolders);

    AidlProcessor processor = new AidlProcessor(
            aidl,
            target.getPath(IAndroidTarget.ANDROID_AIDL),
            fullImportList,
            sourceOutputDir,
            parcelableOutputDir,
            dependencyFileProcessor != null ?
                    dependencyFileProcessor : sNoOpDependencyFileProcessor,
            mProcessExecutor,
            processOutputHandler);

    SourceSearcher searcher = new SourceSearcher(sourceFolders, "aidl");
    searcher.setUseExecutor(true);
    searcher.search(processor);
}
 
Example 4
Source File: DexProcessBuilder.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
public JavaProcessInfo build(
        @NonNull BuildToolInfo buildToolInfo,
        @NonNull DexOptions dexOptions) throws ProcessException {

    checkState(
            !mMultiDex
                    || buildToolInfo.getRevision().compareTo(MIN_MULTIDEX_BUILD_TOOLS_REV) >= 0,
            "Multi dex requires Build Tools " +
                    MIN_MULTIDEX_BUILD_TOOLS_REV.toString() +
                    " / Current: " +
                    buildToolInfo.getRevision().toShortString());


    ProcessInfoBuilder builder = new ProcessInfoBuilder();
    builder.addEnvironments(mEnvironment);

    String dx = buildToolInfo.getPath(BuildToolInfo.PathId.DX_JAR);
    if (dx == null || !new File(dx).isFile()) {
        throw new IllegalStateException("dx.jar is missing");
    }

    builder.setClasspath(dx);
    builder.setMain("com.android.dx.command.Main");

    builder.addArgs("--dex");

    if (mVerbose) {
        builder.addArgs("--verbose");
    }

    if (mIncremental) {
        builder.addArgs("--incremental", "--no-strict");
    }

    if (mNoOptimize) {
        builder.addArgs("--no-optimize");
    }

    // only change thread count is build tools is 22.0.2+
    if (buildToolInfo.getRevision().compareTo(MIN_MULTI_THREADED_DEX_BUILD_TOOLS_REV) >= 0) {
        Integer threadCount = dexOptions.getThreadCount();
        if (threadCount == null) {
            builder.addArgs("--num-threads=4");
        } else {
            builder.addArgs("--num-threads=" + threadCount);
        }
    }

    if (mMultiDex) {
        builder.addArgs("--multi-dex");

        if (mMainDexList != null ) {
            builder.addArgs("--main-dex-list", mMainDexList.getAbsolutePath());
        }
    }

    if (mAdditionalParams != null) {
        for (String arg : mAdditionalParams) {
            builder.addArgs(arg);
        }
    }


    builder.addArgs("--output", mOutputFile.getAbsolutePath());

    // input
    builder.addArgs(getFilesToAdd(buildToolInfo));

    return builder.createJavaProcess();
}