mirror of
https://github.com/revanced/Apktool.git
synced 2025-04-29 21:54:25 +02:00

* refactor: ApkDecoder & ApkBuilder overhaul A major rewrite of ApkDecoder and ApkBuilder classes to make them managable. Removed many instances of redundancy and improved syntaxed and indentation. Modifying the stock Apktool source to our needs have become too difficult, so I'm pushing the general (not specific to our needs) changes upstream. I'd change a lot more, but I wanted to make sure all tests pass as expected, despite some of them being wierd, outdated or unnecessary. This also fixes certain files in META-INF being lost during recompile when the -c/--copy-original option isn't used. This has been tweaked and tested for several days and I vouch for its stablity. * style: fix more redundancy * style: fix more redundancy * tweak: consistent case-sensitivity for cmd and options * refactor: tracking unknownFiles via apkInfo is redundant 1) We take advantage of the fact that doNotCompress already tracks uncompressed files, including those separated into "unknown". With this change the "unknownFiles" is simply ignored, so it's backward-compatible with existing decoded APK dirs. Tweaked a few tests to match the removal of "unknownFiles". 2) Passing doNotCompress to AAPT is redundant, Apktool extracts the temp APK packed by AAPT to build/apk and then repackages it anyway, so it serves no purpose. * refactor: fix minSdkVersion from baksmali + clean up more redundancy * Regression: minSdkVersion inferred from baksmali was not stored properly. * The arsc extension can be generalized for simplicity as seen in AOSP source. https://cs.android.com/android/platform/superproject/main/+/main:external/deqp/scripts/android/build_apk.py;l=644?q=apk%20pack&ss=android%2Fplatform%2Fsuperproject%2Fmain:external%2F Note: NO_COMPRESS_EXT_PATTERN only collapses paths to a common extension. It does NOT force these extensions to be always uncompressed. doNotCompress is the one determining files/extensions that should be uncompressed. (no funcionality was changed) * resourcesAreCompressed in apkInfo is redundant. It was only used in invokeAapt, but not ApkBuilder. Its value is also never set by Apktool, only read. Like with doNotCompress, passing any kind of compression rules to AAPT is pointless, since we don't use the temp APK packed by AAPT directly - it's extracted and repacked by ApkBuilder, where doNotCompress already determines whether resources.arsc should or should not be compressed in the final APK. (no funcionality was changed) * style: optional args come after required args * style: optional args come after required args * style: sdkInfo as a normal field for consistency * style: some formatting tweaks
91 lines
3.4 KiB
Java
91 lines
3.4 KiB
Java
/*
|
|
* Copyright (C) 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
|
|
* Copyright (C) 2010 Connor Tumbleson <connor.tumbleson@gmail.com>
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
package brut.androlib.aapt2;
|
|
|
|
import brut.androlib.*;
|
|
import brut.androlib.Config;
|
|
import brut.common.BrutException;
|
|
import brut.directory.ExtFile;
|
|
import brut.util.OS;
|
|
import org.custommonkey.xmlunit.XMLUnit;
|
|
import org.junit.AfterClass;
|
|
import org.junit.BeforeClass;
|
|
import org.junit.Test;
|
|
import org.xml.sax.SAXException;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Paths;
|
|
|
|
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
public class DebuggableTrueAddedTest extends BaseTest {
|
|
|
|
@BeforeClass
|
|
public static void beforeClass() throws Exception {
|
|
TestUtils.cleanFrameworkFile();
|
|
sTmpDir = new ExtFile(OS.createTempDirectory());
|
|
sTestOrigDir = new ExtFile(sTmpDir, "issue2328-debuggable-missing-orig");
|
|
sTestNewDir = new ExtFile(sTmpDir, "issue2328-debuggable-missing-new");
|
|
LOGGER.info("Unpacking issue2328-debuggable-missing...");
|
|
TestUtils.copyResourceDir(DebuggableTrueAddedTest.class, "aapt2/issue2328/debuggable-missing", sTestOrigDir);
|
|
|
|
LOGGER.info("Building issue2328-debuggable-missing.apk...");
|
|
Config config = Config.getDefaultConfig();
|
|
config.debugMode = true;
|
|
config.verbose = true;
|
|
|
|
ExtFile testApk = new ExtFile(sTmpDir, "issue2328-debuggable-missing.apk");
|
|
new ApkBuilder(sTestOrigDir, config).build(testApk);
|
|
|
|
LOGGER.info("Decoding issue2328-debuggable-missing.apk...");
|
|
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
|
apkDecoder.decode(sTestNewDir);
|
|
}
|
|
|
|
@AfterClass
|
|
public static void afterClass() throws BrutException {
|
|
OS.rmdir(sTmpDir);
|
|
}
|
|
|
|
@Test
|
|
public void buildAndDecodeTest() {
|
|
assertTrue(sTestNewDir.isDirectory());
|
|
}
|
|
|
|
@Test
|
|
public void DebugIsTruePriorToBeingFalseTest() throws IOException, SAXException {
|
|
String apk = "issue2328-debuggable-missing-new";
|
|
|
|
String expected = TestUtils.replaceNewlines("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>" +
|
|
"<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" " +
|
|
"package=\"com.ibotpeaches.issue2328\" platformBuildVersionCode=\"20\" " +
|
|
"platformBuildVersionName=\"4.4W.2-1537038\"> <application android:debuggable=\"true\"/></manifest>");
|
|
|
|
byte[] encoded = Files.readAllBytes(Paths.get(sTmpDir + File.separator + apk + File.separator + "AndroidManifest.xml"));
|
|
String obtained = TestUtils.replaceNewlines(new String(encoded));
|
|
|
|
XMLUnit.setIgnoreWhitespace(true);
|
|
XMLUnit.setIgnoreAttributeOrder(true);
|
|
XMLUnit.setCompareUnmatched(false);
|
|
|
|
assertXMLEqual(expected, obtained);
|
|
}
|
|
}
|