build.gradle 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. String jmeBulletNativeProjectPath = '../jme3-bullet-native'
  2. String localUnzipPath = jmeBulletNativeProjectPath
  3. String localZipFile = jmeBulletNativeProjectPath + File.separator + bulletZipFile
  4. String localZipFolder = jmeBulletNativeProjectPath + File.separator + bulletFolder
  5. String bulletSrcPath = localZipFolder + File.separator + 'src'
  6. String jmeAndroidPath = 'src/native/android'
  7. String jmeCppPath = jmeBulletNativeProjectPath + '/src/native/cpp'
  8. //Working directories for the ndk build.
  9. String ndkWorkingPath = "${buildDir}" + '/bullet'
  10. String jniPath = ndkWorkingPath + '/jni'
  11. String ndkOutputPath = ndkWorkingPath + '/libs'
  12. //Pre-compiled libs directory
  13. String bulletPreCompiledLibsDir = 'libs'
  14. if (!hasProperty('mainClass')) {
  15. ext.mainClass = ''
  16. }
  17. dependencies {
  18. compile project(':jme3-bullet')
  19. }
  20. // Java source sets for IDE acces and source jar bundling / mavenization
  21. sourceSets {
  22. main {
  23. java {
  24. srcDir jmeCppPath
  25. srcDir jmeAndroidPath
  26. }
  27. }
  28. }
  29. // Download bullet if not available
  30. task downloadBullet(type: MyDownload) {
  31. sourceUrl = bulletUrl
  32. target = file(localZipFile)
  33. }
  34. // Unzip bullet if not available
  35. task unzipBullet(type: Copy) {
  36. def zipFile = file(localZipFile)
  37. def outputDir = file(localUnzipPath)
  38. // println "unzipBullet zipFile = " + zipFile.absolutePath
  39. // println "unzipBullet outputDir = " + outputDir.absolutePath
  40. from zipTree(zipFile)
  41. into outputDir
  42. }
  43. unzipBullet.dependsOn {
  44. def zipFile = file(localZipFile)
  45. // println "zipFile path: " + zipFile.absolutePath
  46. // println "zipFile exists: " + zipFile.exists()
  47. if (!zipFile.exists()) {
  48. downloadBullet
  49. }
  50. }
  51. // Copy Bullet files to jni directory
  52. task copyBullet(type: Copy) {
  53. def sourceDir = file(bulletSrcPath)
  54. def outputDir = new File(jniPath)
  55. // println "copyBullet sourceDir = " + sourceDir
  56. // println "copyBullet outputDir = " + outputDir
  57. from sourceDir
  58. into outputDir
  59. }
  60. copyBullet.dependsOn {
  61. def bulletUnzipDir = file(localZipFolder)
  62. // println "bulletUnzipDir: " + bulletUnzipDir.absolutePath
  63. // println "bulletUnzipDir exists: " + bulletUnzipDir.exists()
  64. // println "bulletUnzipDir isDirectory: " + bulletUnzipDir.isDirectory()
  65. if (!bulletUnzipDir.isDirectory()) {
  66. unzipBullet
  67. }
  68. }
  69. // Copy jME cpp native files to jni directory
  70. task copyJmeCpp(type: Copy, dependsOn:copyBullet) {
  71. def sourceDir = new File(jmeCppPath)
  72. def outputDir = new File(jniPath)
  73. // println "copyJmeCpp sourceDir = " + sourceDir
  74. // println "copyJmeCpp outputDir = " + outputDir
  75. from sourceDir
  76. into outputDir
  77. }
  78. // Copy jME android native files to jni directory
  79. task copyJmeAndroid(type: Copy, dependsOn:copyJmeCpp) {
  80. def sourceDir = new File(jmeAndroidPath)
  81. def outputDir = new File(jniPath)
  82. // println "copyJmeAndroid sourceDir = " + sourceDir
  83. // println "copyJmeAndroid outputDir = " + outputDir
  84. from sourceDir
  85. into outputDir
  86. }
  87. task generateNativeHeaders(dependsOn: copyJmeAndroid) << {
  88. String destDirPath = jniPath
  89. String classes = " \
  90. com.jme3.bullet.PhysicsSpace, \
  91. \
  92. com.jme3.bullet.collision.PhysicsCollisionEvent, \
  93. com.jme3.bullet.collision.PhysicsCollisionObject,\
  94. com.jme3.bullet.objects.PhysicsCharacter, \
  95. com.jme3.bullet.objects.PhysicsGhostObject, \
  96. com.jme3.bullet.objects.PhysicsRigidBody, \
  97. com.jme3.bullet.objects.PhysicsVehicle, \
  98. com.jme3.bullet.objects.VehicleWheel, \
  99. com.jme3.bullet.objects.infos.RigidBodyMotionState, \
  100. \
  101. com.jme3.bullet.collision.shapes.CollisionShape, \
  102. com.jme3.bullet.collision.shapes.BoxCollisionShape, \
  103. com.jme3.bullet.collision.shapes.CapsuleCollisionShape, \
  104. com.jme3.bullet.collision.shapes.CompoundCollisionShape, \
  105. com.jme3.bullet.collision.shapes.ConeCollisionShape, \
  106. com.jme3.bullet.collision.shapes.CylinderCollisionShape, \
  107. com.jme3.bullet.collision.shapes.GImpactCollisionShape, \
  108. com.jme3.bullet.collision.shapes.HeightfieldCollisionShape, \
  109. com.jme3.bullet.collision.shapes.HullCollisionShape, \
  110. com.jme3.bullet.collision.shapes.MeshCollisionShape, \
  111. com.jme3.bullet.collision.shapes.PlaneCollisionShape, \
  112. com.jme3.bullet.collision.shapes.SimplexCollisionShape, \
  113. com.jme3.bullet.collision.shapes.SphereCollisionShape, \
  114. \
  115. com.jme3.bullet.joints.PhysicsJoint, \
  116. com.jme3.bullet.joints.ConeJoint, \
  117. com.jme3.bullet.joints.HingeJoint, \
  118. com.jme3.bullet.joints.Point2PointJoint, \
  119. com.jme3.bullet.joints.SixDofJoint, \
  120. com.jme3.bullet.joints.SixDofSpringJoint, \
  121. com.jme3.bullet.joints.SliderJoint, \
  122. com.jme3.bullet.joints.motors.RotationalLimitMotor, \
  123. com.jme3.bullet.joints.motors.TranslationalLimitMotor, \
  124. \
  125. com.jme3.bullet.util.NativeMeshUtil, \
  126. com.jme3.bullet.util.DebugShapeFactory"
  127. String projectClassPath = configurations.runtime.asFileTree.matching {
  128. exclude ".gradle"
  129. }.asPath
  130. exec {
  131. executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
  132. args '-d', destDirPath
  133. args '-classpath', projectClassPath
  134. args classes.split(",").collect { it.trim() }
  135. }
  136. }
  137. task buildBulletNativeLib(type: Exec, dependsOn: generateNativeHeaders) {
  138. // args 'TARGET_PLATFORM=android-9'
  139. // println "buildBulletNativeLib ndkWorkingPath: " + ndkWorkingPath
  140. // println "buildBulletNativeLib rootProject.ndkCommandPath: " + rootProject.ndkCommandPath
  141. workingDir ndkWorkingPath
  142. executable rootProject.ndkCommandPath
  143. args "-j" + Runtime.runtime.availableProcessors()
  144. }
  145. //task updatePreCompiledBulletLibs(type: Copy, dependsOn: generateNativeHeaders) {
  146. task updatePreCompiledBulletLibs(type: Copy, dependsOn: buildBulletNativeLib) {
  147. def sourceDir = new File(ndkOutputPath)
  148. def outputDir = new File(bulletPreCompiledLibsDir)
  149. // println "updatePreCompiledBulletLibs sourceDir: " + sourceDir
  150. // println "updatePreCompiledBulletLibs outputDir: " + outputDir
  151. from sourceDir
  152. into outputDir
  153. }
  154. // Copy pre-compiled libs to build directory (when not building new libs)
  155. task copyPreCompiledBulletLibs(type: Copy) {
  156. def sourceDir = new File(bulletPreCompiledLibsDir)
  157. def outputDir = new File(ndkOutputPath)
  158. // println "copyPreCompiledBulletLibs sourceDir: " + sourceDir
  159. // println "copyPreCompiledBulletLibs outputDir: " + outputDir
  160. from sourceDir
  161. into outputDir
  162. }
  163. // ndkExists is a boolean from the build.gradle in the root project
  164. // buildNativeProjects is a string set to "true"
  165. if (ndkExists && buildNativeProjects == "true") {
  166. // build native libs and update stored pre-compiled libs to commit
  167. compileJava.dependsOn { updatePreCompiledBulletLibs }
  168. } else {
  169. // use pre-compiled native libs (not building new ones)
  170. compileJava.dependsOn { copyPreCompiledBulletLibs }
  171. }
  172. jar.into("lib") { from ndkOutputPath }
  173. // Helper class to wrap ant dowload task
  174. class MyDownload extends DefaultTask {
  175. @Input
  176. String sourceUrl
  177. @OutputFile
  178. File target
  179. @TaskAction
  180. void download() {
  181. ant.get(src: sourceUrl, dest: target)
  182. }
  183. }