Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed app/src/main/assets/bundletool.jar
Binary file not shown.
6 changes: 4 additions & 2 deletions build-tools/build-logic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ dependencies {
// javac
implementation project(path: ':build-tools:javac')
implementation project(path: ':build-tools:xml-repository')

// bundletool
implementation 'com.android.tools.build:bundletool:1.8.2'

testImplementation 'junit:junit:4.13.2'
testImplementation "com.google.truth:truth:1.1.3"
testImplementation "org.robolectric:robolectric:4.7.3"
Expand All @@ -41,4 +43,4 @@ dependencies {
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.tyron.builder.compiler;


import com.tyron.builder.BuildModule;
import java.io.File;
import java.util.ArrayList;
import com.android.tools.build.bundletool.BundleToolMain;

public class BundleTool {

public static class Mode {
public static int TEST = 0;
//ToDo add more modes
}


private final ArrayList<String> commands ;
private final String mApkInputPath ;
private final String mApkOutputPath;

public BundleTool(String inputPath ,String outputPath,int mode){
commands = new ArrayList<>();
mApkInputPath = inputPath;
mApkOutputPath = outputPath;
}

//TODO: Adjust min and max sdk
public void aab() throws Exception {
commands.add("build-bundle");
commands.add("--modules=" + mApkInputPath);
commands.add("--output=" + mApkOutputPath);

com.android.tools.build.bundletool.BundleToolMain.main(commands.toArray(new String[0]));
}
public void apk() throws Exception {
commands.add("build-apks");
commands.add("--bundle=" + mApkInputPath);
commands.add("--output=" + mApkOutputPath);
commands.add("--mode=universal");
commands.add("--aapt2=" + BuildModule.getContext().getApplicationInfo().nativeLibraryDir + "/libaapt2.so");



com.android.tools.build.bundletool.BundleToolMain.main(commands.toArray(new String[0]));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import com.tyron.builder.compiler.BundleTool;

public class AabTask extends Task<AndroidModule> {

Expand All @@ -65,7 +66,10 @@ public AabTask(Project project, AndroidModule module, ILogger logger) {
public String getName() {
return TAG;
}

private File mInputApk;
private File mOutputApk;
private File mOutputApks;

@Override
public void prepare(BuildType type) throws IOException {
mBinDir = new File(getModule().getBuildDirectory(), "/bin");
Expand All @@ -84,7 +88,12 @@ public void prepare(BuildType type) throws IOException {
if (!dex.exists() && !dex.mkdirs()) {
throw new IOException("Failed to create resource output directory");
}

mInputApk = new File(mBinDir.getAbsolutePath() + "/Base-Module.zip");
mOutputApk = new File(mBinDir.getAbsolutePath() + "/module.aab");
mOutputApks = new File(mBinDir.getAbsolutePath() + "/App.apks");



mAddedFiles.clear();
}

Expand All @@ -97,10 +106,10 @@ public void run() throws IOException, CompilationFailedException {
copyDexFiles();
baseZip();
copyLibraries();
budletool();

aab();
buildApks();
extractApks();
// buildApks();
// extractApks();
} catch (SignedJarBuilder.IZipEntryFilter.ZipAbortException e) {
String message = e.getMessage();
if (e instanceof DuplicateFileException) {
Expand Down Expand Up @@ -165,7 +174,7 @@ private static void uApks(String Apks, String dApks) throws IOException {

private void buildApks() throws CompilationFailedException {
getLogger().debug("Building Apks");
List<String> args = new ArrayList<>();
/* List<String> args = new ArrayList<>();
args.add("dalvikvm");
args.add("-Xcompiler-option");
args.add("--compiler-filter=speed");
Expand All @@ -185,27 +194,25 @@ private void buildApks() throws CompilationFailedException {
executor.setCommands(args);
if (!executor.execute().isEmpty()) {
throw new CompilationFailedException(executor.getLog());
}
}

private void budletool() throws IOException {
getLogger().debug("Preparing Bundletool");
}*/
BundleTool signer = new BundleTool(mOutputApk.getAbsolutePath(),
mOutputApks.getAbsolutePath(), BundleTool.Mode.TEST);

File bundletool = new File(BuildModule.getContext().getFilesDir(), "bundletool.jar");
if (!bundletool.exists()) {
InputStream input = BuildModule.getContext()
.getAssets().open("bundletool.jar");
OutputStream output = new FileOutputStream(
new File(BuildModule.getContext().getFilesDir(), "bundletool.jar"));
IOUtils.copy(input, output);
try {
signer.apk();
} catch (Exception e) {
throw new CompilationFailedException(e);
}


}



private void aab() throws CompilationFailedException {
getLogger().debug("Generating AAB.");

List<String> args = new ArrayList<>();
/* List<String> args = new ArrayList<>();
args.add("dalvikvm");
args.add("-Xcompiler-option");
args.add("--compiler-filter=speed");
Expand All @@ -222,7 +229,17 @@ private void aab() throws CompilationFailedException {
executor.setCommands(args);
if (!executor.execute().isEmpty()) {
throw new CompilationFailedException(executor.getLog());
}*/
BundleTool signer = new BundleTool(mInputApk.getAbsolutePath(),
mOutputApk.getAbsolutePath(), BundleTool.Mode.TEST);

try {
signer.aab();
} catch (Exception e) {
throw new CompilationFailedException(e);
}


}


Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ android.useAndroidX=true
android.enableJetifier=true
org.gradle.unsafe.configuration-cache=false
android.bundle.enableUncompressedNativeLibs=false
android.jetifier.ignorelist = bundletool-1.8.2.jar