blob: 6a6719c91b58a47a066adb0a2bf72258d2d5bda8 [file] [log] [blame]
Ryan Mitchell833a1a62018-07-10 13:51:36 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef AAPT2_CONVERT_H
18#define AAPT2_CONVERT_H
19
20#include "Command.h"
Ryan Mitchell4e9a9222018-11-13 10:40:07 -080021#include "LoadedApk.h"
Ryan Mitchell833a1a62018-07-10 13:51:36 -070022#include "format/binary/TableFlattener.h"
23
24namespace aapt {
25
26class ConvertCommand : public Command {
27 public:
28 explicit ConvertCommand() : Command("convert") {
29 SetDescription("Converts an apk between binary and proto formats.");
30 AddRequiredFlag("-o", "Output path", &output_path_);
31 AddOptionalFlag("--output-format", android::base::StringPrintf("Format of the output. "
32 "Accepted values are '%s' and '%s'. When not set, defaults to '%s'.",
33 kOutputFormatProto, kOutputFormatBinary, kOutputFormatBinary), &output_format_);
34 AddOptionalSwitch("--enable-sparse-encoding",
35 "Enables encoding sparse entries using a binary search tree.\n"
36 "This decreases APK size at the cost of resource retrieval performance.",
37 &options_.use_sparse_entries);
38 AddOptionalSwitch("-v", "Enables verbose logging", &verbose_);
39 }
40
41 int Action(const std::vector<std::string>& args) override;
42
43 private:
44 const static char* kOutputFormatProto;
45 const static char* kOutputFormatBinary;
46
47 TableFlattenerOptions options_;
48 std::string output_path_;
49 Maybe<std::string> output_format_;
50 bool verbose_ = false;
51};
52
Ryan Mitchell4e9a9222018-11-13 10:40:07 -080053int Convert(IAaptContext* context, LoadedApk* input, IArchiveWriter* output_writer,
54 ApkFormat output_format, TableFlattenerOptions& options);
55
56} // namespace aapt
Ryan Mitchell833a1a62018-07-10 13:51:36 -070057
58#endif //AAPT2_CONVERT_H