crown-android.rb 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. # Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  2. # Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  3. #
  4. # Permission is hereby granted, free of charge, to any person
  5. # obtaining a copy of this software and associated documentation
  6. # files (the "Software"), to deal in the Software without
  7. # restriction, including without limitation the rights to use,
  8. # copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following
  11. # conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be
  14. # included in all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  18. # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. # OTHER DEALINGS IN THE SOFTWARE.
  24. require 'optparse'
  25. require 'ostruct'
  26. require 'fileutils'
  27. $android_create = "android create project"
  28. $android_update = "android update project"
  29. $activity = "CrownActivity"
  30. $package = "crown.android"
  31. $engine_src = "../engine/."
  32. $android_src = "../engine/os/android/java/."
  33. $config_src = "../engine/os/android/Config.h"
  34. $manifest = "../engine/os/android/AndroidManifest.xml"
  35. $luajit = "../engine/third/ARMv7/luajit"
  36. $oggvorbis = "../engine/third/ARMv7/oggvorbis"
  37. $physx = "../engine/third/ARMv7/physx"
  38. #------------------------------------------------------------------------------
  39. def validate_command_line(args)
  40. if args.length != 8
  41. return false
  42. end
  43. if args[0] != "--target"
  44. return false
  45. end
  46. if args[2] != "--name"
  47. return false
  48. end
  49. if args[4] != "--res"
  50. return false
  51. end
  52. if args[6] != "--path"
  53. return false
  54. end
  55. return true
  56. end
  57. #------------------------------------------------------------------------------
  58. def parse_command_line(args)
  59. banner = "Usage: crown-android.rb --target <android-target> --name <project-name> --path <project-path>\n"
  60. if not validate_command_line(args)
  61. print banner
  62. exit
  63. end
  64. options = OpenStruct.new
  65. OptionParser.new do |opts|
  66. opts.banner = banner
  67. opts.on("-t", "--target TARGET", "Android target") do |t|
  68. options.target = t
  69. end
  70. opts.on("-n", "--name NAME", "Android project name") do |n|
  71. options.name = n
  72. end
  73. opts.on("-r", "--res RES", "Android project compiled resources") do |r|
  74. options.res = r
  75. end
  76. opts.on("-p", "--path PATH", "Android project path") do |p|
  77. options.path = p
  78. end
  79. opts.on_tail("-h", "--help", "Show this message") do
  80. puts opts
  81. exit
  82. end
  83. end.parse!(args)
  84. return options
  85. end
  86. #------------------------------------------------------------------------------
  87. def create_android_project(target, name, path)
  88. engine_dest = path + "/jni"
  89. android_dest = path + "/src/crown/android"
  90. assets_dest = path + "/assets"
  91. # Creates path if not exists
  92. if not Dir.exists?(path)
  93. FileUtils.mkdir_p(path)
  94. end
  95. # Project path is empty
  96. if Dir[path + "/*"].empty?
  97. # Creates android project
  98. system($android_create + " --target " + target + " --name " + name + " --path " + path +
  99. " --activity " + $activity + " --package " + $package)
  100. else
  101. # Updates android project
  102. system($android_update + " --target " + target + " --name " + name + " --path " + path)
  103. end
  104. # if jni dir does not exists, create it!
  105. if not Dir.exists?(engine_dest)
  106. FileUtils.mkdir_p(engine_dest)
  107. print "Created directory " + engine_dest + "\n"
  108. end
  109. # if assets dir does not exists, create it!
  110. if not Dir.exists?(assets_dest)
  111. FileUtils.mkdir_p(assets_dest)
  112. print "Created directory " + assets_dest + "\n"
  113. end
  114. end
  115. #------------------------------------------------------------------------------
  116. def fill_android_project(res, path)
  117. engine_dest = path + "/jni"
  118. android_dest = path + "/src/crown/android"
  119. resources_dest = path + "/assets"
  120. # Copy Engine files
  121. FileUtils.cp_r($engine_src, engine_dest, :remove_destination => true)
  122. print "Copied Engine to " + engine_dest + "\n"
  123. # Copy android Config.h
  124. FileUtils.cp($config_src, engine_dest)
  125. print "Copied Config.h to " + engine_dest + "\n"
  126. # Copy luajit lib
  127. FileUtils.cp($luajit + "/lib/libluajit-5.1.so.2.0.2", engine_dest + "/libluajit-5.1.so")
  128. print "Copied luajit lib to " + engine_dest + "\n"
  129. # Copy oggvorbis lib
  130. FileUtils.cp($oggvorbis + "/lib/libogg.a", engine_dest + "/libogg.a")
  131. FileUtils.cp($oggvorbis + "/lib/libvorbis.a", engine_dest + "/libvorbis.a")
  132. print "Copied oggvorbis libs to " + engine_dest + "\n"
  133. # Copy physx lib
  134. FileUtils.cp($physx + "/lib/libPhysX3.a", engine_dest)
  135. FileUtils.cp($physx + "/lib/libSimulationController.a", engine_dest)
  136. FileUtils.cp($physx + "/lib/libLowLevel.a", engine_dest)
  137. FileUtils.cp($physx + "/lib/libLowLevelCloth.a", engine_dest)
  138. FileUtils.cp($physx + "/lib/libPxTask.a", engine_dest)
  139. FileUtils.cp($physx + "/lib/libPhysXProfileSDK.a", engine_dest)
  140. FileUtils.cp($physx + "/lib/libPhysX3Extensions.a", engine_dest)
  141. FileUtils.cp($physx + "/lib/libSceneQuery.a", engine_dest)
  142. FileUtils.cp($physx + "/lib/libPhysX3Common.a", engine_dest)
  143. FileUtils.cp($physx + "/lib/libPhysX3CharacterKinematic.a", engine_dest)
  144. FileUtils.cp($physx + "/lib/libPhysX3Vehicle.a", engine_dest)
  145. FileUtils.cp($physx + "/lib/libPhysX3Cooking.a", engine_dest)
  146. FileUtils.cp($physx + "/lib/libPvdRuntime.a", engine_dest)
  147. FileUtils.cp($physx + "/lib/libRepX3.a", engine_dest)
  148. # Copy Java files
  149. FileUtils.cp_r(Dir.glob($android_src), android_dest, :remove_destination => true)
  150. print "Copied Java files to " + android_dest + "\n"
  151. # Copy Android Manifest
  152. FileUtils.cp($manifest, path)
  153. print "Copied Android Manifest to " + path + "\n"
  154. #Copy resources
  155. FileUtils.cp_r(res + "/.", resources_dest, :remove_destination => true)
  156. print "Resources copied to " + resources_dest + "\n"
  157. end
  158. #------------------------------------------------------------------------------
  159. def build_android_project(path)
  160. # Move to root directory of Android project
  161. Dir.chdir(path)
  162. # Build libraries
  163. if not system("ndk-build")
  164. print "Critical error: Unable to build crown libraries"
  165. return
  166. end
  167. # Build apk
  168. if not system("ant debug")
  169. print "Critical error: Unable to build crown project"
  170. return
  171. end
  172. end
  173. #------------------------------------------------------------------------------
  174. opts = parse_command_line(ARGV)
  175. create_android_project(opts.target, opts.name, opts.path)
  176. fill_android_project(opts.res, opts.path)
  177. build_android_project(opts.path)