Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move aapt2 to default (from aapt1) #3370

Merged
merged 1 commit into from
Oct 5, 2023
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
20 changes: 14 additions & 6 deletions brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,13 @@ private static void cmdBuild(CommandLine cli, Config config) {
if (cli.hasOption("nc") || cli.hasOption("no-crunch")) {
config.noCrunch = true;
}
if (cli.hasOption("use-aapt1")) {
config.useAapt2 = false;
}

// Temporary flag to enable the use of aapt2. This will transform in time to a use-aapt1 flag, which will be
// legacy and eventually removed.
if (cli.hasOption("use-aapt2")) {
config.useAapt2 = true;
if (cli.hasOption("use-aapt1") && cli.hasOption("use-aapt2")) {
System.err.println("You can only use one of --use-aapt1 or --use-aapt2.");
System.exit(1);
}

File outFile;
Expand Down Expand Up @@ -449,9 +451,14 @@ private static void _options() {
.desc("Load aapt from specified location.")
.build();

Option aapt1Option = Option.builder()
.longOpt("use-aapt1")
.desc("Use aapt binary instead of aapt2 during the build step.")
.build();

Option aapt2Option = Option.builder()
.longOpt("use-aapt2")
.desc("Use aapt2 binary instead of aapt1 during the build step.")
.desc("Use aapt2 binary instead of aapt during the build step.")
.build();

Option originalOption = Option.builder("c")
Expand Down Expand Up @@ -509,7 +516,7 @@ private static void _options() {
buildOptions.addOption(netSecConfOption);
buildOptions.addOption(aaptOption);
buildOptions.addOption(originalOption);
buildOptions.addOption(aapt2Option);
buildOptions.addOption(aapt1Option);
buildOptions.addOption(noCrunchOption);
}

Expand Down Expand Up @@ -568,6 +575,7 @@ private static void _options() {
allOptions.addOption(originalOption);
allOptions.addOption(verboseOption);
allOptions.addOption(quietOption);
allOptions.addOption(aapt1Option);
allOptions.addOption(aapt2Option);
allOptions.addOption(noCrunchOption);
allOptions.addOption(onlyMainClassesOption);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Config {
public boolean verbose = false;
public boolean copyOriginalFiles = false;
public boolean updateFiles = false;
public boolean useAapt2 = false;
public boolean useAapt2 = true;
public boolean noCrunch = false;
public int forceApi = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static void beforeClass() throws Exception {

LOGGER.info("Building not_sparse.apk...");
Config config = Config.getDefaultConfig();
config.useAapt2 = false;
new ApkBuilder(config, sTestNewDir).build(testApk);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static void beforeClass() throws Exception {

LOGGER.info("Building sparse.apk...");
Config config = Config.getDefaultConfig();
config.useAapt2 = false;
new ApkBuilder(config, sTestNewDir).build(testApk);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/
package brut.androlib.aapt1;

import brut.androlib.ApkBuilder;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.androlib.*;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
Expand All @@ -44,7 +41,9 @@ public static void beforeClass() throws Exception {

LOGGER.info("Building testjar.jar...");
File testJar = new File(sTmpDir, "testjar.jar");
new ApkBuilder(sTestOrigDir).build(testJar);
Config config = Config.getDefaultConfig();
config.useAapt2 = false;
new ApkBuilder(config, sTestOrigDir).build(testJar);

LOGGER.info("Decoding testjar.jar...");
ApkDecoder apkDecoder = new ApkDecoder(testJar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/
package brut.androlib.aapt1;

import brut.androlib.ApkBuilder;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.androlib.*;
import brut.androlib.apk.ApkInfo;
import brut.common.BrutException;
import brut.directory.ExtFile;
Expand Down Expand Up @@ -52,7 +49,9 @@ public static void beforeClass() throws Exception {

LOGGER.info("Building testapp.apk...");
File testApk = new File(sTmpDir, "testapp.apk");
new ApkBuilder(sTestOrigDir).build(testApk);
Config config = Config.getDefaultConfig();
config.useAapt2 = false;
new ApkBuilder(config, sTestOrigDir).build(testApk);

LOGGER.info("Decoding testapp.apk...");
ApkDecoder apkDecoder = new ApkDecoder(testApk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static void beforeClass() throws Exception {

LOGGER.info("Building issue1235.apk...");
Config config = Config.getDefaultConfig();
config.useAapt2 = false;
config.debugMode = true;

File testApk = new File(sTmpDir, "issue1235.apk");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/
package brut.androlib.aapt1;

import brut.androlib.ApkBuilder;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.androlib.*;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;
Expand All @@ -46,7 +43,9 @@ public static void beforeClass() throws Exception {

LOGGER.info("Building issue1481.jar...");
File testJar = new File(sTmpDir, "issue1481.jar");
new ApkBuilder(sTestOrigDir).build(testJar);
Config config = Config.getDefaultConfig();
config.useAapt2 = false;
new ApkBuilder(config, sTestOrigDir).build(testJar);

LOGGER.info("Decoding issue1481.jar...");
ApkDecoder apkDecoder = new ApkDecoder(testJar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static void beforeClass() throws Exception {

LOGGER.info("Building issue1730.apk...");
Config config = Config.getDefaultConfig();
config.useAapt2 = false;
new ApkBuilder(config, sTestNewDir).build(testApk);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.decode;
package brut.androlib.aapt1;

import brut.androlib.ApkBuilder;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.androlib.*;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
Expand All @@ -43,7 +40,9 @@ public static void beforeClass() throws Exception {

LOGGER.info("Building doctype.apk...");
File testApk = new File(sTestOrigDir, "doctype.apk");
new ApkBuilder(sTestOrigDir).build(testApk);
Config config = Config.getDefaultConfig();
config.useAapt2 = false;
new ApkBuilder(config, sTestOrigDir).build(testApk);

LOGGER.info("Decoding doctype.apk...");
ApkDecoder apkDecoder = new ApkDecoder(testApk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/
package brut.androlib.aapt1;

import brut.androlib.ApkBuilder;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.androlib.*;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
Expand Down Expand Up @@ -54,8 +51,10 @@ public void checkIfLargeIntsAreHandledTest() throws BrutException, IOException {
apkDecoder.decode(outDir);

// build issue767
Config config = Config.getDefaultConfig();
config.useAapt2 = false;
ExtFile testApk = new ExtFile(sTmpDir, apk + ".out");
new ApkBuilder(testApk).build(null);
new ApkBuilder(config, testApk).build(null);
String newApk = apk + ".out" + File.separator + "dist" + File.separator + apk;

// decode issue767 again
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/
package brut.androlib.aapt1;

import brut.androlib.ApkBuilder;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.androlib.*;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
Expand Down Expand Up @@ -62,7 +59,9 @@ public void isProviderStringReplacementWorking() throws BrutException, IOExcepti

// build issue636
ExtFile testApk = new ExtFile(sTmpDir, apk + ".out");
new ApkBuilder(testApk).build(null);
Config config = Config.getDefaultConfig();
config.useAapt2 = false;
new ApkBuilder(config, testApk).build(null);
String newApk = apk + ".out" + File.separator + "dist" + File.separator + apk;
assertTrue(fileExists(newApk));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void isSharedResourceDecodingAndRebuildingWorking() throws IOException, B
Config config = Config.getDefaultConfig();
config.frameworkDirectory = sTmpDir.getAbsolutePath();
config.frameworkTag = "shared";
config.useAapt2 = false;

// install library/framework
new Framework(config).installFramework(new File(sTmpDir + File.separator + library));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static void beforeClass() throws Exception {
String apk = "deflated_unknowns.apk";
Config config = Config.getDefaultConfig();
config.frameworkDirectory = sTmpDir.getAbsolutePath();
config.useAapt2 = false;

sTestOrigDir = new ExtFile(sTmpDir, apk);

Expand Down
Loading