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

Implement switch to keep extractNativeLibs manifest option #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/main/java/com/reandroid/apkeditor/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ protected boolean containsArg(String argSwitch, boolean ignore_case, String[] ar
protected static final String ARG_DESC_force="force delete output path";
protected static final String ARG_cleanMeta = "-clean-meta";
protected static final String ARG_DESC_cleanMeta = "cleans META-INF directory along with signature block";
protected static final String ARG_keepExtractNativeLibs = "-keep-extractnativelibs";
protected static final String ARG_DESC_keepExtractNativeLibs = "keeps android:ExtractNativeLibs during manifest sanitation";

protected static final String ARG_sig = "-sig";
protected static final String ARG_DESC_sig = "signatures directory path";
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/reandroid/apkeditor/merge/Merger.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void run() throws IOException {
logMessage("Clearing META-INF ...");
clearMeta(mergedModule);
}
sanitizeManifest(mergedModule);
sanitizeManifest(mergedModule, options.keepExtractNativeLibs);
Util.addApkEditorInfo(mergedModule, getClass().getSimpleName());
String message = mergedModule.refreshTable();
if(message != null){
Expand Down Expand Up @@ -129,15 +129,17 @@ private File toTmpDir(File file){
tmp = Util.ensureUniqueFile(tmp);
return tmp;
}
private void sanitizeManifest(ApkModule apkModule) {
private void sanitizeManifest(ApkModule apkModule, boolean keepExtractNativeLibs) {
if(!apkModule.hasAndroidManifestBlock()){
return;
}
AndroidManifestBlock manifest = apkModule.getAndroidManifestBlock();
logMessage("Sanitizing manifest ...");
AndroidManifestHelper.removeAttributeFromManifestAndApplication(manifest,
AndroidManifestBlock.ID_extractNativeLibs,
this, AndroidManifestBlock.NAME_extractNativeLibs);
if (!keepExtractNativeLibs) {
AndroidManifestHelper.removeAttributeFromManifestAndApplication(manifest,
AndroidManifestBlock.ID_extractNativeLibs,
this, AndroidManifestBlock.NAME_extractNativeLibs);
}
AndroidManifestHelper.removeAttributeFromManifestAndApplication(manifest,
AndroidManifestBlock.ID_isSplitRequired,
this, AndroidManifestBlock.NAME_isSplitRequired);
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/reandroid/apkeditor/merge/MergerOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class MergerOptions extends Options {
public boolean validateResDir;
public boolean cleanMeta;
public boolean keepExtractNativeLibs;
public String resDirName;
public MergerOptions(){
super();
Expand All @@ -36,6 +37,7 @@ public void parse(String[] args) throws ARGException {
parseResDirName(args);
parseValidateResDir(args);
parseCleanMeta(args);
parseKeepExtractNativeLibs(args);
super.parse(args);
}
private void parseValidateResDir(String[] args) throws ARGException {
Expand All @@ -55,6 +57,9 @@ private void parseOutput(String[] args) throws ARGException {
}
this.outputFile=file;
}
private void parseKeepExtractNativeLibs(String[] args) throws ARGException {
this.keepExtractNativeLibs=containsArg(ARG_keepExtractNativeLibs, false, args);
}
private File getOutputApkFromInput(File file){
String name = file.getName();
int i = name.lastIndexOf('.');
Expand Down Expand Up @@ -96,6 +101,9 @@ public String toString(){
if(cleanMeta){
builder.append("\n Keep meta: true");
}
if(keepExtractNativeLibs){
builder.append("\n Keep android:extractNativeLibs: true");
}
builder.append("\n ---------------------------- ");
return builder.toString();
}
Expand All @@ -112,7 +120,8 @@ public static String getHelp(){
builder.append("\nFlags:\n");
table=new String[][]{
new String[]{ARG_force, ARG_DESC_force},
new String[]{ARG_cleanMeta, ARG_DESC_cleanMeta}
new String[]{ARG_cleanMeta, ARG_DESC_cleanMeta},
new String[]{ARG_keepExtractNativeLibs, ARG_DESC_keepExtractNativeLibs}
};
StringHelper.printTwoColumns(builder, " ", Options.PRINT_WIDTH, table);
String jar = APKEditor.getJarName();
Expand Down