1 #include <msp/fs/utils.h>
2 #include "androidassetpackagingtool.h"
3 #include "androidmanifestfile.h"
4 #include "androidresourcebundle.h"
5 #include "androidtools.h"
7 #include "externaltask.h"
8 #include "sourcepackage.h"
13 AndroidAssetPackagingTool::AndroidAssetPackagingTool(Builder &b, const AndroidSdk &s):
17 if(sdk.get_root_dir().empty())
18 problems.push_back("Android SDK not found");
19 else if(sdk.get_build_tools_dir().empty())
20 problems.push_back("Android build-tools not found");
22 set_command((sdk.get_build_tools_dir()/"aapt").str());
24 if(sdk.get_platform_jar().empty())
25 problems.push_back("Android platform not found");
28 Target *AndroidAssetPackagingTool::create_target(const list<Target *> &sources, const string &)
30 AndroidManifestFile *manifest = 0;
31 list<FileTarget *> resources;
32 for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
34 if(AndroidManifestFile *m = dynamic_cast<AndroidManifestFile *>(*i))
36 else if(FileTarget *f = dynamic_cast<FileTarget *>(*i))
37 resources.push_back(f);
41 throw invalid_argument("AndroidAssetPackagingTool::create_target");
43 AndroidResourceBundle *res = new AndroidResourceBundle(builder, *manifest->get_component(), *manifest, resources);
48 Task *AndroidAssetPackagingTool::run(const Target &tgt) const
50 const AndroidResourceBundle &res = dynamic_cast<const AndroidResourceBundle &>(tgt);
52 ExternalTask::Arguments argv;
53 argv.push_back(executable->get_path().str());
54 argv.push_back("package");
56 FS::Path work_dir = res.get_component()->get_package().get_source_directory();
59 argv.push_back(sdk.get_platform_jar().str());
62 argv.push_back(FS::relative(res.get_path(), work_dir).str());
64 const Target::Dependencies &depends = res.get_dependencies();
65 list<FS::Path> resource_dirs;
66 for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
68 FileTarget *file = dynamic_cast<FileTarget *>(*i);
69 Target *real = (*i)->get_real_target();
71 if(dynamic_cast<AndroidManifestFile *>(real))
74 argv.push_back(FS::relative(file->get_path(), work_dir).str());
76 else if(real->get_package()==res.get_package())
78 const FS::Path &path = file->get_path();
79 resource_dirs.push_back(path.subpath(0, path.size()-2));
83 set<string> seen_dirs;
84 for(list<FS::Path>::const_iterator i=resource_dirs.begin(); i!=resource_dirs.end(); ++i)
85 if(seen_dirs.insert(i->str()).second)
88 argv.push_back(FS::relative(*i, work_dir).str());
91 return new ExternalTask(argv, work_dir);