build.gradle 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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) {
  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) {
  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 buildBulletNativeLib(type: Exec, dependsOn: [copyJmeAndroid, copyJmeCpp, copyBullet]) {
  88. // args 'TARGET_PLATFORM=android-9'
  89. // println "buildBulletNativeLib ndkWorkingPath: " + ndkWorkingPath
  90. // println "buildBulletNativeLib rootProject.ndkCommandPath: " + rootProject.ndkCommandPath
  91. workingDir ndkWorkingPath
  92. executable rootProject.ndkCommandPath
  93. args "-j" + Runtime.runtime.availableProcessors()
  94. }
  95. //task updatePreCompiledBulletLibs(type: Copy, dependsOn: generateNativeHeaders) {
  96. task updatePreCompiledBulletLibs(type: Copy, dependsOn: buildBulletNativeLib) {
  97. def sourceDir = new File(ndkOutputPath)
  98. def outputDir = new File(bulletPreCompiledLibsDir)
  99. // println "updatePreCompiledBulletLibs sourceDir: " + sourceDir
  100. // println "updatePreCompiledBulletLibs outputDir: " + outputDir
  101. from sourceDir
  102. into outputDir
  103. }
  104. // Copy pre-compiled libs to build directory (when not building new libs)
  105. task copyPreCompiledBulletLibs(type: Copy) {
  106. def sourceDir = new File(bulletPreCompiledLibsDir)
  107. def outputDir = new File(ndkOutputPath)
  108. // println "copyPreCompiledBulletLibs sourceDir: " + sourceDir
  109. // println "copyPreCompiledBulletLibs outputDir: " + outputDir
  110. from sourceDir
  111. into outputDir
  112. }
  113. // ndkExists is a boolean from the build.gradle in the root project
  114. // buildNativeProjects is a string set to "true"
  115. if (ndkExists && buildNativeProjects == "true") {
  116. // build native libs and update stored pre-compiled libs to commit
  117. compileJava.dependsOn { updatePreCompiledBulletLibs }
  118. } else {
  119. // use pre-compiled native libs (not building new ones)
  120. compileJava.dependsOn { copyPreCompiledBulletLibs }
  121. }
  122. jar.into("lib") { from ndkOutputPath }
  123. // Helper class to wrap ant dowload task
  124. class MyDownload extends DefaultTask {
  125. @Input
  126. String sourceUrl
  127. @OutputFile
  128. File target
  129. @TaskAction
  130. void download() {
  131. ant.get(src: sourceUrl, dest: target)
  132. }
  133. }