build.gradle 3.8 KB

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