build.gradle 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. String jmeBulletNativeProjectPath = project(":jme3-bullet-native").projectDir
  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 access 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. from zipTree(localZipFile)
  37. into file(localUnzipPath)
  38. }
  39. unzipBullet.dependsOn {
  40. if (!file(localZipFile).exists()) {
  41. downloadBullet
  42. }
  43. }
  44. // Copy Bullet files to jni directory
  45. task copyBullet(type: Copy) {
  46. from file(bulletSrcPath)
  47. into file(jniPath)
  48. }
  49. copyBullet.dependsOn {
  50. if (!file(localZipFolder).isDirectory()) {
  51. unzipBullet
  52. }
  53. }
  54. // Copy jME cpp native files to jni directory
  55. task copyJmeCpp(type: Copy) {
  56. from file(jmeCppPath)
  57. into file(jniPath)
  58. }
  59. // Copy jME android native files to jni directory
  60. task copyJmeAndroid(type: Copy) {
  61. from file(jmeAndroidPath)
  62. into file(jniPath)
  63. }
  64. task buildBulletNativeLib(type: Exec, dependsOn: [copyJmeAndroid, ':jme3-bullet:compileJava', copyJmeCpp, copyBullet]) {
  65. // args 'TARGET_PLATFORM=android-9'
  66. // println "buildBulletNativeLib ndkWorkingPath: " + ndkWorkingPath
  67. // println "buildBulletNativeLib rootProject.ndkCommandPath: " + rootProject.ndkCommandPath
  68. workingDir ndkWorkingPath
  69. executable rootProject.ndkCommandPath
  70. args "-j" + Runtime.runtime.availableProcessors()
  71. }
  72. /* The following two tasks: We store a prebuilt version in the repository, so nobody has to build
  73. * natives in order to build the engine. When building these natives however, the prebuilt libraries
  74. * can be updated (which is what the CI does). That's what the following two tasks do
  75. */
  76. task updatePreCompiledBulletLibs(type: Copy, dependsOn: buildBulletNativeLib) {
  77. from file(ndkOutputPath)
  78. into file(bulletPreCompiledLibsDir)
  79. }
  80. // Copy pre-compiled libs to build directory (when not building new libs)
  81. task copyPreCompiledBulletLibs(type: Copy) {
  82. from file(bulletPreCompiledLibsDir)
  83. into file(ndkOutputPath)
  84. }
  85. // ndkExists is a boolean from the build.gradle in the root project
  86. // buildNativeProjects is a string set to "true"
  87. if (ndkExists && buildNativeProjects == "true") {
  88. // build native libs and update stored pre-compiled libs to commit
  89. compileJava.dependsOn { updatePreCompiledBulletLibs }
  90. } else {
  91. // use pre-compiled native libs (not building new ones)
  92. compileJava.dependsOn { copyPreCompiledBulletLibs }
  93. }
  94. jar.into("lib") { from ndkOutputPath }
  95. // Helper class to wrap ant download task
  96. class MyDownload extends DefaultTask {
  97. @Input
  98. String sourceUrl
  99. @OutputFile
  100. File target
  101. @TaskAction
  102. void download() {
  103. ant.get(src: sourceUrl, dest: target)
  104. }
  105. }