From 154da4c64398687f5fca7e6533721c2595251f82 Mon Sep 17 00:00:00 2001 From: Adib Faramarzi Date: Thu, 30 May 2019 18:46:59 +0430 Subject: [PATCH] Fix removal of META-INF/services folder - copy the META-INF/services folder to the destination APK folder so it does not get dropped --- .../src/main/java/brut/androlib/Androlib.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java index c2499924..2a9b86b7 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java @@ -239,6 +239,14 @@ public class Androlib { } if (in.containsDir("META-INF")) { in.copyToDir(originalDir, "META-INF"); + + if(in.containsDir("META-INF/services")){ + // If the original APK contains the folder META-INF/services folder + // that is used for service locators (like coroutines on android), + // copy it to the destination folder so it does not get dropped. + LOGGER.info("Copying META-INF/services directory"); + in.copyToDir(outDir, "META-INF/services"); + } } } catch (DirectoryException ex) { throw new AndrolibException(ex); @@ -560,6 +568,7 @@ public class Androlib { buildLibrary(appDir, "lib"); buildLibrary(appDir, "libs"); buildLibrary(appDir, "kotlin"); + buildLibrary(appDir, "META-INF/services"); } public void buildLibrary(File appDir, String folder) throws AndrolibException { @@ -570,7 +579,7 @@ public class Androlib { } File stored = new File(appDir, APK_DIRNAME + "/" + folder); - if (apkOptions.forceBuildAll || isModified(working, stored)) { + if (apkOptions.forceBuildAll || isModified(working, stored) || folder.contains("services")) { LOGGER.info("Copying libs... (/" + folder + ")"); try { OS.rmdir(stored); @@ -788,5 +797,5 @@ public class Androlib { "AndroidManifest.xml" }; private final static String[] APK_STANDARD_ALL_FILENAMES = new String[] { "classes.dex", "AndroidManifest.xml", "resources.arsc", "res", "r", "R", - "lib", "libs", "assets", "META-INF", "kotlin" }; + "lib", "libs", "assets", "META-INF", "kotlin"}; }