Skip to content

Commit

Permalink
Merge pull request #68 from Kirlif/dex_file_magic
Browse files Browse the repository at this point in the history
proper version number in the dex header
  • Loading branch information
REAndroid authored Aug 23, 2023
2 parents 635913f + 8c661ee commit fdb7465
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.reandroid.apk.DexEncoder;
import com.reandroid.archive.FileInputSource;
import com.reandroid.archive.InputSource;
import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
import com.reandroid.utils.StringsUtil;
import org.jf.smali.Smali;
import org.jf.smali.SmaliOptions;
Expand All @@ -32,6 +33,7 @@
public class SmaliCompiler implements DexEncoder {
private APKLogger apkLogger;
private final boolean noCache;
private Integer minSdkVersion;
public SmaliCompiler(boolean noCache){
this.noCache = noCache;
}
Expand All @@ -41,6 +43,10 @@ public List<InputSource> buildDexFiles(ApkModuleEncoder apkModuleEncoder, File m
if(!smaliDir.isDirectory()){
return null;
}
AndroidManifestBlock manifestBlock = apkModuleEncoder.getApkModule().getAndroidManifestBlock();
if (manifestBlock != null) {
this.minSdkVersion = manifestBlock.getMinSdkVersion();
}
List<InputSource> results = new ArrayList<>();
List<File> classesDirList = listClassesDirectories(smaliDir);
int i = 0;
Expand Down Expand Up @@ -73,6 +79,9 @@ private InputSource build(String progress, File classesDir, File dexCacheFile) t
if(smaliOptions.jobs <= 0){
smaliOptions.jobs = 1;
}
if (this.minSdkVersion != null) {
smaliOptions.apiLevel = this.minSdkVersion.intValue();
}
boolean success = Smali.assemble(smaliOptions, classesDir.getAbsolutePath());
if(!success){
throw new IOException("Failed to build smali, check the logs");
Expand Down

0 comments on commit fdb7465

Please sign in to comment.