Search in sources :

Example 1 with SymbolWriter

use of com.android.sdklib.internal.build.SymbolWriter in project android by JetBrains.

the class AndroidApt method doCompile.

private static Map<AndroidCompilerMessageKind, List<String>> doCompile(@NotNull IAndroidTarget target, @NotNull String manifestFileOsPath, @NotNull String outDirOsPath, @NotNull String[] resourceDirsOsPaths, @NotNull List<Pair<String, String>> libRTxtFilesAndPackages, @Nullable String customPackage, boolean nonConstantIds, @Nullable String proguardCfgOutputFileOsPath, @Nullable String rTxtOutDirOsPath, boolean optimizeRFile) throws IOException {
    final List<String> args = new ArrayList<String>();
    BuildToolInfo buildToolInfo = target.getBuildToolInfo();
    if (buildToolInfo == null) {
        return Collections.singletonMap(AndroidCompilerMessageKind.ERROR, Collections.singletonList("No Build Tools in the Android SDK."));
    }
    args.add(buildToolInfo.getPath(BuildToolInfo.PathId.AAPT));
    args.add("package");
    args.add("-m");
    if (nonConstantIds) {
        args.add("--non-constant-id");
    }
    if (resourceDirsOsPaths.length > 1) {
        args.add("--auto-add-overlay");
    }
    final Set<String> extraPackages = new HashSet<String>();
    for (Pair<String, String> pair : libRTxtFilesAndPackages) {
        extraPackages.add(pair.getSecond());
    }
    if (extraPackages.size() > 0) {
        args.add("--extra-packages");
        args.add(toPackagesString(ArrayUtil.toStringArray(extraPackages)));
    }
    if (customPackage != null) {
        args.add("--custom-package");
        args.add(customPackage);
    }
    if (rTxtOutDirOsPath != null) {
        args.add("--output-text-symbols");
        args.add(rTxtOutDirOsPath);
    }
    args.add("-J");
    args.add(outDirOsPath);
    args.add("-M");
    args.add(manifestFileOsPath);
    for (String libResFolderOsPath : resourceDirsOsPaths) {
        args.add("-S");
        args.add(libResFolderOsPath);
    }
    args.add("-I");
    args.add(target.getPath(IAndroidTarget.ANDROID_JAR));
    if (proguardCfgOutputFileOsPath != null) {
        args.add("-G");
        args.add(proguardCfgOutputFileOsPath);
    }
    final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidExecutionUtil.doExecute(ArrayUtil.toStringArray(args));
    LOG.info(AndroidCommonUtils.command2string(args));
    if (messages.get(AndroidCompilerMessageKind.ERROR).size() > 0) {
        return messages;
    }
    if (optimizeRFile && !libRTxtFilesAndPackages.isEmpty() && rTxtOutDirOsPath != null) {
        final File rFile = new File(rTxtOutDirOsPath, SdkConstants.FN_RESOURCE_TEXT);
        // if the project has no resources the file could not exist.
        if (rFile.isFile()) {
            final SymbolLoader fullSymbolValues = new SymbolLoader(rFile);
            fullSymbolValues.load();
            final MultiMap<String, SymbolLoader> libMap = new MultiMap<String, SymbolLoader>();
            for (Pair<String, String> pair : libRTxtFilesAndPackages) {
                final File rTextFile = new File(pair.getFirst());
                final String libPackage = pair.getSecond();
                if (rTextFile.isFile()) {
                    final SymbolLoader libSymbols = new SymbolLoader(rTextFile);
                    libSymbols.load();
                    libMap.putValue(libPackage, libSymbols);
                }
            }
            for (Map.Entry<String, Collection<SymbolLoader>> entry : libMap.entrySet()) {
                final String libPackage = entry.getKey();
                final Collection<SymbolLoader> symbols = entry.getValue();
                final SymbolWriter writer = new SymbolWriter(outDirOsPath, libPackage, fullSymbolValues);
                for (SymbolLoader symbolLoader : symbols) {
                    writer.addSymbolsToWrite(symbolLoader);
                }
                writer.write();
            }
        }
    }
    return messages;
}
Also used : BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) SymbolLoader(com.android.sdklib.internal.build.SymbolLoader) MultiMap(com.intellij.util.containers.MultiMap) SymbolWriter(com.android.sdklib.internal.build.SymbolWriter) File(java.io.File) HashMap(com.intellij.util.containers.HashMap) MultiMap(com.intellij.util.containers.MultiMap) HashSet(com.intellij.util.containers.HashSet)

Aggregations

BuildToolInfo (com.android.sdklib.BuildToolInfo)1 SymbolLoader (com.android.sdklib.internal.build.SymbolLoader)1 SymbolWriter (com.android.sdklib.internal.build.SymbolWriter)1 HashMap (com.intellij.util.containers.HashMap)1 HashSet (com.intellij.util.containers.HashSet)1 MultiMap (com.intellij.util.containers.MultiMap)1 File (java.io.File)1 AndroidCompilerMessageKind (org.jetbrains.android.util.AndroidCompilerMessageKind)1