Search in sources :

Example 6 with DirectoryException

use of brut.directory.DirectoryException in project Apktool by iBotPeaches.

the class AndrolibResources method generateValuesFile.

private void generateValuesFile(ResValuesFile valuesFile, Directory out, ExtXmlSerializer serial) throws AndrolibException {
    try {
        OutputStream outStream = out.getFileOutput(valuesFile.getPath());
        serial.setOutput((outStream), null);
        serial.startDocument(null, null);
        serial.startTag(null, "resources");
        for (ResResource res : valuesFile.listResources()) {
            if (valuesFile.isSynthesized(res)) {
                continue;
            }
            ((ResValuesXmlSerializable) res.getValue()).serializeToResValuesXml(serial, res);
        }
        serial.endTag(null, "resources");
        serial.newLine();
        serial.endDocument();
        serial.flush();
        outStream.close();
    } catch (IOException | DirectoryException ex) {
        throw new AndrolibException("Could not generate: " + valuesFile.getPath(), ex);
    }
}
Also used : ResValuesXmlSerializable(brut.androlib.res.xml.ResValuesXmlSerializable) ZipOutputStream(java.util.zip.ZipOutputStream) AndrolibException(brut.androlib.AndrolibException) DirectoryException(brut.directory.DirectoryException)

Example 7 with DirectoryException

use of brut.directory.DirectoryException in project Apktool by iBotPeaches.

the class AndrolibResources method decodeManifestWithResources.

public void decodeManifestWithResources(ResTable resTable, ExtFile apkFile, File outDir) throws AndrolibException {
    Duo<ResFileDecoder, AXmlResourceParser> duo = getResFileDecoder();
    ResFileDecoder fileDecoder = duo.m1;
    ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder();
    attrDecoder.setCurrentPackage(resTable.listMainPackages().iterator().next());
    Directory inApk, in = null, out;
    try {
        inApk = apkFile.getDirectory();
        out = new FileDirectory(outDir);
        LOGGER.info("Decoding AndroidManifest.xml with resources...");
        fileDecoder.decodeManifest(inApk, "AndroidManifest.xml", out, "AndroidManifest.xml");
        // Remove versionName / versionCode (aapt API 16)
        if (!resTable.getAnalysisMode()) {
            // check for a mismatch between resources.arsc package and the package listed in AndroidManifest
            // also remove the android::versionCode / versionName from manifest for rebuild
            // this is a required change to prevent aapt warning about conflicting versions
            // it will be passed as a parameter to aapt like "--min-sdk-version" via apktool.yml
            adjustPackageManifest(resTable, outDir.getAbsolutePath() + File.separator + "AndroidManifest.xml");
            ResXmlPatcher.removeManifestVersions(new File(outDir.getAbsolutePath() + File.separator + "AndroidManifest.xml"));
            mPackageId = String.valueOf(resTable.getPackageId());
        }
    } catch (DirectoryException ex) {
        throw new AndrolibException(ex);
    }
}
Also used : FileDirectory(brut.directory.FileDirectory) AndrolibException(brut.androlib.AndrolibException) ZipFile(java.util.zip.ZipFile) ExtFile(brut.directory.ExtFile) DirectoryException(brut.directory.DirectoryException) FileDirectory(brut.directory.FileDirectory) Directory(brut.directory.Directory)

Example 8 with DirectoryException

use of brut.directory.DirectoryException in project Apktool by iBotPeaches.

the class SmaliBuilder method build.

private void build() throws AndrolibException {
    try {
        DexBuilder dexBuilder;
        if (mApiLevel > 0) {
            dexBuilder = DexBuilder.makeDexBuilder(Opcodes.forApi(mApiLevel));
        } else {
            dexBuilder = DexBuilder.makeDexBuilder();
        }
        for (String fileName : mSmaliDir.getDirectory().getFiles(true)) {
            buildFile(fileName, dexBuilder);
        }
        dexBuilder.writeTo(new FileDataStore(new File(mDexFile.getAbsolutePath())));
    } catch (IOException | DirectoryException ex) {
        throw new AndrolibException(ex);
    }
}
Also used : AndrolibException(brut.androlib.AndrolibException) FileDataStore(org.jf.dexlib2.writer.io.FileDataStore) ExtFile(brut.directory.ExtFile) DirectoryException(brut.directory.DirectoryException) DexBuilder(org.jf.dexlib2.writer.builder.DexBuilder)

Aggregations

DirectoryException (brut.directory.DirectoryException)8 AndrolibException (brut.androlib.AndrolibException)7 Directory (brut.directory.Directory)4 FileDirectory (brut.directory.FileDirectory)4 ExtFile (brut.directory.ExtFile)2 IOException (java.io.IOException)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 CantFindFrameworkResException (brut.androlib.err.CantFindFrameworkResException)1 InFileNotFoundException (brut.androlib.err.InFileNotFoundException)1 OutDirExistsException (brut.androlib.err.OutDirExistsException)1 ExtMXSerializer (brut.androlib.res.util.ExtMXSerializer)1 ResValuesXmlSerializable (brut.androlib.res.xml.ResValuesXmlSerializable)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 Matcher (java.util.regex.Matcher)1 ZipFile (java.util.zip.ZipFile)1 DexBuilder (org.jf.dexlib2.writer.builder.DexBuilder)1 FileDataStore (org.jf.dexlib2.writer.io.FileDataStore)1