No need to add loader dex and so for local mode
This commit is contained in:
parent
fbd327dadf
commit
5db7ecf7bd
|
|
@ -236,35 +236,7 @@ public class LSPatch {
|
||||||
throw new PatchError("Error when modifying manifest", e);
|
throw new PatchError("Error when modifying manifest", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.d("Adding native lib..");
|
logger.i("Adding config...");
|
||||||
|
|
||||||
// copy so and dex files into the unzipped apk
|
|
||||||
// do not put liblspatch.so into apk!lib because x86 native bridge causes crash
|
|
||||||
for (String arch : ARCHES) {
|
|
||||||
String entryName = "assets/lspatch/so/" + arch + "/liblspatch.so";
|
|
||||||
try (var is = getClass().getClassLoader().getResourceAsStream(entryName)) {
|
|
||||||
dstZFile.add(entryName, is, false); // no compress for so
|
|
||||||
} catch (Throwable e) {
|
|
||||||
// More exception info
|
|
||||||
throw new PatchError("Error when adding native lib", e);
|
|
||||||
}
|
|
||||||
logger.d("added " + entryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.d("Adding dex..");
|
|
||||||
|
|
||||||
try (var is = getClass().getClassLoader().getResourceAsStream(Constants.META_LOADER_DEX_ASSET_PATH)) {
|
|
||||||
dstZFile.add("classes.dex", is);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new PatchError("Error when adding dex", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try (var is = getClass().getClassLoader().getResourceAsStream(LOADER_DEX_ASSET_PATH)) {
|
|
||||||
dstZFile.add(LOADER_DEX_ASSET_PATH, is);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new PatchError("Error when adding assets", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// save lspatch config to asset..
|
// save lspatch config to asset..
|
||||||
try (var is = new ByteArrayInputStream(configBytes)) {
|
try (var is = new ByteArrayInputStream(configBytes)) {
|
||||||
dstZFile.add(CONFIG_ASSET_PATH, is);
|
dstZFile.add(CONFIG_ASSET_PATH, is);
|
||||||
|
|
@ -272,27 +244,36 @@ public class LSPatch {
|
||||||
throw new PatchError("Error when saving config");
|
throw new PatchError("Error when saving config");
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> apkArches = new HashSet<>();
|
logger.i("Adding metaloader dex...");
|
||||||
|
try (var is = getClass().getClassLoader().getResourceAsStream(Constants.META_LOADER_DEX_ASSET_PATH)) {
|
||||||
logger.d("Search target apk library arch...");
|
dstZFile.add("classes.dex", is);
|
||||||
|
} catch (Throwable e) {
|
||||||
for (StoredEntry storedEntry : srcZFile.entries()) {
|
throw new PatchError("Error when adding dex", e);
|
||||||
var name = storedEntry.getCentralDirectoryHeader().getName();
|
|
||||||
if (name.startsWith("lib/") && name.length() >= 5) {
|
|
||||||
var arch = name.substring(4, name.indexOf('/', 5));
|
|
||||||
apkArches.add(arch);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (apkArches.isEmpty()) apkArches.addAll(ARCHES);
|
|
||||||
apkArches.removeIf((arch) -> {
|
|
||||||
if (!ARCHES.contains(arch) && !arch.equals("armeabi")) {
|
|
||||||
logger.e("Warning: unsupported arch " + arch + ". Skipping...");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!useManager) {
|
if (!useManager) {
|
||||||
|
logger.i("Adding loader dex...");
|
||||||
|
try (var is = getClass().getClassLoader().getResourceAsStream(LOADER_DEX_ASSET_PATH)) {
|
||||||
|
dstZFile.add(LOADER_DEX_ASSET_PATH, is);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
throw new PatchError("Error when adding assets", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.i("Adding native lib...");
|
||||||
|
// copy so and dex files into the unzipped apk
|
||||||
|
// do not put liblspatch.so into apk!lib because x86 native bridge causes crash
|
||||||
|
for (String arch : ARCHES) {
|
||||||
|
String entryName = "assets/lspatch/so/" + arch + "/liblspatch.so";
|
||||||
|
try (var is = getClass().getClassLoader().getResourceAsStream(entryName)) {
|
||||||
|
dstZFile.add(entryName, is, false); // no compress for so
|
||||||
|
} catch (Throwable e) {
|
||||||
|
// More exception info
|
||||||
|
throw new PatchError("Error when adding native lib", e);
|
||||||
|
}
|
||||||
|
logger.d("added " + entryName);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.i("Embedding modules...");
|
||||||
embedModules(dstZFile);
|
embedModules(dstZFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,7 +297,6 @@ public class LSPatch {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void embedModules(ZFile zFile) {
|
private void embedModules(ZFile zFile) {
|
||||||
logger.i("Embedding modules...");
|
|
||||||
for (var module : modules) {
|
for (var module : modules) {
|
||||||
File file = new File(module);
|
File file = new File(module);
|
||||||
try (var apk = ZFile.openReadOnly(new File(module));
|
try (var apk = ZFile.openReadOnly(new File(module));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue