openalsoft.gradle 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // OpenAL Soft r1.16
  2. String openALSoftUrl = 'https://github.com/jMonkeyEngine/openal-soft/archive/e5016f814a265ed592a88acea95cf912c4bfdf12.zip'
  3. String openALSoftZipFile = 'OpenALSoft.zip'
  4. // OpenAL Soft directory the download is extracted into
  5. // Typically, the downloaded OpenAL Soft zip file will extract to a directory
  6. // called "openal-soft"
  7. String openALSoftFolder = 'openal-soft-e5016f814a265ed592a88acea95cf912c4bfdf12'
  8. //Working directories for the ndk build.
  9. String openalsoftBuildDir = "${buildDir}" + File.separator + 'openalsoft'
  10. String openalsoftClassesBuildDir = "${buildDir}" + File.separator + 'openalsoft_classes'
  11. String openalsoftBuildJniDir = openalsoftBuildDir + File.separator + 'jni'
  12. String openalsoftBuildLibsDir = openalsoftBuildDir + File.separator + 'libs'
  13. //Pre-compiled libs directory
  14. def rootPath = rootProject.projectDir.absolutePath
  15. String openalsoftPreCompiledLibsDir = rootPath + File.separator + 'build' + File.separator + 'native' + File.separator + 'android' + File.separator + 'openalsoft'
  16. // jME Android Native source files path
  17. String openalsoftJmeAndroidPath = 'src/native/jme_openalsoft'
  18. String jmeHeaders = 'src/native/headers'
  19. // Download external source files if not available
  20. task downloadOpenALSoft(type: MyDownload) {
  21. sourceUrl = openALSoftUrl
  22. target = file(openalsoftBuildDir + File.separator + openALSoftZipFile)
  23. }
  24. // Unzip external source files
  25. task unzipOpenALSoft(type: Copy) {
  26. def zipFile = file(openalsoftBuildDir + File.separator + openALSoftZipFile)
  27. def outputDir = file(openalsoftBuildDir)
  28. from zipTree(zipFile)
  29. into outputDir
  30. }
  31. unzipOpenALSoft.dependsOn {
  32. def zipFilePath = openalsoftBuildDir + File.separator + openALSoftZipFile
  33. def zipFile = new File(zipFilePath)
  34. // println "zipFile path: " + zipFile.absolutePath
  35. // println "zipFile exists: " + zipFile.exists()
  36. if (!zipFile.exists()) {
  37. downloadOpenALSoft
  38. }
  39. }
  40. // Copy external source files to jni directory
  41. task copyOpenALSoft(type: Copy) {
  42. def sourceDir = file(openalsoftBuildDir + File.separator + openALSoftFolder)
  43. def outputDir = file(openalsoftBuildJniDir)
  44. // println "copyOpenALSoft sourceDir: " + sourceDir
  45. // println "copyOpenALSoft outputDir: " + outputDir
  46. from sourceDir
  47. into outputDir
  48. }
  49. copyOpenALSoft.dependsOn {
  50. def openALSoftUnzipDir = new File(project.projectDir.absolutePath + File.separator + openALSoftFolder)
  51. // println "openALSoftUnzipDir path: " + openALSoftUnzipDir.absolutePath
  52. // println "openALSoftUnzipDir exists: " + openALSoftUnzipDir.isDirectory()
  53. if (!openALSoftUnzipDir.isDirectory()) {
  54. unzipOpenALSoft
  55. }
  56. }
  57. // Copy JME Headers to jni directory
  58. task copyJmeHeadersOpenAL(type: Copy) {
  59. from file(jmeHeaders)
  60. into file(openalsoftBuildJniDir + File.separator + "headers")
  61. }
  62. // Copy jME Android native files to jni directory
  63. task copyJmeOpenALSoft(type: Copy, dependsOn: [copyOpenALSoft, copyJmeHeadersOpenAL]) {
  64. def sourceDir = file(openalsoftJmeAndroidPath)
  65. def outputDir = file(openalsoftBuildJniDir)
  66. // println "copyJmeOpenALSoft sourceDir: " + sourceDir
  67. // println "copyJmeOpenALSoft outputDir: " + outputDir
  68. from sourceDir
  69. into outputDir
  70. }
  71. task buildOpenAlSoftNativeLib(type: Exec, dependsOn: copyJmeOpenALSoft) {
  72. // println "openalsoft build dir: " + openalsoftBuildDir
  73. // println "ndkCommandPath: " + project.ndkCommandPath
  74. workingDir openalsoftBuildDir
  75. executable rootProject.ndkCommandPath
  76. args "-j" + Runtime.runtime.availableProcessors()
  77. }
  78. task updatePreCompiledOpenAlSoftLibs(type: Copy, dependsOn: buildOpenAlSoftNativeLib) {
  79. def sourceDir = new File(openalsoftBuildLibsDir)
  80. def outputDir = new File(openalsoftPreCompiledLibsDir)
  81. // println "updatePreCompiledOpenAlSoftLibs sourceDir: " + sourceDir
  82. // println "updatePreCompiledOpenAlSoftLibs outputDir: " + outputDir
  83. from sourceDir
  84. into outputDir
  85. }
  86. // Copy pre-compiled libs to build directory (when not building new libs)
  87. task copyPreCompiledOpenAlSoftLibs(type: Copy) {
  88. def sourceDir = file(openalsoftPreCompiledLibsDir)
  89. def outputDir = file(openalsoftBuildLibsDir)
  90. // println "copyStbiJmeFiles sourceDir: " + sourceDir
  91. // println "copyStbiJmeFiles outputDir: " + outputDir
  92. from sourceDir
  93. into outputDir
  94. }
  95. // ndkExists is a boolean from the build.gradle in the root project
  96. // buildNativeProjects is a string set to "true"
  97. if (ndkExists && buildNativeProjects == "true") {
  98. // build native libs and update stored pre-compiled libs to commit
  99. compileJava.dependsOn { updatePreCompiledOpenAlSoftLibs }
  100. } else {
  101. // use pre-compiled native libs (not building new ones)
  102. compileJava.dependsOn { copyPreCompiledOpenAlSoftLibs }
  103. }
  104. jar.into("lib") { from openalsoftBuildLibsDir }
  105. // Helper class to wrap ant dowload task
  106. class MyDownload extends DefaultTask {
  107. @Input
  108. String sourceUrl
  109. @OutputFile
  110. File target
  111. @TaskAction
  112. void download() {
  113. ant.get(src: sourceUrl, dest: target)
  114. }
  115. }