private void forEachUnalignedInput(InputProcessor processor) { String archivesBaseName = (String)getProject().getProperties().get("archivesBaseName"); Pattern unalignedPattern = Pattern.compile( archivesBaseName + "-" + outputBaseName + "_(.*)-unaligned.apk"); for (File file : getInputFiles()) { Matcher unaligned = unalignedPattern.matcher(file.getName()); if (unaligned.matches() && isFilter(unaligned.group(1))) { processor.process(unaligned.group(1), file); } } }
private void forEachUnsignedInput(InputProcessor processor) { String archivesBaseName = (String)getProject().getProperties().get("archivesBaseName"); Pattern unsignedPattern = Pattern.compile( archivesBaseName + "-" + outputBaseName + "_(.*)-unsigned.apk"); for (File file : getInputFiles()) { Matcher unsigned = unsignedPattern.matcher(file.getName()); if (unsigned.matches() && isFilter(unsigned.group(1))) { processor.process(unsigned.group(1), file); } } }
@Override public void process(final String split, final File file) { final File out = new File(getOutputDirectory(), archivesBaseName + "-" + outputBaseName + "_" + split + ".apk"); getProject().exec(new Action<ExecSpec>() { @Override public void execute(ExecSpec execSpec) { execSpec.setExecutable(getZipAlignExe()); execSpec.args("-f", "4"); execSpec.args(file.getAbsolutePath()); execSpec.args(out); } }); } };
@Override @NonNull public synchronized ImmutableList<ApkOutputFile> getOutputSplitFiles() { final String archivesBaseName = (String)getProject().getProperties().get("archivesBaseName"); final ImmutableList.Builder<ApkOutputFile> outputFiles = ImmutableList.builder(); InputProcessor addingLogic = new InputProcessor() { @Override public void process(String split, File file) { outputFiles.add(new ApkOutputFile( OutputType.SPLIT, ImmutableList.of( FilterDataImpl.build( getFilterType(split).toString(), getFilter(split))), Callables.returning( new File( outputDirectory, archivesBaseName + "-" + outputBaseName + "_" + split + ".apk")))); } }; forEachUnalignedInput(addingLogic); forEachUnsignedInput(addingLogic); return outputFiles.build(); }
@TaskAction public void splitZipAlign() throws IOException { final String archivesBaseName = (String)getProject().getProperties().get("archivesBaseName"); InputProcessor zipAlignIt = new InputProcessor() { @Override public void process(final String split, final File file) { final File out = new File(getOutputDirectory(), archivesBaseName + "-" + outputBaseName + "_" + split + ".apk"); getProject().exec(new Action<ExecSpec>() { @Override public void execute(ExecSpec execSpec) { execSpec.setExecutable(getZipAlignExe()); execSpec.args("-f", "4"); execSpec.args(file.getAbsolutePath()); execSpec.args(out); } }); } }; forEachUnalignedInput(zipAlignIt); forEachUnsignedInput(zipAlignIt); saveApkMetadataFile(); }