build.gradle 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Note: "common.gradle" in the root project contains additional initialization
  2. // for this project. This initialization is applied in the "build.gradle"
  3. // of the root project.
  4. // NetBeans will automatically add "run" and "debug" tasks relying on the
  5. // "mainClass" property. You may however define the property prior executing
  6. // tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
  7. //
  8. // Note however, that you may define your own "run" and "debug" task if you
  9. // prefer. In this case NetBeans will not add these tasks but you may rely on
  10. // your own implementation.
  11. // // OpenAL Soft r1.15.1
  12. //String openALSoftUrl = 'http://repo.or.cz/w/openal-soft.git/snapshot/9b6a226da55a987cb883f425eeb568776ea12c8d.zip'
  13. // OpenAL Soft r1.15.1 + Android OpenSL Support
  14. String openALSoftUrl = 'http://repo.or.cz/w/openal-soft.git/snapshot/be25e6802dacad78876c6fa1d6a5c63797b8a9ed.zip'
  15. // OpenAL Soft r1.15.1 latest build (at the time)
  16. //String openALSoftUrl = 'http://repo.or.cz/w/openal-soft.git/snapshot/3f5914e0949ee12b504ee7254990e007ff8057ef.zip'
  17. // OpenAL Soft directory the download is extracted into
  18. // Typically, the downloaded OpenAL Soft zip file will extract to a directory
  19. // called "openal-soft"
  20. String openALSoftFolder = 'openal-soft'
  21. String openALSoftZipFile = 'OpenALSoft.zip'
  22. //Working directory for the ndk build.
  23. //Must be the parent directory of the jni directory
  24. //Libs directory (output of ndk) will be created in this directory as well
  25. String ndkWorkingPath = 'src/native'
  26. // jni folder path to build from
  27. String jniPath = ndkWorkingPath + '/jni'
  28. //Output directory of the NDK (do not change)
  29. String ndkOutputPath = ndkWorkingPath + '/libs'
  30. // jME Android Native source files path
  31. String jMEAndroidPath = 'src/native/android'
  32. if (!hasProperty('mainClass')) {
  33. ext.mainClass = ''
  34. }
  35. sourceSets {
  36. main {
  37. java {
  38. srcDir jMEAndroidPath
  39. }
  40. }
  41. }
  42. dependencies {
  43. // TODO: Add dependencies here
  44. // but note that JUnit should have already been added in parent.gradle.
  45. // By default, only the Maven Central Repository is specified in
  46. // parent.gradle.
  47. //
  48. // You can read more about how to add dependency here:
  49. // http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies
  50. compile project(':jme3-android')
  51. }
  52. // Download bullet if not available
  53. task downloadOpenALSoft(type: MyDownload) {
  54. sourceUrl = openALSoftUrl
  55. target = file(openALSoftZipFile)
  56. }
  57. // Unzip OpenALSoft
  58. task unzipOpenALSoft(type: Copy) {
  59. def zipFile = file(openALSoftZipFile)
  60. def outputDir = file(".")
  61. from zipTree(zipFile)
  62. into outputDir
  63. }
  64. unzipOpenALSoft.dependsOn {
  65. def zipFilePath = project.projectDir.absolutePath + File.separator + openALSoftZipFile
  66. def zipFile = new File(zipFilePath)
  67. // println "zipFile path: " + zipFile.absolutePath
  68. // println "zipFile exists: " + zipFile.exists()
  69. if (!zipFile.exists()) {
  70. downloadOpenALSoft
  71. }
  72. }
  73. // Copy OpenALSoft files to jni directory
  74. task copyOpenALSoft(type: Copy) {
  75. def sourceDir = file(openALSoftFolder)
  76. def outputDir = file(jniPath)
  77. from sourceDir
  78. into outputDir
  79. }
  80. copyOpenALSoft.dependsOn {
  81. def openALSoftUnzipDir = new File(project.projectDir.absolutePath + File.separator + openALSoftFolder)
  82. // println "openALSoftUnzipDir path: " + openALSoftUnzipDir.absolutePath
  83. // println "openALSoftUnzipDir exists: " + openALSoftUnzipDir.isDirectory()
  84. if (!openALSoftUnzipDir.isDirectory()) {
  85. unzipOpenALSoft
  86. }
  87. }
  88. // Copy jME Android native files to jni directory
  89. task copyJmeOpenALSoft(type: Copy, dependsOn:copyOpenALSoft) {
  90. def sourceDir = file(jMEAndroidPath)
  91. def outputDir = file(jniPath)
  92. from sourceDir
  93. into outputDir
  94. }
  95. task buildNative(type: Exec, dependsOn:copyJmeOpenALSoft) {
  96. String ndkBuildFile = "ndk-build"
  97. // if windows, use ndk-build.cmd instead
  98. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  99. ndkBuildFile = "ndk-build.cmd"
  100. }
  101. // ndkPath is defined in the root project gradle.properties file
  102. String ndkBuildPath = ndkPath + File.separator + ndkBuildFile
  103. //Use the environment variable for the NDK location if defined
  104. if (System.env.ANDROID_NDK != null) {
  105. ndkBuildPath = System.env.ANDROID_NDK + File.separator + ndkBuildFile
  106. }
  107. // need to target android-9 so the ndk can pull in the opensl library
  108. args 'TARGET_PLATFORM=android-9'
  109. workingDir ndkWorkingPath
  110. executable ndkBuildPath
  111. }
  112. jar.into("lib") { from ndkOutputPath }
  113. compileJava.dependsOn {
  114. // ndkPath is defined in the root project gradle.properties file
  115. def ndkDir = new File(ndkPath)
  116. if (ndkDir.isDirectory()) {
  117. buildNative
  118. }
  119. }
  120. // Helper class to wrap ant dowload task
  121. class MyDownload extends DefaultTask {
  122. @Input
  123. String sourceUrl
  124. @OutputFile
  125. File target
  126. @TaskAction
  127. void download() {
  128. ant.get(src: sourceUrl, dest: target)
  129. }
  130. }