Bullet(Cocos2dx)之交叉编译Android,集成到cocos2dx3.x
新建两个文件Android.mk,Application.mk
Application.mk内容如下:
APP_ABI:=armeabiarmeabi-v7ax86
APP_PLATFORM:=android-8
APP_STL:=stlport_static
Android.mk内容如下:
LOCAL_PATH:=$(callmy-dir)
include$(CLEAR_VARS)
LOCAL_MODULE :=bullet_static(可随便起)
LOCAL_MODULE_FILENAME:=libbullet(可随便起)
LOCAL_C_INCLUDES:=src/(头文件位置)
(源文件,要列出所有用到的,这里用到BulletSoftBodyBulletDynamics
BulletCollisionsLinearMath)
- LOCAL_SRC_FILES:=src/BulletSoftBody/btSoftBody.cpp\
- src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp\
- src/BulletSoftBody/btSoftBodyHelpers.cpp\
- src/BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.cpp\
- src/BulletSoftBody/btSoftRigidCollisionAlgorithm.cpp\
- src/BulletSoftBody/btSoftRigidDynamicsWorld.cpp\
- src/BulletSoftBody/btSoftSoftCollisionAlgorithm.cpp\
- src/BulletSoftBody/btDefaultSoftBodySolver.cpp\
- src/BulletDynamics/Character/btKinematicCharacterController.cpp\
- src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp\
- src/BulletDynamics/ConstraintSolver/btContactConstraint.cpp\
- src/BulletDynamics/ConstraintSolver/btFixedConstraint.cpp\
- src/BulletDynamics/ConstraintSolver/btGearConstraint.cpp\
- src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp\
- src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp\
- src/BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.cpp\
- src/BulletDynamics/ConstraintSolver/btHinge2Constraint.cpp\
- src/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp\
- src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.cpp\
- src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp\
- src/BulletDynamics/ConstraintSolver/btNNCGConstraintSolver.cpp\
- src/BulletDynamics/ConstraintSolver/btSliderConstraint.cpp\
- src/BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.cpp\
- src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp\
- src/BulletDynamics/ConstraintSolver/btUniversalConstraint.cpp\
- src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp\
- src/BulletDynamics/Dynamics/btRigidBody.cpp\
- src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp\
- src/BulletDynamics/Vehicle/btRaycastVehicle.cpp\
- src/BulletDynamics/Vehicle/btWheelInfo.cpp\
- src/BulletDynamics/Featherstone/btMultiBody.cpp\
- src/BulletDynamics/Featherstone/btMultiBodyConstraintSolver.cpp\
- src/BulletDynamics/Featherstone/btMultiBodyDynamicsWorld.cpp\
- src/BulletDynamics/Featherstone/btMultiBodyJointLimitConstraint.cpp\
- src/BulletDynamics/Featherstone/btMultiBodyConstraint.cpp\
- src/BulletDynamics/Featherstone/btMultiBodyPoint2Point.cpp\
- src/BulletDynamics/Featherstone/btMultiBodyJointMotor.cpp\
- src/BulletDynamics/MLCPSolvers/btDantzigLCP.cpp\
- src/BulletDynamics/MLCPSolvers/btMLCPSolver.cpp\
- src/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.cpp\
- src/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp\
- src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.cpp\
- src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.cpp\
- src/BulletCollision/BroadphaseCollision/btDbvt.cpp\
- src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp\
- src/BulletCollision/BroadphaseCollision/btDispatcher.cpp\
- src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp\
- src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp\
- src/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp\
- src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp\
- src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp\
- src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp\
- src/BulletCollision/CollisionDispatch/btCollisionObject.cpp\
- src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp\
- src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp\
- src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp\
- src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btGhostObject.cpp\
- src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.cpp\
- src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp\
- src/BulletCollision/CollisionDispatch/btManifoldResult.cpp\
- src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp\
- src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp\
- src/BulletCollision/CollisionDispatch/btUnionFind.cpp\
- src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp\
- src/BulletCollision/CollisionShapes/btBoxShape.cpp\
- src/BulletCollision/CollisionShapes/btBox2dShape.cpp\
- src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp\
- src/BulletCollision/CollisionShapes/btCapsuleShape.cpp\
- src/BulletCollision/CollisionShapes/btCollisionShape.cpp\
- src/BulletCollision/CollisionShapes/btCompoundShape.cpp\
- src/BulletCollision/CollisionShapes/btConcaveShape.cpp\
- src/BulletCollision/CollisionShapes/btConeShape.cpp\
- src/BulletCollision/CollisionShapes/btConvexHullShape.cpp\
- src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp\
- src/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp\
- src/BulletCollision/CollisionShapes/btConvexPolyhedron.cpp\
- src/BulletCollision/CollisionShapes/btConvexShape.cpp\
- src/BulletCollision/CollisionShapes/btConvex2dShape.cpp\
- src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp\
- src/BulletCollision/CollisionShapes/btCylinderShape.cpp\
- src/BulletCollision/CollisionShapes/btEmptyShape.cpp\
- src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp\
- src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp\
- src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.cpp\
- src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp\
- src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp\
- src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp\
- src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp\
- src/BulletCollision/CollisionShapes/btShapeHull.cpp\
- src/BulletCollision/CollisionShapes/btSphereShape.cpp\
- src/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp\
- src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp\
- src/BulletCollision/CollisionShapes/btTetrahedronShape.cpp\
- src/BulletCollision/CollisionShapes/btTriangleBuffer.cpp\
- src/BulletCollision/CollisionShapes/btTriangleCallback.cpp\
- src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp\
- src/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp\
- src/BulletCollision/CollisionShapes/btTriangleMesh.cpp\
- src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp\
- src/BulletCollision/CollisionShapes/btUniformScalingShape.cpp\
- src/BulletCollision/Gimpact/btContactProcessing.cpp\
- src/BulletCollision/Gimpact/btGenericPoolAllocator.cpp\
- src/BulletCollision/Gimpact/btGImpactBvh.cpp\
- src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.cpp\
- src/BulletCollision/Gimpact/btGImpactQuantizedBvh.cpp\
- src/BulletCollision/Gimpact/btGImpactShape.cpp\
- src/BulletCollision/Gimpact/btTriangleShapeEx.cpp\
- src/BulletCollision/Gimpact/gim_Box_set.cpp\
- src/BulletCollision/Gimpact/gim_contact.cpp\
- src/BulletCollision/Gimpact/gim_memory.cpp\
- src/BulletCollision/Gimpact/gim_tri_collision.cpp\
- src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp\
- src/BulletCollision/NarrowPhaseCollision/btConvexCast.cpp\
- src/BulletCollision/NarrowPhaseCollision/btGjkConvexCast.cpp\
- src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp\
- src/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp\
- src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp\
- src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp\
- src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp\
- src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.cpp\
- src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp\
- src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp\
- src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp\
- src/LinearMath/btAlignedAllocator.cpp\
- src/LinearMath/btConvexHull.cpp\
- src/LinearMath/btConvexHullComputer.cpp\
- src/LinearMath/btGeometryUtil.cpp\
- src/LinearMath/btPolarDecomposition.cpp\
- src/LinearMath/btQuickprof.cpp\
- src/LinearMath/btSerializer.cpp\
- src/LinearMath/btVector3.cpp
最后还要加上一句,表示生成静态库如果将STATIC该文SHARED则生成动态库
include$(BUILD_STATIC_LIBRARY)
然后进入命令行
进入jni所在目录
ndk-build
等待编译完成
将三个目录下的libbullet.a分别复制到cocos2dx的安装目录下的
安装目录\Cocos\frameworks\cocos2d-x\prebuilt\android\相应文件下
进入Cocos\frameworks\cocos2d-x\external
新建文件夹Bullet,在Bullet下新建prebuild-mk
将Box2D\prebuild-mk下的Android.mk复制到Bullet/prebuild-mk
修改如下3行
LOCAL_MODULE:=bullet_static
LOCAL_MODULE_FILENAME:=libbullet
LOCAL_SRC_FILES:=../../../prebuilt/android/$(TARGET_ARCH_ABI)/libbullet.a
复制头文件
将bullet3的src的所有文件复制到新建的Bullet文件下
下一步任务繁重,
将所有用到BulletCollisionBulletDynamicsBulletSoftBodyLinearMath目录下的include都加上Bullet/,可以使用Notepad++在Bullet目录搜索Bullet,并替换为Bullet/Bullet,LinearMath并替换为Bullet/LinearMath
进入Cocos\frameworks\cocos2d-x\cocos\prebuilt-mk
在Android.mk
在LOCAL_WHOLE_STATIC_LIBRARIES+=Box2d_static下面添加
LOCAL_WHOLE_STATIC_LIBRARIES+=bullet_static
$(callimport-module,Box2D/prebuilt-mk)下面添加
$(callimport-module,Bullet/prebuilt-mk)
至此已经完成编译静态库