diff --git a/.gitignore b/.gitignore index 32cd7f98d..782b60710 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,4 @@ /jme3-android-native/openal-soft/ /jme3-android-native/OpenALSoft.zip /jme3-android-native/stb_image/ +/jme3-bullet-native-android/build/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index 1cb069a56..52c71cee7 100644 --- a/build.gradle +++ b/build.gradle @@ -116,8 +116,8 @@ String findNDK() { } } -boolean ndkExists() { - String ndkCommandPath = findNDK() +boolean checkNdkExists(String ndkCommandPath) { +// String ndkCommandPath = findNDK() if (ndkCommandPath != null && new File(ndkCommandPath).exists()) { return true } else { @@ -125,6 +125,11 @@ boolean ndkExists() { } } +ext { + ndkCommandPath = findNDK() + ndkExists = checkNdkExists(ndkCommandPath) +} + //class IncrementalReverseTask extends DefaultTask { // @InputDirectory // def File inputDir diff --git a/gradle.properties b/gradle.properties index 0df1c0e51..d8edbb788 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,3 +12,8 @@ buildNativeProjects = true # Path to android NDK for building native libraries #ndkPath=/Users/normenhansen/Documents/Code-Import/android-ndk-r7 ndkPath = D:/android/android-ndk-r8e + +# Path for downloading native Bullet +bulletUrl = http://bullet.googlecode.com/files/bullet-2.82-r2704.zip +bulletFolder = bullet-2.82-r2704 +bulletZipFile = bullet.zip diff --git a/jme3-android-native/build.gradle b/jme3-android-native/build.gradle index adb0cdf81..380783bcd 100644 --- a/jme3-android-native/build.gradle +++ b/jme3-android-native/build.gradle @@ -39,13 +39,8 @@ ext { projectClassPath = configurations.runtime.asFileTree.matching { exclude ".gradle" }.asPath - - // findNDK() is defined in the root project gradle.build so it - // can be visible to all subprojects that need to build an Android native lib - ndkCommandPath = findNDK() } //println "projectClassPath = " + projectClassPath -//println "ndkCommandPath = " + ndkCommandPath // add each native lib build file apply from: file('openalsoft.gradle') diff --git a/jme3-android-native/openalsoft.gradle b/jme3-android-native/openalsoft.gradle index d5e302bae..1027f44ef 100644 --- a/jme3-android-native/openalsoft.gradle +++ b/jme3-android-native/openalsoft.gradle @@ -96,7 +96,7 @@ task buildOpenAlSoftNativeLib(type: Exec, dependsOn: generateOpenAlSoftHeaders) // println "ndkCommandPath: " + project.ndkCommandPath args 'TARGET_PLATFORM=android-9' workingDir openalsoftBuildDir - executable project.ndkCommandPath + executable rootProject.ndkCommandPath } task updatePreCompiledOpenAlSoftLibs(type: Copy, dependsOn: buildOpenAlSoftNativeLib) { @@ -121,7 +121,7 @@ task copyPreCompiledOpenAlSoftLibs(type: Copy) { into outputDir } -if (ndkExists()) { +if (rootProject.ndkExists) { // build native libs and update stored pre-compiled libs to commit compileJava.dependsOn { updatePreCompiledOpenAlSoftLibs } } else { diff --git a/jme3-android-native/stb_image.gradle b/jme3-android-native/stb_image.gradle index e4784e621..e5a0c3af7 100644 --- a/jme3-android-native/stb_image.gradle +++ b/jme3-android-native/stb_image.gradle @@ -76,7 +76,7 @@ task buildStbiNativeLib(type: Exec, dependsOn: generateStbiHeaders) { // println "ndkCommandPath: " + project.ndkCommandPath args 'TARGET_PLATFORM=android-9' workingDir stbiBuildDir - executable project.ndkCommandPath + executable rootProject.ndkCommandPath } task updatePreCompiledStbiLibs(type: Copy, dependsOn: buildStbiNativeLib) { @@ -100,7 +100,7 @@ task copyPreCompiledStbiLibs(type: Copy) { into outputDir } -if (ndkExists()) { +if (rootProject.ndkExists) { // build native libs and update stored pre-compiled libs to commit compileJava.dependsOn { updatePreCompiledStbiLibs } } else { diff --git a/jme3-bullet-native-android/build.gradle b/jme3-bullet-native-android/build.gradle new file mode 100644 index 000000000..982f4c34e --- /dev/null +++ b/jme3-bullet-native-android/build.gradle @@ -0,0 +1,213 @@ +String jmeBulletNativeProjectPath = '../jme3-bullet-native' + +String localUnzipPath = jmeBulletNativeProjectPath +String localZipFile = jmeBulletNativeProjectPath + File.separator + bulletZipFile +String localZipFolder = jmeBulletNativeProjectPath + File.separator + bulletFolder +String bulletSrcPath = localZipFolder + File.separator + 'src' + +String jmeAndroidPath = 'src/native/android' +String jmeCppPath = jmeBulletNativeProjectPath + '/src/native/cpp' + +//Working directories for the ndk build. +String ndkWorkingPath = "${buildDir}" + '/bullet' +String jniPath = ndkWorkingPath + '/jni' +String ndkOutputPath = ndkWorkingPath + '/libs' + +//Pre-compiled libs directory +String bulletPreCompiledLibsDir = 'libs' + +if (!hasProperty('mainClass')) { + ext.mainClass = '' +} + +dependencies { + compile project(':jme3-bullet') +} + +// Java source sets for IDE acces and source jar bundling / mavenization +sourceSets { + main { + java { + srcDir jmeCppPath + srcDir jmeAndroidPath + } + } +} + +// Download bullet if not available +task downloadBullet(type: MyDownload) { + sourceUrl = bulletUrl + target = file(localZipFile) +} + +// Unzip bullet if not available +task unzipBullet(type: Copy) { + def zipFile = file(localZipFile) + def outputDir = file(localUnzipPath) +// println "unzipBullet zipFile = " + zipFile.absolutePath +// println "unzipBullet outputDir = " + outputDir.absolutePath + + from zipTree(zipFile) + into outputDir +} +unzipBullet.dependsOn { + def zipFile = file(localZipFile) +// println "zipFile path: " + zipFile.absolutePath +// println "zipFile exists: " + zipFile.exists() + + if (!zipFile.exists()) { + downloadBullet + } +} + +// Copy Bullet files to jni directory +task copyBullet(type: Copy) { + def sourceDir = file(bulletSrcPath) + def outputDir = new File(jniPath) +// println "copyBullet sourceDir = " + sourceDir +// println "copyBullet outputDir = " + outputDir + + from sourceDir + into outputDir +} +copyBullet.dependsOn { + def bulletUnzipDir = file(localZipFolder) +// println "bulletUnzipDir: " + bulletUnzipDir.absolutePath +// println "bulletUnzipDir exists: " + bulletUnzipDir.exists() +// println "bulletUnzipDir isDirectory: " + bulletUnzipDir.isDirectory() + if (!bulletUnzipDir.isDirectory()) { + unzipBullet + } +} + +// Copy jME cpp native files to jni directory +task copyJmeCpp(type: Copy, dependsOn:copyBullet) { + def sourceDir = new File(jmeCppPath) + def outputDir = new File(jniPath) +// println "copyJmeCpp sourceDir = " + sourceDir +// println "copyJmeCpp outputDir = " + outputDir + + from sourceDir + into outputDir +} + +// Copy jME android native files to jni directory +task copyJmeAndroid(type: Copy, dependsOn:copyJmeCpp) { + def sourceDir = new File(jmeAndroidPath) + def outputDir = new File(jniPath) +// println "copyJmeAndroid sourceDir = " + sourceDir +// println "copyJmeAndroid outputDir = " + outputDir + + from sourceDir + into outputDir +} + +task generateNativeHeaders(dependsOn: copyJmeAndroid) << { + String destDirPath = jniPath + String classes = " \ + com.jme3.bullet.PhysicsSpace, \ + \ + com.jme3.bullet.collision.PhysicsCollisionEvent, \ + com.jme3.bullet.collision.PhysicsCollisionObject,\ + com.jme3.bullet.objects.PhysicsCharacter, \ + com.jme3.bullet.objects.PhysicsGhostObject, \ + com.jme3.bullet.objects.PhysicsRigidBody, \ + com.jme3.bullet.objects.PhysicsVehicle, \ + com.jme3.bullet.objects.VehicleWheel, \ + com.jme3.bullet.objects.infos.RigidBodyMotionState, \ + \ + com.jme3.bullet.collision.shapes.CollisionShape, \ + com.jme3.bullet.collision.shapes.BoxCollisionShape, \ + com.jme3.bullet.collision.shapes.CapsuleCollisionShape, \ + com.jme3.bullet.collision.shapes.CompoundCollisionShape, \ + com.jme3.bullet.collision.shapes.ConeCollisionShape, \ + com.jme3.bullet.collision.shapes.CylinderCollisionShape, \ + com.jme3.bullet.collision.shapes.GImpactCollisionShape, \ + com.jme3.bullet.collision.shapes.HeightfieldCollisionShape, \ + com.jme3.bullet.collision.shapes.HullCollisionShape, \ + com.jme3.bullet.collision.shapes.MeshCollisionShape, \ + com.jme3.bullet.collision.shapes.PlaneCollisionShape, \ + com.jme3.bullet.collision.shapes.SimplexCollisionShape, \ + com.jme3.bullet.collision.shapes.SphereCollisionShape, \ + \ + com.jme3.bullet.joints.PhysicsJoint, \ + com.jme3.bullet.joints.ConeJoint, \ + com.jme3.bullet.joints.HingeJoint, \ + com.jme3.bullet.joints.Point2PointJoint, \ + com.jme3.bullet.joints.SixDofJoint, \ + com.jme3.bullet.joints.SixDofSpringJoint, \ + com.jme3.bullet.joints.SliderJoint, \ + com.jme3.bullet.joints.motors.RotationalLimitMotor, \ + com.jme3.bullet.joints.motors.TranslationalLimitMotor, \ + \ + com.jme3.bullet.util.NativeMeshUtil, \ + com.jme3.bullet.util.DebugShapeFactory, \ + " + + String projectClassPath = configurations.runtime.asFileTree.matching { + exclude ".gradle" + }.asPath + + ant.javah( + classpath: projectClassPath, + destdir: destDirPath, + class: classes + ) + +} + +task buildBulletNativeLib(type: Exec, dependsOn: generateNativeHeaders) { + args 'TARGET_PLATFORM=android-9' +// println "buildBulletNativeLib ndkWorkingPath: " + ndkWorkingPath +// println "buildBulletNativeLib rootProject.ndkCommandPath: " + rootProject.ndkCommandPath + workingDir ndkWorkingPath + executable rootProject.ndkCommandPath +} + +//task updatePreCompiledBulletLibs(type: Copy, dependsOn: generateNativeHeaders) { +task updatePreCompiledBulletLibs(type: Copy, dependsOn: buildBulletNativeLib) { + def sourceDir = new File(ndkOutputPath) + def outputDir = new File(bulletPreCompiledLibsDir) +// println "updatePreCompiledBulletLibs sourceDir: " + sourceDir +// println "updatePreCompiledBulletLibs outputDir: " + outputDir + + from sourceDir + into outputDir +} + +// Copy pre-compiled libs to build directory (when not building new libs) +task copyPreCompiledBulletLibs(type: Copy) { + def sourceDir = new File(bulletPreCompiledLibsDir) + def outputDir = new File(ndkOutputPath) +// println "copyPreCompiledBulletLibs sourceDir: " + sourceDir +// println "copyPreCompiledBulletLibs outputDir: " + outputDir + + from sourceDir + into outputDir +} + +if (rootProject.ndkExists) { + // build native libs and update stored pre-compiled libs to commit + compileJava.dependsOn { updatePreCompiledBulletLibs } +} else { + // use pre-compiled native libs (not building new ones) + compileJava.dependsOn { copyPreCompiledBulletLibs } +} + +jar.into("lib") { from ndkOutputPath } + + +// Helper class to wrap ant dowload task +class MyDownload extends DefaultTask { + @Input + String sourceUrl + + @OutputFile + File target + + @TaskAction + void download() { + ant.get(src: sourceUrl, dest: target) + } +} + diff --git a/jme3-bullet-native-android/libs/armeabi-v7a/libbulletjme.so b/jme3-bullet-native-android/libs/armeabi-v7a/libbulletjme.so new file mode 100644 index 000000000..6e4d8039a Binary files /dev/null and b/jme3-bullet-native-android/libs/armeabi-v7a/libbulletjme.so differ diff --git a/jme3-bullet-native-android/libs/armeabi/libbulletjme.so b/jme3-bullet-native-android/libs/armeabi/libbulletjme.so new file mode 100644 index 000000000..00ac8a563 Binary files /dev/null and b/jme3-bullet-native-android/libs/armeabi/libbulletjme.so differ diff --git a/jme3-bullet-native-android/libs/mips/libbulletjme.so b/jme3-bullet-native-android/libs/mips/libbulletjme.so new file mode 100644 index 000000000..6da05bfa2 Binary files /dev/null and b/jme3-bullet-native-android/libs/mips/libbulletjme.so differ diff --git a/jme3-bullet-native-android/libs/x86/libbulletjme.so b/jme3-bullet-native-android/libs/x86/libbulletjme.so new file mode 100644 index 000000000..9f50a17a0 Binary files /dev/null and b/jme3-bullet-native-android/libs/x86/libbulletjme.so differ diff --git a/jme3-bullet-native-android/src/native/android/Android.mk b/jme3-bullet-native-android/src/native/android/Android.mk new file mode 100644 index 000000000..b46f8ec29 --- /dev/null +++ b/jme3-bullet-native-android/src/native/android/Android.mk @@ -0,0 +1,65 @@ +# /* +# Bullet Continuous Collision Detection and Physics Library for Android NDK +# Copyright (c) 2006-2009 Noritsuna Imamura http://www.siprop.org/ +# +# This software is provided 'as-is', without any express or implied warranty. +# In no event will the authors be held liable for any damages arising from the use of this software. +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it freely, +# subject to the following restrictions: +# +# 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +# 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +# 3. This notice may not be removed or altered from any source distribution. +# */ +LOCAL_PATH:= $(call my-dir) +BULLET_PATH:= ${LOCAL_PATH}/../ + +include $(CLEAR_VARS) + +LOCAL_MODULE := bulletjme +LOCAL_C_INCLUDES := $(BULLET_PATH)/\ + $(BULLET_PATH)/BulletCollision\ + $(BULLET_PATH)/BulletCollision/BroadphaseCollision\ + $(BULLET_PATH)/BulletCollision/CollisionDispatch\ + $(BULLET_PATH)/BulletCollision/CollisionShapes\ + $(BULLET_PATH)/BulletCollision/NarrowPhaseCollision\ + $(BULLET_PATH)/BulletCollision/Gimpact\ + $(BULLET_PATH)/BulletDynamics\ + $(BULLET_PATH)/BulletDynamics/ConstraintSolver\ + $(BULLET_PATH)/BulletDynamics/Dynamics\ + $(BULLET_PATH)/BulletDynamics/Vehicle\ + $(BULLET_PATH)/BulletDynamics/Character\ + $(BULLET_PATH)/BulletMultiThreaded\ + $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers\ + $(BULLET_PATH)/BulletMultiThreaded/SpuNarrowPhaseCollisionTask\ + $(BULLET_PATH)/BulletMultiThreaded/SpuSampleTask\ + $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/CPU\ + $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/DX11\ + $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL\ + $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/DX11/HLSL\ + $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/AMD\ + $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/Apple\ + $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/MiniCL\ + $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/NVidia\ + $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC\ + $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10\ + $(BULLET_PATH)/LinearMath\ + $(BULLET_PATH)/BulletSoftBody\ + $(BULLET_PATH)/LinearMath\ + $(BULLET_PATH)/MiniCL\ + $(BULLET_PATH)/MiniCL/MiniCLTask\ + $(BULLET_PATH)/vectormath\ + $(BULLET_PATH)/vectormath/scalar\ + $(BULLET_PATH)/vectormath/sse\ + $(BULLET_PATH)/vectormath/neon + +LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) +LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -ldl -lm -llog + +FILE_LIST := $(wildcard $(LOCAL_PATH)/*.cpp) +FILE_LIST += $(wildcard $(LOCAL_PATH)/**/*.cpp) +FILE_LIST += $(wildcard $(LOCAL_PATH)/**/**/*.cpp) +LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) + +include $(BUILD_SHARED_LIBRARY) \ No newline at end of file diff --git a/jme3-bullet-native-android/src/native/android/Application.mk b/jme3-bullet-native-android/src/native/android/Application.mk new file mode 100644 index 000000000..34f65f6e8 --- /dev/null +++ b/jme3-bullet-native-android/src/native/android/Application.mk @@ -0,0 +1,4 @@ +APP_OPTIM := release +APP_ABI := all +#APP_ABI := armeabi-v7a +APP_MODULES := bulletjme diff --git a/settings.gradle b/settings.gradle index 14ccda86b..3a01698aa 100644 --- a/settings.gradle +++ b/settings.gradle @@ -27,6 +27,7 @@ include 'jme3-ios' include 'jme3-bullet' //java if(buildNativeProjects == "true"){ include 'jme3-bullet-native' //cpp + include 'jme3-bullet-native-android' //cpp } include 'jme3-android-native' //cpp