ExternalBuildManifestLoader { public static void loadAndPopulateContext( @NonNull File execRootFile, @NonNull File manifestProtoFile, @NonNull Project project, @NonNull ExternalBuildContext externalBuildContext) throws IOException { if (!manifestProtoFile.exists()) { throw new FileNotFoundException(manifestProtoFile.getAbsolutePath()); } ExternalBuildApkManifest.ApkManifest manifest; try (InputStream is = new BufferedInputStream(new FileInputStream(manifestProtoFile))) { manifest = ExternalBuildApkManifest.ApkManifest.parseFrom(is); } externalBuildContext.setBuildManifest(manifest); externalBuildContext.setExecutionRoot(execRootFile); List<File> jarFiles = manifest.getJarsList().stream() .map(artifact -> new File(execRootFile, artifact.getExecRootPath())) .collect(Collectors.toList()); externalBuildContext.setInputJarFiles(jarFiles); externalBuildContext.setAndroidBuilder( createAndroidBuilder(execRootFile, project, manifest)); }  static void loadAndPopulateContext(
            @NonNull File execRootFile,
            @NonNull File manifestProtoFile,
            @NonNull Project project,
            @NonNull ExternalBuildContext externalBuildContext);  }
@Test public void manifestReadingTest() throws IOException { File apk_manifest_test = new File(mTemporaryFolder.getRoot(), "apk_manifest_test"); when(mProject.getPath()).thenReturn(mTemporaryFolder.getRoot().getPath()); File dx = new File(mTemporaryFolder.getRoot(), "dx.jar"); when(mProject.file("dx.jar")).thenReturn(dx); File aapt = new File(mTemporaryFolder.getRoot(), "aapt"); when(mProject.file("aapt")).thenReturn(aapt); File jarOne = new File(mTemporaryFolder.getRoot(), "tmp/one"); when(mProject.file("tmp/one")).thenReturn(jarOne); File jarTwo = new File(mTemporaryFolder.getRoot(), "tmp/two"); when(mProject.file("tmp/two")).thenReturn(jarTwo); FileUtils.createFile(dx, "dx.jar content"); try (OutputStream os = new BufferedOutputStream( new FileOutputStream(apk_manifest_test))) { ExternalBuildApkManifest.ApkManifest.newBuilder() .setAndroidSdk(ExternalBuildApkManifest.AndroidSdk.newBuilder() .setDx("dx.jar") .setAapt("aapt")) .addJars(ExternalBuildApkManifest.Artifact.newBuilder() .setExecRootPath("tmp/one")) .addJars(ExternalBuildApkManifest.Artifact.newBuilder() .setExecRootPath("tmp/two")) .build() .writeTo(os); } ExternalBuildContext externalBuildContext = new ExternalBuildContext(mExternalBuildExtension); ExternalBuildManifestLoader.loadAndPopulateContext( mTemporaryFolder.getRoot(), apk_manifest_test, mProject, externalBuildContext); assertThat(externalBuildContext.getBuildManifest()).isNotNull(); ExternalBuildApkManifest.ApkManifest buildManifest = externalBuildContext .getBuildManifest(); assertThat(buildManifest.getJarsCount()).isEqualTo(2); assertThat(buildManifest.getAndroidSdk().getAapt()).isEqualTo("aapt"); assertThat(externalBuildContext.getInputJarFiles()).containsAllOf( new File(mTemporaryFolder.getRoot(), "tmp/one"), new File(mTemporaryFolder.getRoot(), "tmp/two")); }