public void assertThatBuildToolsVersionIsAtLeast( String version, String feature ) throws InvalidSdkException, NumberFormatException { if ( getBuildToolInfo().getRevision(). compareTo( Revision.parseRevision( version ) ) < 0 ) { throw new InvalidSdkException( "Version of build tools must be at least " + version + " for " + feature + " to work" ); } }
/** * Get the path for build-tools lib directory * @return */ public String getBuildToolsLibDirectoryPath() { File buildToolsLib = new File( getBuildToolInfo().getLocation(), "lib" ); if ( buildToolsLib.exists() ) { return buildToolsLib.getAbsolutePath(); } throw new InvalidSdkException( "Cannot find " + buildToolsLib ); }
private String getPathForBuildTool( BuildToolInfo.PathId pathId ) { return getBuildToolInfo().getPath( pathId ); }
String aapt = buildToolInfo.getPath(BuildToolInfo.PathId.AAPT); if (aapt == null) { throw new IllegalStateException( "Unable to get aapt location from Build Tools " + buildToolInfo.getRevision());
@NonNull private File getZipAlignExe() throws TransformException { final TargetInfo info = androidBuilder.getTargetInfo(); if (info == null) { throw new TransformException("Cannot find zipAlign executable, no target info set"); } String path1 = info.getBuildTools().getPath(ZIP_ALIGN); if (path1 == null) { throw new TransformException("Cannot find zipAlign executable for build tools " + info.getBuildTools().getLocation()); } return new File(path1); }
.orElseThrow(() -> new IllegalStateException("Cannot load Jill from build tools.")); BuildToolInfo.JackVersion apiVersion = buildToolInfo.getSupportedJackApi(); String.format( "jack.jar from build tools %s does not support Jack API v%d.", buildToolInfo.getRevision().toString(), apiVersion.getVersion()); throw new ToolchainException(errorMessage, e);
@NonNull File zipAlign, @Nullable File aapt2) { BuildToolInfo result = new BuildToolInfo(revision, mainPath); result.add(AAPT, aapt); result.add(AIDL, aidl); result.add(DX, dx); result.add(DX_JAR, dxJar); result.add(LLVM_RS_CC, llmvRsCc); result.add(ANDROID_RS, androidRs); result.add(ANDROID_RS_CLANG, androidRsClang); result.add(ZIP_ALIGN, zipAlign); result.add(BCC_COMPAT, bccCompat); } else if (BCC_COMPAT.isPresentIn(revision)) { throw new IllegalArgumentException("BCC_COMPAT required in " + revision.toString()); result.add(LD_ARM, ldArm); } else if (LD_ARM.isPresentIn(revision)) { throw new IllegalArgumentException("LD_ARM required in " + revision.toString()); result.add(LD_ARM64, ldArm64); } else if (LD_ARM64.isPresentIn(revision)) { throw new IllegalArgumentException("LD_ARM64 required in " + revision.toString()); result.add(LD_X86, ldX86); } else if (LD_X86.isPresentIn(revision)) { throw new IllegalArgumentException("LD_X86 required in " + revision.toString());
/** * Creates a {@link BuildToolInfo} from a {@link LocalPackage}. */ @NonNull public static BuildToolInfo fromLocalPackage(@NonNull LocalPackage localPackage) { checkNotNull(localPackage, "localPackage"); checkArgument( localPackage.getPath().contains(SdkConstants.FD_BUILD_TOOLS), "%s package required.", SdkConstants.FD_BUILD_TOOLS); return fromStandardDirectoryLayout(localPackage.getVersion(), localPackage.getLocation()); }
@NonNull @Override public TargetInfo getTargetInfo(@NonNull String targetHash, @NonNull FullRevision buildToolRevision, @NonNull ILogger logger) { init(logger); IAndroidTarget androidTarget = new FakeAndroidTarget(mTreeLocation.getPath(), targetHash); File hostTools = getHostToolsFolder(); BuildToolInfo buildToolInfo = new BuildToolInfo( buildToolRevision, mTreeLocation, new File(hostTools, FN_AAPT), new File(hostTools, FN_AIDL), new File(mTreeLocation, "prebuilts/sdk/tools/dx"), new File(mTreeLocation, "prebuilts/sdk/tools/lib/dx.jar"), new File(hostTools, FN_RENDERSCRIPT), new File(mTreeLocation, "prebuilts/sdk/renderscript/include"), new File(mTreeLocation, "prebuilts/sdk/renderscript/clang-include"), new File(hostTools, FN_BCC_COMPAT), new File(hostTools, "arm-linux-androideabi-ld"), new File(hostTools, "i686-linux-android-ld"), new File(hostTools, "mipsel-linux-android-ld"), new File(hostTools, FN_ZIPALIGN)); return new TargetInfo(androidTarget, buildToolInfo); }
@NonNull private BuildToolInfo createLegacyBuildTools(@NonNull LocalPlatformToolPkgInfo ptInfo) { File platformTools = new File(getLocation(), SdkConstants.FD_PLATFORM_TOOLS); File platformToolsLib = ptInfo.getLocalDir(); File platformToolsRs = new File(platformTools, SdkConstants.FN_FRAMEWORK_RENDERSCRIPT); return BuildToolInfo.modifiedLayout( ptInfo.getDesc().getRevision(), platformTools, new File(platformTools, SdkConstants.FN_AAPT), new File(platformTools, SdkConstants.FN_AIDL), new File(platformTools, SdkConstants.FN_DX), new File(platformToolsLib, SdkConstants.FN_DX_JAR), new File(platformTools, SdkConstants.FN_RENDERSCRIPT), new File(platformToolsRs, SdkConstants.FN_FRAMEWORK_INCLUDE), new File(platformToolsRs, SdkConstants.FN_FRAMEWORK_INCLUDE_CLANG), null, null, null, null, null, null, new File(platformTools, SdkConstants.FN_ZIPALIGN), null); }
String aapt = buildToolInfo.getPath(BuildToolInfo.PathId.AAPT); if (aapt == null) { throw new IllegalStateException( "Unable to get aapt location from Build Tools " + buildToolInfo.getRevision());
private void scanBuildTools(File collectionDir, Collection<LocalPkgInfo> outCollection) { // The build-tool root folder contains a list of per-revision folders. for (File buildToolDir : mFileOp.listFiles(collectionDir)) { if (!shouldVisitDir(PkgType.PKG_BUILD_TOOLS, buildToolDir)) { continue; } Properties props = parseProperties(new File(buildToolDir, SdkConstants.FN_SOURCE_PROP)); Revision rev = PackageParserUtils.getRevisionProperty(props, PkgProps.PKG_REVISION); if (rev == null) { continue; // skip, no revision } // Since we used to require a complete revision rev = fullySpecifyRevision(rev); BuildToolInfo btInfo = BuildToolInfo.fromStandardDirectoryLayout(rev, buildToolDir); LocalBuildToolPkgInfo pkgInfo = new LocalBuildToolPkgInfo(this, buildToolDir, props, rev, btInfo); outCollection.add(pkgInfo); } }
/** * Creates a {@link BuildToolInfo} from a directory which follows the standard layout * convention. */ @NonNull public static BuildToolInfo fromStandardDirectoryLayout( @NonNull Revision revision, @NonNull File path) { return new BuildToolInfo(revision, path); }
@NonNull @Override public TargetInfo getTargetInfo( @NonNull String targetHash, @NonNull Revision buildToolRevision, @NonNull ILogger logger, @NonNull SdkLibData sdkLibData) { init(logger); IAndroidTarget androidTarget = new FakeAndroidTarget(mTreeLocation.getPath(), targetHash); File hostTools = getHostToolsFolder(); BuildToolInfo buildToolInfo = BuildToolInfo.modifiedLayout( buildToolRevision, mTreeLocation, new File(hostTools, FN_AAPT), new File(hostTools, FN_AIDL), new File(mTreeLocation, "prebuilts/sdk/tools/dx"), new File(mTreeLocation, "prebuilts/sdk/tools/lib/dx.jar"), new File(hostTools, FN_RENDERSCRIPT), new File(mTreeLocation, "prebuilts/sdk/renderscript/include"), new File(mTreeLocation, "prebuilts/sdk/renderscript/clang-include"), new File(hostTools, FN_BCC_COMPAT), new File(hostTools, "arm-linux-androideabi-ld"), new File(hostTools, "aarch64-linux-android-ld"), new File(hostTools, "i686-linux-android-ld"), new File(hostTools, "x86_64-linux-android-ld"), new File(hostTools, "mipsel-linux-android-ld"), new File(hostTools, FN_ZIPALIGN), new File(hostTools, FN_AAPT2)); return new TargetInfo(androidTarget, buildToolInfo); }
@NonNull @Override public Map<String, Object> getParameterInputs() { return ImmutableMap.of("buildToolsRev", buildToolInfo.get().getRevision().toString()); }
/** * Obtains the path for the {@code aapt} executable. * * @return the path */ @NonNull private String getAapt2ExecutablePath() { String aapt2 = mBuildToolInfo.getPath(BuildToolInfo.PathId.AAPT2); if (aapt2 == null || !new File(aapt2).isFile()) { throw new IllegalStateException("aapt2 is missing on '" + aapt2 + "'"); } return aapt2; }
private PngCruncher getCruncher() { if (getUseNewCruncher()) { if (getBuilder().getTargetInfo().getBuildTools().getRevision().getMajor() >= 22) { return QueuedCruncher.Builder.INSTANCE.newCruncher( getBuilder().getTargetInfo().getBuildTools().getPath( BuildToolInfo.PathId.AAPT), getILogger()); } getLogger().info("New PNG cruncher will be enabled with build tools 22 and above."); } return getBuilder().getAaptCruncher(); }
/** * Get the path for mainDexClasses.rules * @return */ public String getMainDexClassesRulesPath() { File mainDexClassesRules = new File( getBuildToolInfo().getLocation(), "mainDexClasses.rules" ); if ( mainDexClassesRules.exists() ) { return mainDexClassesRules.getAbsolutePath(); } throw new InvalidSdkException( "Cannot find " + mainDexClassesRules ); }
mergeResourcesTask.buildToolInfo = () -> BuildToolInfo.fromStandardDirectoryLayout( androidExtension.getBuildToolsRevision(), androidExtension.getBuildToolsDir());
/** * Creates a new {@link BuildToolInfo} where only some tools are present. * * <p>This may be the case when paths are managed by an external build system. */ @NonNull public static BuildToolInfo partial( @NonNull Revision revision, @NonNull File location, @NonNull Map<PathId, File> paths) { BuildToolInfo result = new BuildToolInfo(revision, location); paths.forEach(result::add); return result; }