use of com.android.sdklib.BuildToolInfo in project android by JetBrains.
the class AndroidApt method packageResources.
public static Map<AndroidCompilerMessageKind, List<String>> packageResources(@NotNull IAndroidTarget target, int platformToolsRevision, @NotNull String manifestPath, @NotNull String[] resPaths, @NotNull String[] osAssetDirPaths, @NotNull String outputPath, @Nullable String configFilter, boolean debugMode, int versionCode, @Nullable String customManifestPackage, @Nullable String additionalParameters, FileFilter assetsFilter) throws IOException {
for (String resDirPath : resPaths) {
if (FileUtil.isAncestor(resDirPath, outputPath, false)) {
throw new IOException("Resource directory " + FileUtil.toSystemDependentName(resDirPath) + " contains output " + FileUtil.toSystemDependentName(outputPath));
}
}
for (String assetsDirPath : osAssetDirPaths) {
if (FileUtil.isAncestor(assetsDirPath, outputPath, false)) {
throw new IOException("Assets directory " + FileUtil.toSystemDependentName(assetsDirPath) + " contains output " + FileUtil.toSystemDependentName(outputPath));
}
}
BuildToolInfo buildToolInfo = target.getBuildToolInfo();
if (buildToolInfo == null) {
return Collections.singletonMap(AndroidCompilerMessageKind.ERROR, Collections.singletonList("No Build Tools in the Android SDK."));
}
final ArrayList<String> args = new ArrayList<String>();
args.add(buildToolInfo.getPath(BuildToolInfo.PathId.AAPT));
args.add(COMMAND_PACKAGE);
for (String path : resPaths) {
args.add("-S");
args.add(path);
}
args.add("-f");
if (platformToolsRevision < 0 || platformToolsRevision > 7) {
args.add("--no-crunch");
}
if (resPaths.length > 1) {
args.add("--auto-add-overlay");
}
if (debugMode) {
args.add("--debug-mode");
}
if (versionCode > 0) {
args.add("--version-code");
args.add(Integer.toString(versionCode));
}
if (configFilter != null) {
args.add("-c");
args.add(configFilter);
}
args.add("-M");
args.add(manifestPath);
File tempDir = null;
try {
if (osAssetDirPaths.length > 0) {
final String[] nonEmptyAssetDirs = getNonEmptyExistingDirs(osAssetDirPaths);
if (nonEmptyAssetDirs.length > 0) {
if (nonEmptyAssetDirs.length == 1) {
args.add("-A");
args.add(nonEmptyAssetDirs[0]);
} else {
tempDir = FileUtil.createTempDirectory("android_combined_assets", "tmp");
for (int i = nonEmptyAssetDirs.length - 1; i >= 0; i--) {
final String assetDir = nonEmptyAssetDirs[i];
FileUtil.copyDir(new File(assetDir), tempDir, assetsFilter);
}
args.add("-A");
args.add(tempDir.getPath());
}
}
}
args.add("-I");
args.add(target.getPath(IAndroidTarget.ANDROID_JAR));
if (customManifestPackage != null) {
args.add("--rename-manifest-package");
args.add(customManifestPackage);
}
if (additionalParameters != null && additionalParameters.length() > 0) {
args.addAll(ParametersListUtil.parse(additionalParameters));
}
args.add("-F");
args.add(outputPath);
LOG.info(AndroidCommonUtils.command2string(args));
return AndroidExecutionUtil.doExecute(ArrayUtil.toStringArray(args));
} finally {
if (tempDir != null) {
FileUtil.delete(tempDir);
}
}
}
use of com.android.sdklib.BuildToolInfo 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;
}
use of com.android.sdklib.BuildToolInfo in project android by JetBrains.
the class AndroidApt method crunch.
public static Map<AndroidCompilerMessageKind, List<String>> crunch(@NotNull IAndroidTarget target, @NotNull List<String> resPaths, @NotNull String outputPath) throws IOException {
BuildToolInfo buildToolInfo = target.getBuildToolInfo();
if (buildToolInfo == null) {
return Collections.singletonMap(AndroidCompilerMessageKind.ERROR, Collections.singletonList("No Build Tools in the Android SDK."));
}
final ArrayList<String> args = new ArrayList<String>();
args.add(buildToolInfo.getPath(BuildToolInfo.PathId.AAPT));
args.add(COMMAND_CRUNCH);
File tempDir = null;
try {
if (resPaths.size() > 0) {
if (resPaths.size() == 1) {
args.add("-S");
args.add(resPaths.get(0));
} else {
tempDir = FileUtil.createTempDirectory("android_combined_resources", "tmp");
for (int i = resPaths.size() - 1; i >= 0; i--) {
final String resDirPath = resPaths.get(i);
final File resDir = new File(resDirPath);
if (resDir.exists()) {
FileUtil.copyDir(resDir, tempDir, PNG_FILES_FILTER);
}
}
args.add("-S");
args.add(tempDir.getPath());
}
}
args.add("-C");
args.add(outputPath);
LOG.info(AndroidCommonUtils.command2string(args));
return AndroidExecutionUtil.doExecute(ArrayUtil.toStringArray(args));
} finally {
if (tempDir != null) {
FileUtil.delete(tempDir);
}
}
}
use of com.android.sdklib.BuildToolInfo in project android by JetBrains.
the class AndroidIdl method execute.
@NotNull
public static Map<AndroidCompilerMessageKind, List<String>> execute(@NotNull IAndroidTarget target, @NotNull String file, @NotNull String outFile, @NotNull String[] sourceRootPaths) throws IOException {
BuildToolInfo buildToolInfo = target.getBuildToolInfo();
if (buildToolInfo == null) {
return Collections.singletonMap(AndroidCompilerMessageKind.ERROR, Collections.singletonList("No Build Tools in the Android SDK."));
}
final List<String> commands = new ArrayList<String>();
final String frameworkAidlPath = target.getPath(IAndroidTarget.ANDROID_AIDL);
commands.add(buildToolInfo.getPath(BuildToolInfo.PathId.AIDL));
commands.add("-p" + frameworkAidlPath);
for (String path : sourceRootPaths) {
commands.add("-I" + path);
}
commands.add(file);
commands.add(outFile);
LOG.info(AndroidCommonUtils.command2string(commands));
return AndroidExecutionUtil.doExecute(ArrayUtil.toStringArray(commands));
}
use of com.android.sdklib.BuildToolInfo in project android by JetBrains.
the class AndroidRenderscript method execute.
public static Map<AndroidCompilerMessageKind, List<String>> execute(@NotNull final String sdkLocation, @NotNull IAndroidTarget target, @NotNull String sourceFilePath, @NotNull final String genFolderPath, @Nullable String depFolderPath, @NotNull final String rawDirPath) throws IOException {
BuildToolInfo buildToolInfo = target.getBuildToolInfo();
if (buildToolInfo == null) {
return Collections.singletonMap(AndroidCompilerMessageKind.ERROR, Collections.singletonList("No Build Tools in the Android SDK."));
}
final List<String> command = new ArrayList<String>();
command.add(buildToolInfo.getPath(BuildToolInfo.PathId.LLVM_RS_CC));
command.add("-I");
command.add(buildToolInfo.getPath(BuildToolInfo.PathId.ANDROID_RS_CLANG));
command.add("-I");
command.add(buildToolInfo.getPath(BuildToolInfo.PathId.ANDROID_RS));
command.add("-p");
command.add(FileUtil.toSystemDependentName(genFolderPath));
command.add("-o");
command.add(FileUtil.toSystemDependentName(rawDirPath));
command.add("-target-api");
int targetApi = target.getVersion().getApiLevel();
if (targetApi < 11) {
targetApi = 11;
}
command.add(Integer.toString(targetApi));
if (depFolderPath != null) {
command.add("-d");
command.add(FileUtil.toSystemDependentName(depFolderPath));
}
command.add("-MD");
command.add(FileUtil.toSystemDependentName(sourceFilePath));
LOG.info(AndroidCommonUtils.command2string(command));
return AndroidExecutionUtil.doExecute(ArrayUtil.toStringArray(command));
}
Aggregations