Skip to content

Commit

Permalink
Merge pull request #1 from iBotPeaches/master
Browse files Browse the repository at this point in the history
update fork
  • Loading branch information
realityJie committed Nov 21, 2019
2 parents 31a23ba + b05f19b commit d91080e
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 29 deletions.
32 changes: 18 additions & 14 deletions INTERNAL.md
Expand Up @@ -224,15 +224,15 @@ original as they were.
### First we need the AOSP source

As cheesy as it is, just follow this [downloading](https://source.android.com/source/downloading.html) link in order
to get the source downloaded. This is no small download, expect to use 40-60GB.
to get the source downloaded. This is no small download, expect to use 80-100GB.

After that, you need to build AOSP via this [documentation](https://source.android.com/source/building.html) guide. Now
we aren't building the entire AOSP package, the initial build is to just see if you are capable of building it.

We check out a certain tag. Currently we use
We check out a certain tag or branch. Currently we use

* aapt2 - `android-9.0.0_r22`.
* aapt1 - `android-9.0.0_r22`.
* aapt2 - `master`.
* aapt1 - `master`.

### Including our modified `frameworks/base` package.

Expand All @@ -247,41 +247,45 @@ we lose the ability to quickly build just the aapt binary. So the Windows proced
#### Unix
1. `source build/envsetup.sh`
2. `lunch sdk-eng`
3. `make OUT_DIR=out-x64 LOCAL_MULTILIB=64 USE_NINJA=false aapt`
4. `strip out-x64/host/linux-x86/bin/aapt`
3. `make LOCAL_MULTILIB=64 USE_NINJA=false aapt`
4. `strip out/host/linux-x86/bin/aapt`
5. `strip out/host/linux-x86/bin/aapt_64`

#### Windows
1. `source build/envsetup.sh`
2. `lunch sdk-eng`
3. `make PRODUCT-sdk-win_sdk USE_NINJA=false`
3. `make LOCAL_MULTILIB=64 USE_NINJA=false aapt`
4. `strip out/host/windows-x86/bin/aapt.exe`
5. `strip out/host/windows-x86/bin/aapt_64.exe`

#### Mac
1. `source build/envsetup.sh`
2. `lunch sdk-eng`
3. `make OUT_DIR=out-x64 LOCAL_MULTILIB=64 USE_NINJA=false aapt`
4. `strip out-x64/host/darwin-x86/bin/aapt_64`
3. `make LOCAL_MULTILIB=64 USE_NINJA=false aapt`
4. `strip out/host/darwin-x86/bin/aapt_64`

As of Android Oreo (API 26) all aapt binaries are 64 bit (With exception of Windows).
32/64 bit binaries will be built for Unix and Windows.

### Building the aapt2 binary.

The steps below are different per flavor and operating system. For cross compiling the Windows binary on Unix,
we lose the ability to quickly build just the aapt2 binary. So the Windows procedure builds the entire Sdk.

#### Unix
1. `make OUT_DIR=out-x64 LOCAL_MULTILIB=64 USE_NINJA=false aapt2`
2. `strip out-x64/host/linux-x86/bin/aapt2`
1. `make LOCAL_MULTILIB=64 USE_NINJA=false aapt2`
2. `strip out/host/linux-x86/bin/aapt2`
3. `strip out/host/linux-x86/bin/aapt2_64`

#### Windows
1. `make PRODUCT-sdk-win_sdk USE_NINJA=false`
2. `strip out/host/windows-x86/bin/aapt2.exe`
3. `strip out/host/windows-x86/bin/aapt2_64.exe`

#### Mac
1. `export ANDROID_JAVA_HOME=/Path/To/Jdk`
2. `source build/envsetup.sh`
3. `make OUT_DIR=out-x64 LOCAL_MULTILIB=64 USE_NINJA=false aapt2`
4. `strip out-x64/host/darwin-x86/bin/aapt2_64`
3. `make LOCAL_MULTILIB=64 USE_NINJA=false aapt2`
4. `strip out/host/darwin-x86/bin/aapt2_64`

#### Confirming aapt/aapt2 builds are static

Expand Down
Expand Up @@ -519,6 +519,7 @@ private static void _Options() {
allOptions.addOption(quietOption);
allOptions.addOption(aapt2Option);
allOptions.addOption(noCrunchOption);
allOptions.addOption(onlyMainClassesOption);
}

private static String verbosityHelp() {
Expand Down
18 changes: 7 additions & 11 deletions brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java
Expand Up @@ -19,7 +19,6 @@
import brut.androlib.meta.MetaInfo;
import brut.androlib.meta.UsesFramework;
import brut.androlib.res.AndrolibResources;
import brut.androlib.res.data.ResConfigFlags;
import brut.androlib.res.data.ResPackage;
import brut.androlib.res.data.ResTable;
import brut.androlib.res.data.ResUnknownFiles;
Expand All @@ -42,7 +41,6 @@

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;

/**
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
Expand Down Expand Up @@ -168,15 +166,10 @@ public void recordUncompressedFiles(ExtFile apkFile, Collection<String> uncompre
String ext;

for (String file : files) {
if (isAPKFileNames(file) &&
unk.getCompressionLevel(file) == 0 &&
unk.getSize(file) != 0) {

if (isAPKFileNames(file) && unk.getCompressionLevel(file) == 0 && unk.getSize(file) != 0) {
ext = FilenameUtils.getExtension(file);

// If we don't have a png extension, but we have multiple "dots", we may have another iteration
// of OEM specific 9patch files. We need to record full path for these.
if (ext.isEmpty() || (!ext.equals("png") && StringUtils.countMatches(file, ".") > 1)) {
if (ext.isEmpty() || !NO_COMPRESS_PATTERN.matcher(ext).find()) {
ext = file;
}
if (!uncompressedFilesOrExts.contains(ext)) {
Expand Down Expand Up @@ -485,7 +478,7 @@ public boolean buildResourcesFull(File appDir, UsesFramework usesFramework)
ninePatch = null;
}
mAndRes.aaptPackage(apkFile, new File(appDir,
"AndroidManifest.xml"), new File(appDir, "res"),
"AndroidManifest.xml"), new File(appDir, "res"),
ninePatch, null, parseUsesFramework(usesFramework));

Directory tmpDir = new ExtFile(apkFile).getDirectory();
Expand Down Expand Up @@ -547,7 +540,7 @@ public boolean buildManifest(ExtFile appDir, UsesFramework usesFramework)
}

mAndRes.aaptPackage(apkFile, new File(appDir,
"AndroidManifest.xml"), null, ninePatch, null,
"AndroidManifest.xml"), null, ninePatch, null,
parseUsesFramework(usesFramework));

Directory tmpDir = new ExtFile(apkFile).getDirectory();
Expand Down Expand Up @@ -796,4 +789,7 @@ public void close() throws IOException {
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" };
private final static Pattern NO_COMPRESS_PATTERN = Pattern.compile("(" +
"jpg|jpeg|png|gif|wav|mp2|mp3|ogg|aac|mpg|mpeg|mid|midi|smf|jet|rtttl|imy|xmf|mp4|" +
"m4a|m4v|3gp|3gpp|3g2|3gpp2|amr|awb|wma|wmv|webm|mkv)$");
}
Expand Up @@ -317,8 +317,31 @@ public String checkTargetSdkVersionBounds() {
return Integer.toString(target);
}

private File createDoNotCompressExtensionsFile(ApkOptions apkOptions) throws AndrolibException {
if (apkOptions.doNotCompress == null || apkOptions.doNotCompress.isEmpty()) {
return null;
}

File doNotCompressFile;
try {
doNotCompressFile = File.createTempFile("APKTOOL", null);
doNotCompressFile.deleteOnExit();

BufferedWriter fileWriter = new BufferedWriter(new FileWriter(doNotCompressFile));
for (String extension : apkOptions.doNotCompress) {
fileWriter.write(extension);
fileWriter.newLine();
}
fileWriter.close();

return doNotCompressFile;
} catch (IOException ex) {
throw new AndrolibException(ex);
}
}

private void aapt2Package(File apkFile, File manifest, File resDir, File rawDir, File assetDir, File[] include,
List<String> cmd)
List<String> cmd, boolean customAapt)
throws AndrolibException {

List<String> compileCommand = new ArrayList<>(cmd);
Expand Down Expand Up @@ -425,7 +448,13 @@ private void aapt2Package(File apkFile, File manifest, File resDir, File rawDir,
cmd.add("-x");
}

if (apkOptions.doNotCompress != null) {
if (apkOptions.doNotCompress != null && !customAapt) {
// Use custom -e option to avoid limits on commandline length.
// Can only be used when custom aapt binary is not used.
String extensionsFilePath = createDoNotCompressExtensionsFile(apkOptions).getAbsolutePath();
cmd.add("-e");
cmd.add(extensionsFilePath);
} else if (apkOptions.doNotCompress != null) {
for (String file : apkOptions.doNotCompress) {
cmd.add("-0");
cmd.add(file);
Expand Down Expand Up @@ -541,12 +570,19 @@ private void aapt1Package(File apkFile, File manifest, File resDir, File rawDir,
cmd.add("-x");
}

if (apkOptions.doNotCompress != null) {
if (apkOptions.doNotCompress != null && !customAapt) {
// Use custom -e option to avoid limits on commandline length.
// Can only be used when custom aapt binary is not used.
String extensionsFilePath = createDoNotCompressExtensionsFile(apkOptions).getAbsolutePath();
cmd.add("-e");
cmd.add(extensionsFilePath);
} else if (apkOptions.doNotCompress != null) {
for (String file : apkOptions.doNotCompress) {
cmd.add("-0");
cmd.add(file);
}
}

if (!apkOptions.resourcesAreCompressed) {
cmd.add("-0");
cmd.add("arsc");
Expand Down Expand Up @@ -598,7 +634,7 @@ public void aaptPackage(File apkFile, File manifest, File resDir, File rawDir, F
}

if (apkOptions.isAapt2()) {
aapt2Package(apkFile, manifest, resDir, rawDir, assetDir, include, cmd);
aapt2Package(apkFile, manifest, resDir, rawDir, assetDir, include, cmd, customAapt);
return;
}
aapt1Package(apkFile, manifest, resDir, rawDir, assetDir, include, cmd, customAapt);
Expand Down
Binary file modified brut.apktool/apktool-lib/src/main/resources/prebuilt/linux/aapt
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions brut.j.util/src/main/java/brut/util/OSDetection.java
Expand Up @@ -33,6 +33,12 @@ public static boolean isUnix() {
}

public static boolean is64Bit() {
if (isWindows()) {
String arch = System.getenv("PROCESSOR_ARCHITECTURE");
String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432");

return arch != null && arch.endsWith("64") || wow64Arch != null && wow64Arch.endsWith("64");
}
return Bit.equalsIgnoreCase("64");
}

Expand Down

0 comments on commit d91080e

Please sign in to comment.