mirror of
https://github.com/revanced/Apktool.git
synced 2025-01-05 17:45:52 +01:00
feat: allow configurable api-level for smali
This commit is contained in:
parent
438c4b9c59
commit
0efccc2d93
@ -230,6 +230,9 @@ public class Main {
|
||||
if (cli.hasOption("use-aapt2")) {
|
||||
apkOptions.useAapt2 = true;
|
||||
}
|
||||
if (cli.hasOption("api") || cli.hasOption("api-level")) {
|
||||
apkOptions.forceApi = Integer.parseInt(cli.getOptionValue("api"));
|
||||
}
|
||||
if (cli.hasOption("o") || cli.hasOption("output")) {
|
||||
outFile = new File(cli.getOptionValue("o"));
|
||||
} else {
|
||||
|
@ -416,7 +416,7 @@ public class Androlib {
|
||||
if (apkOptions.forceBuildAll || isModified(smaliDir, dex)) {
|
||||
LOGGER.info("Smaling " + folder + " folder into " + filename + "...");
|
||||
dex.delete();
|
||||
SmaliBuilder.build(smaliDir, dex, mMinSdkVersion);
|
||||
SmaliBuilder.build(smaliDir, dex, apkOptions.forceApi > 0 ? apkOptions.forceApi : mMinSdkVersion);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ public class ApkOptions {
|
||||
public boolean resourcesAreCompressed = false;
|
||||
public boolean useAapt2 = false;
|
||||
public boolean noCrunch = false;
|
||||
public int forceApi = 0;
|
||||
public Collection<String> doNotCompress;
|
||||
|
||||
public String frameworkFolderLocation = null;
|
||||
|
@ -29,14 +29,14 @@ import org.jf.smali.*;
|
||||
*/
|
||||
public class SmaliMod {
|
||||
|
||||
public static boolean assembleSmaliFile(String smali, DexBuilder dexBuilder, boolean verboseErrors,
|
||||
public static boolean assembleSmaliFile(String smali, DexBuilder dexBuilder, int apiLevel, boolean verboseErrors,
|
||||
boolean printTokens, File smaliFile) throws IOException, RuntimeException, RecognitionException {
|
||||
|
||||
InputStream is = new ByteArrayInputStream(smali.getBytes());
|
||||
return assembleSmaliFile(is, dexBuilder, verboseErrors, printTokens, smaliFile);
|
||||
return assembleSmaliFile(is, dexBuilder, apiLevel, verboseErrors, printTokens, smaliFile);
|
||||
}
|
||||
|
||||
public static boolean assembleSmaliFile(InputStream is,DexBuilder dexBuilder, boolean verboseErrors,
|
||||
public static boolean assembleSmaliFile(InputStream is,DexBuilder dexBuilder, int apiLevel, boolean verboseErrors,
|
||||
boolean printTokens, File smaliFile) throws IOException, RecognitionException {
|
||||
|
||||
// copy our filestream into a tmp file, so we don't overwrite
|
||||
@ -47,10 +47,10 @@ public class SmaliMod {
|
||||
IOUtils.copy(is, os);
|
||||
os.close();
|
||||
|
||||
return assembleSmaliFile(tmp,dexBuilder, verboseErrors, printTokens);
|
||||
return assembleSmaliFile(tmp,dexBuilder, apiLevel, verboseErrors, printTokens);
|
||||
}
|
||||
|
||||
public static boolean assembleSmaliFile(File smaliFile,DexBuilder dexBuilder, boolean verboseErrors,
|
||||
public static boolean assembleSmaliFile(File smaliFile,DexBuilder dexBuilder, int apiLevel, boolean verboseErrors,
|
||||
boolean printTokens) throws IOException, RecognitionException {
|
||||
|
||||
CommonTokenStream tokens;
|
||||
@ -77,6 +77,7 @@ public class SmaliMod {
|
||||
}
|
||||
|
||||
smaliParser parser = new smaliParser(tokens);
|
||||
parser.setApiLevel(apiLevel);
|
||||
parser.setVerboseErrors(verboseErrors);
|
||||
|
||||
smaliParser.smali_file_return result = parser.smali_file();
|
||||
@ -93,7 +94,7 @@ public class SmaliMod {
|
||||
treeStream.setTokenStream(tokens);
|
||||
|
||||
smaliTreeWalker dexGen = new smaliTreeWalker(treeStream);
|
||||
|
||||
dexGen.setApiLevel(apiLevel);
|
||||
dexGen.setVerboseErrors(verboseErrors);
|
||||
dexGen.setDexBuilder(dexBuilder);
|
||||
dexGen.smali_file();
|
||||
|
@ -71,7 +71,7 @@ public class SmaliBuilder {
|
||||
|
||||
if (fileName.endsWith(".smali")) {
|
||||
try {
|
||||
if (!SmaliMod.assembleSmaliFile(inFile, dexBuilder, false, false)) {
|
||||
if (!SmaliMod.assembleSmaliFile(inFile, dexBuilder, mApiLevel, false, false)) {
|
||||
throw new AndrolibException("Could not smali file: " + fileName);
|
||||
}
|
||||
} catch (IOException | RecognitionException ex) {
|
||||
|
Loading…
Reference in New Issue
Block a user