use of brut.androlib.meta.MetaInfo in project Apktool by iBotPeaches.
the class ApkDecoder method writeMetaFile.
private void writeMetaFile() throws AndrolibException {
MetaInfo meta = new MetaInfo();
meta.version = Androlib.getVersion();
meta.apkFileName = mApkFile.getName();
if (mDecodeResources != DECODE_RESOURCES_NONE && (hasManifest() || hasResources())) {
meta.isFrameworkApk = mAndrolib.isFrameworkApk(getResTable());
putUsesFramework(meta);
putSdkInfo(meta);
putPackageInfo(meta);
putVersionInfo(meta);
putSharedLibraryInfo(meta);
}
putUnknownInfo(meta);
putFileCompressionInfo(meta);
mAndrolib.writeMetaFile(mOutDir, meta);
}
use of brut.androlib.meta.MetaInfo in project Apktool by iBotPeaches.
the class ReferenceVersionCodeTest method referenceBecomesLiteralTest.
@Test
public void referenceBecomesLiteralTest() throws BrutException, IOException {
String apk = "issue1234.apk";
// decode issue1234.apk
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
ExtFile decodedApk = new ExtFile(sTmpDir + File.separator + apk + ".out");
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
apkDecoder.decode();
MetaInfo metaInfo = new Androlib().readMetaFile(decodedApk);
assertEquals("v1.0.0", metaInfo.versionInfo.versionName);
}
use of brut.androlib.meta.MetaInfo in project Apktool by iBotPeaches.
the class Androlib method build.
public void build(ExtFile appDir, File outFile) throws BrutException {
LOGGER.info("Using Apktool " + Androlib.getVersion());
MetaInfo meta = readMetaFile(appDir);
apkOptions.isFramework = meta.isFrameworkApk;
apkOptions.resourcesAreCompressed = meta.compressionType;
apkOptions.doNotCompress = meta.doNotCompress;
mAndRes.setSdkInfo(meta.sdkInfo);
mAndRes.setPackageId(meta.packageInfo);
mAndRes.setPackageRenamed(meta.packageInfo);
mAndRes.setVersionInfo(meta.versionInfo);
mAndRes.setSharedLibrary(meta.sharedLibrary);
if (meta.sdkInfo != null && meta.sdkInfo.get("minSdkVersion") != null) {
mMinSdkVersion = Integer.parseInt(meta.sdkInfo.get("minSdkVersion"));
}
if (outFile == null) {
String outFileName = meta.apkFileName;
outFile = new File(appDir, "dist" + File.separator + (outFileName == null ? "out.apk" : outFileName));
}
new File(appDir, APK_DIRNAME).mkdirs();
buildSources(appDir);
buildNonDefaultSources(appDir);
File manifest = new File(appDir, "AndroidManifest.xml");
File manifestOriginal = new File(appDir, "AndroidManifest.xml.orig");
if (manifest.isFile() && manifest.exists()) {
try {
if (manifestOriginal.exists()) {
manifestOriginal.delete();
}
FileUtils.copyFile(manifest, manifestOriginal);
ResXmlPatcher.fixingPublicAttrsInProviderAttributes(manifest);
} catch (IOException ex) {
throw new AndrolibException(ex.getMessage());
}
}
buildResources(appDir, meta.usesFramework);
buildLib(appDir);
buildLibs(appDir);
buildCopyOriginalFiles(appDir);
buildApk(appDir, outFile);
// we must go after the Apk is built, and copy the files in via Zip
// this is because Aapt won't add files it doesn't know (ex unknown files)
buildUnknownFiles(appDir, outFile, meta);
// lets restore the unedited one, to not change the original
if (manifest.isFile() && manifest.exists()) {
try {
if (new File(appDir, "AndroidManifest.xml").delete()) {
FileUtils.moveFile(manifestOriginal, manifest);
}
} catch (IOException ex) {
throw new AndrolibException(ex.getMessage());
}
}
}
use of brut.androlib.meta.MetaInfo in project Apktool by iBotPeaches.
the class BuildAndDecodeTest method compareUnknownFiles.
@SuppressWarnings("unchecked")
private void compareUnknownFiles() throws BrutException, IOException {
MetaInfo control = new Androlib().readMetaFile(sTestOrigDir);
MetaInfo test = new Androlib().readMetaFile(sTestNewDir);
assertNotNull(control.unknownFiles);
assertNotNull(test.unknownFiles);
Map<String, String> control_files = control.unknownFiles;
Map<String, String> test_files = test.unknownFiles;
assertTrue(control_files.size() == test_files.size());
// Make sure that the compression methods are still the same
for (Map.Entry<String, String> controlEntry : control_files.entrySet()) {
assertTrue(controlEntry.getValue().equals(test_files.get(controlEntry.getKey())));
}
}
use of brut.androlib.meta.MetaInfo in project Apktool by iBotPeaches.
the class DoubleExtensionUnknownFileTest method multipleExtensionUnknownFileTest.
@Test
public void multipleExtensionUnknownFileTest() throws BrutException, IOException {
String apk = "issue1244.apk";
// decode issue1244.apk
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
ExtFile decodedApk = new ExtFile(sTmpDir + File.separator + apk + ".out");
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
apkDecoder.decode();
MetaInfo metaInfo = new Androlib().readMetaFile(decodedApk);
for (String string : metaInfo.doNotCompress) {
if (StringUtils.countMatches(string, ".") > 1) {
assertTrue(string.equalsIgnoreCase("assets/bin/Data/sharedassets1.assets.split0"));
}
}
}