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