BuildAndroid.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include <Atomic/Core/StringUtils.h>
  5. #include <Atomic/IO/FileSystem.h>
  6. #include <Atomic/IO/File.h>
  7. #include "../ToolSystem.h"
  8. #include "../ToolEnvironment.h"
  9. #include "../Project/Project.h"
  10. #include "AndroidProjectGenerator.h"
  11. #include "BuildSystem.h"
  12. #include "BuildAndroid.h"
  13. namespace ToolCore
  14. {
  15. BuildAndroid::BuildAndroid(Context* context, Project* project) : BuildBase(context, project)
  16. {
  17. }
  18. BuildAndroid::~BuildAndroid()
  19. {
  20. }
  21. void BuildAndroid::Initialize()
  22. {
  23. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  24. Project* project = tsystem->GetProject();
  25. Vector<String> defaultResourcePaths;
  26. GetDefaultResourcePaths(defaultResourcePaths);
  27. String projectResources = project->GetResourcePath();
  28. for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
  29. {
  30. AddResourceDir(defaultResourcePaths[i]);
  31. }
  32. // TODO: smart filtering of cache
  33. AddResourceDir(project->GetProjectPath() + "Cache/");
  34. AddResourceDir(projectResources);
  35. BuildResourceEntries();
  36. }
  37. void BuildAndroid::Build(const String& buildPath)
  38. {
  39. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  40. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  41. Project* project = tsystem->GetProject();
  42. buildPath_ = AddTrailingSlash(buildPath) + GetBuildSubfolder();
  43. Initialize();
  44. //generate manifest file
  45. String manifest;
  46. for (unsigned i = 0; i < resourceEntries_.Size(); i++)
  47. {
  48. BuildResourceEntry* entry = resourceEntries_[i];
  49. manifest += entry->packagePath_;
  50. if ( i != resourceEntries_.Size() - 1)
  51. manifest += ";";
  52. }
  53. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  54. if (fileSystem->DirExists(buildPath_))
  55. fileSystem->RemoveDir(buildPath_, true);
  56. String buildSourceDir = tenv->GetToolDataDir();
  57. String androidProject = buildSourceDir + "Deployment/Android";
  58. // Copy the base android project
  59. fileSystem->CopyDir(androidProject, buildPath_);
  60. Vector<String> defaultResourcePaths;
  61. GetDefaultResourcePaths(defaultResourcePaths);
  62. String projectResources = project->GetResourcePath();
  63. for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
  64. {
  65. fileSystem->CopyDir(defaultResourcePaths[i], buildPath_ + "/assets/" + GetFileName(RemoveTrailingSlash(defaultResourcePaths[i])));
  66. }
  67. fileSystem->CopyDir(project->GetProjectPath() + "Cache/", buildPath_ + "/assets/Cache");
  68. fileSystem->CopyDir(projectResources, buildPath_ + "/assets/AtomicResources");
  69. // write the manifest
  70. SharedPtr<File> mfile(new File(context_, buildPath_ + "/assets/AtomicManifest", FILE_WRITE));
  71. mfile->WriteString(manifest);
  72. mfile->Close();
  73. AndroidProjectGenerator gen(context_);
  74. gen.SetBuildPath(buildPath_);
  75. if (!gen.Generate())
  76. {
  77. return;
  78. }
  79. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  80. buildSystem->BuildComplete(PLATFORMID_ANDROID, buildPath_);
  81. //fileSystem->SystemCommandAsync("/Applications/Firefox.app/Contents/MacOS/firefox");
  82. }
  83. }