crown-android.rb 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 != 6
  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] != "--path"
  50. return false
  51. end
  52. return true
  53. end
  54. #------------------------------------------------------------------------------
  55. def parse_command_line(args)
  56. banner = "Usage: crown-android.rb --target <android-target> --name <project-name> --path <project-path>\n"
  57. if not validate_command_line(args)
  58. print banner
  59. exit
  60. end
  61. options = OpenStruct.new
  62. OptionParser.new do |opts|
  63. opts.banner = banner
  64. opts.on("-t", "--target TARGET", "Android target") do |t|
  65. options.target = t
  66. end
  67. opts.on("-n", "--name NAME", "Android project name") do |n|
  68. options.name = n
  69. end
  70. opts.on("-r", "--res RES", "Android project compiled resources") do |r|
  71. options.res = r
  72. end
  73. opts.on("-p", "--path PATH", "Android project path") do |p|
  74. options.path = p
  75. end
  76. opts.on_tail("-h", "--help", "Show this message") do
  77. puts opts
  78. exit
  79. end
  80. end.parse!(args)
  81. return options
  82. end
  83. #------------------------------------------------------------------------------
  84. def create_android_project(target, name, path)
  85. engine_dest = path + "/jni"
  86. android_dest = path + "/src/crown/android"
  87. assets_dest = path + "/assets"
  88. # Creates path if not exists
  89. if not Dir.exists?(path)
  90. FileUtils.mkdir_p(path)
  91. end
  92. # Project path is empty
  93. if Dir[path + "/*"].empty?
  94. # Creates android project
  95. system($android_create + " --target " + target + " --name " + name + " --path " + path +
  96. " --activity " + $activity + " --package " + $package)
  97. else
  98. # Updates android project
  99. system($android_update + " --target " + target + " --name " + name + " --path " + path)
  100. end
  101. # if jni dir does not exists, create it!
  102. if not Dir.exists?(engine_dest)
  103. FileUtils.mkdir_p(engine_dest)
  104. print "Created directory " + engine_dest + "\n"
  105. end
  106. # if assets dir does not exists, create it!
  107. if not Dir.exists?(assets_dest)
  108. FileUtils.mkdir_p(assets_dest)
  109. print "Created directory " + assets_dest + "\n"
  110. end
  111. end
  112. #------------------------------------------------------------------------------
  113. def fill_android_project(res, path)
  114. engine_dest = path + "/jni"
  115. android_dest = path + "/src/crown/android"
  116. resources_dest = path + "/assets"
  117. # Copy Engine files
  118. FileUtils.cp_r($engine_src, engine_dest, :remove_destination => true)
  119. print "Copied Engine to " + engine_dest + "\n"
  120. # Copy android Config.h
  121. FileUtils.cp($config_src, engine_dest)
  122. print "Copied Config.h to " + engine_dest + "\n"
  123. # Copy luajit lib
  124. FileUtils.cp($luajit + "/lib/libluajit-5.1.so.2.0.2", engine_dest + "/libluajit-5.1.so")
  125. print "Copied luajit lib to " + engine_dest + "\n"
  126. # Copy oggvorbis lib
  127. FileUtils.cp($oggvorbis + "/lib/libogg.a", engine_dest + "/libogg.a")
  128. FileUtils.cp($oggvorbis + "/lib/libvorbis.a", engine_dest + "/libvorbis.a")
  129. print "Copied oggvorbis libs to " + engine_dest + "\n"
  130. # Copy physx lib
  131. FileUtils.cp($physx + "/lib/libPhysX3.a", engine_dest)
  132. FileUtils.cp($physx + "/lib/libSimulationController.a", engine_dest)
  133. FileUtils.cp($physx + "/lib/libLowLevel.a", engine_dest)
  134. FileUtils.cp($physx + "/lib/libLowLevelCloth.a", engine_dest)
  135. FileUtils.cp($physx + "/lib/libPxTask.a", engine_dest)
  136. FileUtils.cp($physx + "/lib/libPhysXProfileSDK.a", engine_dest)
  137. FileUtils.cp($physx + "/lib/libPhysX3Extensions.a", engine_dest)
  138. FileUtils.cp($physx + "/lib/libSceneQuery.a", engine_dest)
  139. FileUtils.cp($physx + "/lib/libPhysX3Common.a", engine_dest)
  140. FileUtils.cp($physx + "/lib/libPhysX3CharacterKinematic.a", engine_dest)
  141. FileUtils.cp($physx + "/lib/libPhysX3Vehicle.a", engine_dest)
  142. FileUtils.cp($physx + "/lib/libPhysX3Cooking.a", engine_dest)
  143. FileUtils.cp($physx + "/lib/libPvdRuntime.a", engine_dest)
  144. FileUtils.cp($physx + "/lib/libRepX3.a", engine_dest)
  145. # Copy Java files
  146. FileUtils.cp_r(Dir.glob($android_src), android_dest, :remove_destination => true)
  147. print "Copied Java files to " + android_dest + "\n"
  148. # Copy Android Manifest
  149. FileUtils.cp($manifest, path)
  150. print "Copied Android Manifest to " + path + "\n"
  151. end
  152. #------------------------------------------------------------------------------
  153. def build_android_project(path)
  154. # Move to root directory of Android project
  155. Dir.chdir(path)
  156. # Build libraries
  157. if not system("ndk-build")
  158. print "Critical error: Unable to build crown libraries"
  159. return
  160. end
  161. # Build apk
  162. if not system("ant debug")
  163. print "Critical error: Unable to build crown project"
  164. return
  165. end
  166. end
  167. #------------------------------------------------------------------------------
  168. opts = parse_command_line(ARGV)
  169. create_android_project(opts.target, opts.name, opts.path)
  170. fill_android_project(opts.res, opts.path)
  171. build_android_project(opts.path)