/** * Creates a new builder. */ public Builder() { mConfig = new AaptPackageConfig(); }
/** * Creates a new {@link AaptPackageConfig} from the data already placed in the builder. * * @return the new config */ @NonNull public AaptPackageConfig build() { return mConfig.clone(); }
if (config.isVerbose()) { builder.add("-v"); IAndroidTarget target = config.getAndroidTarget(); Preconditions.checkNotNull(target); builder.add("-I", target.getPath(IAndroidTarget.ANDROID_JAR)); File manifestFile = config.getManifestFile(); Preconditions.checkNotNull(manifestFile); builder.add("--manifest", manifestFile.getAbsolutePath()); if (config.getResourceDir() != null) { Files.walk(config.getResourceDir().toPath()) .filter(Files::isRegularFile) .forEach((p) -> builder.add("-R", p.toString())); } catch (IOException e) { throw new AaptException("Failed to walk path " + config.getResourceDir()); if (config.getSourceOutputDir() != null) { builder.add("--java", config.getSourceOutputDir().getAbsolutePath()); if (config.getResourceOutputApk() != null) { builder.add("-o", config.getResourceOutputApk().getAbsolutePath()); } else { if (config.getProguardOutputFile()!= null) { builder.add("--proguard", config.getProguardOutputFile().getAbsolutePath());
if (packageConfig.getManifestFile() == null) { throw new AaptException("Manifest file not set."); if (packageConfig.getOptions() == null) { throw new AaptException("aapt options not set."); if (packageConfig.getAndroidTarget() == null) { throw new AaptException("Android target not set."); ILogger logger = packageConfig.getLogger(); if (logger == null) { throw new AaptException("Logger not set."); BuildToolInfo buildToolInfo = packageConfig.getBuildToolInfo(); if (buildToolInfo == null) { throw new AaptException("Build tools not set."); if (packageConfig.getVariantType() == null) { throw new AaptException("Variant type not set."); if (packageConfig.getSourceOutputDir() == null && packageConfig.getResourceOutputApk() == null) { throw new AaptException("Neither source output dir nor resource output dir were " + "set, but at least one must be."); if ((packageConfig.getSymbolOutputDir() != null || packageConfig.getSourceOutputDir() != null) && packageConfig.getLibraries().isEmpty()) {
File sourceOut = aaptConfig.getSourceOutputDir(); if (sourceOut != null) { String mainPackageName = aaptConfig.getCustomPackageForR(); if (mainPackageName == null) { File manifestFile = aaptConfig.getManifestFile(); if (manifestFile != null) { try { File mainRTxt = new File(aaptConfig.getSymbolOutputDir(), "R.txt"); SymbolTable mainSymbols = mainRTxt.isFile()? SymbolIo.read(mainRTxt) : SymbolTable.builder().build(); for (AndroidDependency dependency : aaptConfig.getLibraries()) { File depMan = dependency.getManifest(); String depPackageName; if (aaptConfig.getVariantType() == VariantType.LIBRARY) { finalIds = false; } else if (aaptConfig.getVariantType() == VariantType.ATOM && aaptConfig.getBaseFeature() != null) { finalIds = false;
if (config.isVerbose()) { builder.addArgs("-v"); IAndroidTarget target = config.getAndroidTarget(); Preconditions.checkNotNull(target); builder.addArgs("-I", target.getPath(IAndroidTarget.ANDROID_JAR)); File manifestFile = config.getManifestFile(); Preconditions.checkNotNull(manifestFile); builder.addArgs("-M", FileUtils.toExportableSystemDependentPath(manifestFile)); if (config.getResourceDir() != null) { builder.addArgs("-S", config.getResourceDir().getAbsolutePath()); if (config.getSourceOutputDir() != null) { builder.addArgs("-m"); builder.addArgs( "-J", FileUtils.toExportableSystemDependentPath(config.getSourceOutputDir())); if (config.getResourceOutputApk() != null) { builder.addArgs("-F", config.getResourceOutputApk().getAbsolutePath()); if (config.getProguardOutputFile() != null) { builder.addArgs( "-G", FileUtils.toExportableSystemDependentPath(config.getProguardOutputFile())); if (config.getMainDexListProguardOutputFile() != null) { builder.addArgs(
@Override @NonNull public AaptPackageConfig clone() { try { return (AaptPackageConfig) super.clone(); } catch (CloneNotSupportedException e) { /* * Never thrown. Return line should fool the compiler :) */ Verify.verify(false); return new AaptPackageConfig(); } }