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
85 lines
2.9 KiB
Java
85 lines
2.9 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.decode;
|
|
|
|
import brut.androlib.*;
|
|
import brut.androlib.apk.ApkInfo;
|
|
import brut.common.BrutException;
|
|
import brut.directory.ExtFile;
|
|
import brut.util.OS;
|
|
import org.junit.After;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
public class SparseFlagTest extends BaseTest {
|
|
|
|
@Before
|
|
public void beforeClass() throws Exception {
|
|
TestUtils.cleanFrameworkFile();
|
|
sTmpDir = new ExtFile(OS.createTempDirectory());
|
|
sTestOrigDir = new ExtFile(sTmpDir, "sparse-orig");
|
|
sTestNewDir = new ExtFile(sTmpDir, "sparse-new");
|
|
LOGGER.info("Unpacking sparse.apk && not-sparse.apk...");
|
|
TestUtils.copyResourceDir(SparseFlagTest.class, "decode/sparse", sTestOrigDir);
|
|
}
|
|
|
|
@After
|
|
public void afterClass() throws BrutException {
|
|
OS.rmdir(sTmpDir);
|
|
}
|
|
|
|
@Test
|
|
public void decodeWithExpectationOfSparseResources() throws BrutException, IOException {
|
|
ExtFile testApk = new ExtFile(sTestOrigDir, "sparse.apk");
|
|
|
|
LOGGER.info("Decoding sparse.apk...");
|
|
Config config = Config.getDefaultConfig();
|
|
config.frameworkTag = "issue-3298";
|
|
|
|
ApkDecoder apkDecoder = new ApkDecoder(testApk, config);
|
|
ApkInfo apkInfo = apkDecoder.decode(sTestNewDir);
|
|
|
|
assertTrue("Expecting sparse resources", apkInfo.sparseResources);
|
|
|
|
LOGGER.info("Building sparse.apk...");
|
|
new ApkBuilder(sTestNewDir, config).build(testApk);
|
|
}
|
|
|
|
@Test
|
|
public void decodeWithExpectationOfNoSparseResources() throws BrutException, IOException {
|
|
ExtFile testApk = new ExtFile(sTestOrigDir, "not-sparse.apk");
|
|
|
|
LOGGER.info("Decoding not-sparse.apk...");
|
|
Config config = Config.getDefaultConfig();
|
|
config.frameworkTag = "issue-3298";
|
|
|
|
ApkDecoder apkDecoder = new ApkDecoder(testApk, config);
|
|
ApkInfo apkInfo = apkDecoder.decode(sTestNewDir);
|
|
|
|
assertFalse("Expecting not-sparse resources", apkInfo.sparseResources);
|
|
|
|
LOGGER.info("Building not-sparse.apk...");
|
|
new ApkBuilder(sTestNewDir, config).build(testApk);
|
|
}
|
|
}
|