mirror of https://github.com/axmolengine/axmol.git
Merge branch 'gles20' of https://github.com/cocos2d/cocos2d-x into gles20
This commit is contained in:
commit
2fd9c16276
|
@ -6,7 +6,26 @@ LOCAL_MODULE := cocosdenshion_static
|
|||
LOCAL_MODULE_FILENAME := libcocosdenshion
|
||||
|
||||
LOCAL_SRC_FILES := SimpleAudioEngine.cpp \
|
||||
jni/SimpleAudioEngineJni.cpp
|
||||
jni/SimpleAudioEngineJni.cpp
|
||||
|
||||
# for OpenSLES
|
||||
ifeq ($(APP_PLATFORM), android-9)
|
||||
|
||||
# define # define the macro to compile through CocosDenshion/android/SimpleAudioEngine.cpp
|
||||
# LOCAL_CFLAGS := -DENABLE_OPENSL
|
||||
|
||||
LOCAL_SRC_FILES += opensl/OpenSLEngine.cpp \
|
||||
opensl/SimpleAudioEngineOpenSL.cpp
|
||||
|
||||
LOCAL_EXPORT_LDLIBS := -lOpenSLES\
|
||||
-landroid
|
||||
|
||||
LOCAL_LDLIBS := -lOpenSLES
|
||||
LOCAL_LDLIBS += -llog
|
||||
LOCAL_LDLIBS += -landroid
|
||||
|
||||
endif
|
||||
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include
|
||||
|
||||
|
@ -14,7 +33,5 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include \
|
|||
$(LOCAL_PATH)/../../cocos2dx \
|
||||
$(LOCAL_PATH)/../../cocos2dx/include \
|
||||
$(LOCAL_PATH)/../../cocos2dx/platform/android
|
||||
|
||||
LOCAL_LDLIBS := -llog
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
|
|
@ -25,18 +25,27 @@ THE SOFTWARE.
|
|||
#include "SimpleAudioEngine.h"
|
||||
#include "jni/SimpleAudioEngineJni.h"
|
||||
|
||||
/*
|
||||
* for OpenSLES on Android 2.3 and above
|
||||
*/
|
||||
#ifdef ENABLE_OPENSL
|
||||
#include "opensl/SimpleAudioEngineOpenSL.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace CocosDenshion {
|
||||
|
||||
static SimpleAudioEngine *s_pEngine = 0;
|
||||
|
||||
SimpleAudioEngine::SimpleAudioEngine()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SimpleAudioEngine::~SimpleAudioEngine()
|
||||
{
|
||||
|
||||
#ifdef ENABLE_OPENSL
|
||||
SimpleAudioEngineOpenSL::sharedEngine()->end();
|
||||
#endif
|
||||
}
|
||||
|
||||
SimpleAudioEngine* SimpleAudioEngine::sharedEngine()
|
||||
|
@ -52,6 +61,10 @@ SimpleAudioEngine* SimpleAudioEngine::sharedEngine()
|
|||
void SimpleAudioEngine::end()
|
||||
{
|
||||
endJNI();
|
||||
|
||||
#ifdef ENABLE_OPENSL
|
||||
SimpleAudioEngineOpenSL::sharedEngine()->end();
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
|
||||
|
@ -106,57 +119,103 @@ void SimpleAudioEngine::setBackgroundMusicVolume(float volume)
|
|||
|
||||
float SimpleAudioEngine::getEffectsVolume()
|
||||
{
|
||||
return getEffectsVolumeJNI();
|
||||
#ifdef ENABLE_OPENSL
|
||||
return SimpleAudioEngineOpenSL::sharedEngine()->getEffectsVolume();
|
||||
#else
|
||||
return getEffectsVolumeJNI();
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::setEffectsVolume(float volume)
|
||||
{
|
||||
setEffectsVolumeJNI(volume);
|
||||
#ifdef ENABLE_OPENSL
|
||||
// @TO-DO
|
||||
// Here may crash, fixing.
|
||||
// SimpleAudioEngineOpenSL::sharedEngine()->setEffectsVolume(volume);
|
||||
#else
|
||||
setEffectsVolumeJNI(volume);
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
|
||||
{
|
||||
return playEffectJNI(pszFilePath, bLoop);
|
||||
#ifdef ENABLE_OPENSL
|
||||
return SimpleAudioEngineOpenSL::sharedEngine()->playEffect(pszFilePath, bLoop);
|
||||
#else
|
||||
return playEffectJNI(pszFilePath, bLoop);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
|
||||
{
|
||||
stopEffectJNI(nSoundId);
|
||||
#ifdef ENABLE_OPENSL
|
||||
SimpleAudioEngineOpenSL::sharedEngine()->stopEffect(nSoundId);
|
||||
#else
|
||||
stopEffectJNI(nSoundId);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
|
||||
{
|
||||
preloadEffectJNI(pszFilePath);
|
||||
#ifdef ENABLE_OPENSL
|
||||
SimpleAudioEngineOpenSL::sharedEngine()->preloadEffect(pszFilePath);
|
||||
#else
|
||||
preloadEffectJNI(pszFilePath);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::unloadEffect(const char* pszFilePath)
|
||||
{
|
||||
unloadEffectJNI(pszFilePath);
|
||||
#ifdef ENABLE_OPENSL
|
||||
SimpleAudioEngineOpenSL::sharedEngine()->unloadEffect(pszFilePath);
|
||||
#else
|
||||
unloadEffectJNI(pszFilePath);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::pauseEffect(unsigned int nSoundId)
|
||||
{
|
||||
pauseEffectJNI(nSoundId);
|
||||
#ifdef ENABLE_OPENSL
|
||||
SimpleAudioEngineOpenSL::sharedEngine()->pauseEffect(nSoundId);
|
||||
#else
|
||||
pauseEffectJNI(nSoundId);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::pauseAllEffects()
|
||||
{
|
||||
pauseAllEffectsJNI();
|
||||
#ifdef ENABLE_OPENSL
|
||||
SimpleAudioEngineOpenSL::sharedEngine()->pauseAllEffects();
|
||||
#else
|
||||
pauseAllEffectsJNI();
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::resumeEffect(unsigned int nSoundId)
|
||||
{
|
||||
resumeEffectJNI(nSoundId);
|
||||
#ifdef ENABLE_OPENSL
|
||||
SimpleAudioEngineOpenSL::sharedEngine()->resumeEffect(nSoundId);
|
||||
#else
|
||||
resumeEffectJNI(nSoundId);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::resumeAllEffects()
|
||||
{
|
||||
resumeAllEffectsJNI();
|
||||
#ifdef ENABLE_OPENSL
|
||||
SimpleAudioEngineOpenSL::sharedEngine()->resumeAllEffects();
|
||||
#else
|
||||
resumeAllEffectsJNI();
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::stopAllEffects()
|
||||
{
|
||||
stopAllEffectsJNI();
|
||||
#ifdef ENABLE_OPENSL
|
||||
SimpleAudioEngineOpenSL::sharedEngine()->stopAllEffects();
|
||||
#else
|
||||
stopAllEffectsJNI();
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,558 @@
|
|||
#include "OpenSLEngine.h"
|
||||
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,"OPENSL_ENGINE.CPP", __VA_ARGS__)
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
OpenSLEngine::OpenSLEngine()
|
||||
:m_musicVolume(0),
|
||||
m_effectVolume(0)
|
||||
{}
|
||||
|
||||
OpenSLEngine::~OpenSLEngine()
|
||||
{
|
||||
closeEngine();
|
||||
}
|
||||
|
||||
/**********************************************************************************
|
||||
* jni
|
||||
**********************************************************************************/
|
||||
#define CLASS_NAME "org/cocos2dx/lib/Cocos2dxActivity"
|
||||
|
||||
typedef struct JniMethodInfo_
|
||||
{
|
||||
JNIEnv * env;
|
||||
jclass classID;
|
||||
jmethodID methodID;
|
||||
} JniMethodInfo;
|
||||
|
||||
extern "C" {
|
||||
static JNIEnv* getJNIEnv(void)
|
||||
{
|
||||
|
||||
JavaVM* jvm = cocos2d::JniHelper::getJavaVM();
|
||||
if (NULL == jvm) {
|
||||
LOGD("Failed to get JNIEnv. JniHelper::getJavaVM() is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JNIEnv *env = NULL;
|
||||
// get jni environment
|
||||
jint ret = jvm->GetEnv((void**)&env, JNI_VERSION_1_4);
|
||||
|
||||
switch (ret) {
|
||||
case JNI_OK :
|
||||
// Success!
|
||||
return env;
|
||||
|
||||
case JNI_EDETACHED :
|
||||
// Thread not attached
|
||||
|
||||
// TODO : If calling AttachCurrentThread() on a native thread
|
||||
// must call DetachCurrentThread() in future.
|
||||
// see: http://developer.android.com/guide/practices/design/jni.html
|
||||
|
||||
if (jvm->AttachCurrentThread(&env, NULL) < 0)
|
||||
{
|
||||
LOGD("Failed to get the environment using AttachCurrentThread()");
|
||||
return NULL;
|
||||
} else {
|
||||
// Success : Attached and obtained JNIEnv!
|
||||
return env;
|
||||
}
|
||||
|
||||
case JNI_EVERSION :
|
||||
// Cannot recover from this error
|
||||
LOGD("JNI interface version 1.4 not supported");
|
||||
default :
|
||||
LOGD("Failed to get the environment using GetEnv()");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static jclass getClassID(JNIEnv *pEnv)
|
||||
{
|
||||
jclass ret = pEnv->FindClass(CLASS_NAME);
|
||||
if (! ret)
|
||||
{
|
||||
LOGD("Failed to find class of %s", CLASS_NAME);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool getStaticMethodInfo(JniMethodInfo &methodinfo, const char *methodName, const char *paramCode)
|
||||
{
|
||||
jmethodID methodID = 0;
|
||||
JNIEnv *pEnv = 0;
|
||||
bool bRet = false;
|
||||
|
||||
do
|
||||
{
|
||||
pEnv = getJNIEnv();
|
||||
if (! pEnv)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
jclass classID = getClassID(pEnv);
|
||||
|
||||
methodID = pEnv->GetStaticMethodID(classID, methodName, paramCode);
|
||||
if (! methodID)
|
||||
{
|
||||
LOGD("Failed to find static method id of %s", methodName);
|
||||
break;
|
||||
}
|
||||
|
||||
methodinfo.classID = classID;
|
||||
methodinfo.env = pEnv;
|
||||
methodinfo.methodID = methodID;
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*********************************************************************************
|
||||
* helper
|
||||
********************************************************************************/
|
||||
#define PLAYSTATE_STOPPED 1
|
||||
#define PLAYSTATE_PAUSED 2
|
||||
#define PLAYSTATE_PLAYING 3
|
||||
#define FILE_NOT_FOUND -1
|
||||
#define ASSET_MANAGER_GETTER "getAssetManager"
|
||||
|
||||
struct AudioPlayer
|
||||
{
|
||||
AAsset* Asset;
|
||||
SLDataSource audioSrc;
|
||||
SLObjectItf fdPlayerObject;
|
||||
SLPlayItf fdPlayerPlay;
|
||||
SLSeekItf fdPlayerSeek;
|
||||
SLVolumeItf fdPlayerVolume;
|
||||
} musicPlayer; /* for background music */
|
||||
|
||||
typedef map<unsigned int, AudioPlayer *> EffectList;
|
||||
typedef pair<unsigned int, AudioPlayer *> Effect;
|
||||
|
||||
static EffectList& sharedList()
|
||||
{
|
||||
static EffectList s_List;
|
||||
return s_List;
|
||||
}
|
||||
|
||||
unsigned int _Hash(const char *key)
|
||||
{
|
||||
unsigned int len = strlen(key);
|
||||
const char *end=key+len;
|
||||
unsigned int hash;
|
||||
|
||||
for (hash = 0; key < end; key++)
|
||||
{
|
||||
hash *= 16777619;
|
||||
hash ^= (unsigned int) (unsigned char) toupper(*key);
|
||||
}
|
||||
return (hash);
|
||||
}
|
||||
|
||||
int getFileDescriptor(AudioPlayer * player, const char * filename, off_t & start, off_t & length)
|
||||
{
|
||||
JniMethodInfo methodInfo;
|
||||
if (! getStaticMethodInfo(methodInfo, ASSET_MANAGER_GETTER, "()Landroid/content/res/AssetManager;"))
|
||||
{
|
||||
return FILE_NOT_FOUND;
|
||||
}
|
||||
jobject assetManager = methodInfo.env->CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID);
|
||||
methodInfo.env->DeleteLocalRef(methodInfo.classID);
|
||||
|
||||
AAssetManager* mgr = AAssetManager_fromJava(methodInfo.env, assetManager);
|
||||
assert(NULL != mgr);
|
||||
player->Asset = AAssetManager_open(mgr, filename, AASSET_MODE_UNKNOWN);
|
||||
|
||||
if (player->Asset == NULL)
|
||||
{
|
||||
LOGD("file not found! Stop preload file: %s", filename);
|
||||
return FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
// open asset as file descriptor
|
||||
int fd = AAsset_openFileDescriptor(player->Asset, &start, &length);
|
||||
assert(0 <= fd);
|
||||
AAsset_close(player->Asset);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************************
|
||||
* engine
|
||||
**********************************************************************************/
|
||||
static SLObjectItf s_pEngineObject = NULL;
|
||||
static SLEngineItf s_pEngineEngine = NULL;
|
||||
static SLObjectItf s_pOutputMixObject = NULL;
|
||||
|
||||
bool initAudioPlayer(AudioPlayer* player, const char* filename)
|
||||
{
|
||||
// configure audio sink
|
||||
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, s_pOutputMixObject};
|
||||
SLDataSink audioSnk = {&loc_outmix, NULL};
|
||||
|
||||
// configure audio source
|
||||
off_t start, length;
|
||||
int fd = getFileDescriptor(player, filename, start, length);
|
||||
if (FILE_NOT_FOUND == fd)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
SLDataLocator_AndroidFD loc_fd = {SL_DATALOCATOR_ANDROIDFD, fd, start, length};
|
||||
SLDataFormat_MIME format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
|
||||
(player->audioSrc) = {&loc_fd, &format_mime};
|
||||
|
||||
// create audio player
|
||||
const SLInterfaceID ids[3] = {SL_IID_SEEK, SL_IID_MUTESOLO, SL_IID_VOLUME};
|
||||
const SLboolean req[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
|
||||
SLresult result = (*s_pEngineEngine)->CreateAudioPlayer(s_pEngineEngine, &(player->fdPlayerObject), &(player->audioSrc), &audioSnk, 3, ids, req);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
|
||||
// realize the player
|
||||
result = (*(player->fdPlayerObject))->Realize(player->fdPlayerObject, SL_BOOLEAN_FALSE);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
|
||||
// get the play interface
|
||||
result = (*(player->fdPlayerObject))->GetInterface(player->fdPlayerObject, SL_IID_PLAY, &(player->fdPlayerPlay));
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
|
||||
// get the volume interface
|
||||
result = (*(player->fdPlayerObject))->GetInterface(player->fdPlayerObject, SL_IID_VOLUME, &(player->fdPlayerVolume));
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
|
||||
// get the volume interface
|
||||
result = (*(player->fdPlayerObject))->GetInterface(player->fdPlayerObject, SL_IID_SEEK, &(player->fdPlayerSeek));
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void destroyAudioPlayer(AudioPlayer * player)
|
||||
{
|
||||
if (player->fdPlayerObject != NULL){
|
||||
(*(player->fdPlayerObject))->Destroy(player->fdPlayerObject);
|
||||
player->fdPlayerObject = NULL;
|
||||
player->fdPlayerPlay = NULL;
|
||||
player->fdPlayerSeek = NULL;
|
||||
player->fdPlayerVolume = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSLEngine::createEngine()
|
||||
{
|
||||
SLresult result;
|
||||
LOGD("createEngine");
|
||||
|
||||
// create engine
|
||||
if (s_pEngineObject == NULL)
|
||||
{
|
||||
result = slCreateEngine(&s_pEngineObject, 0, NULL, 0, NULL, NULL);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
|
||||
// realize the engine
|
||||
result = (*s_pEngineObject)->Realize(s_pEngineObject, SL_BOOLEAN_FALSE);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
|
||||
// get the engine interface, which is needed in order to create other objects
|
||||
result = (*s_pEngineObject)->GetInterface(s_pEngineObject, SL_IID_ENGINE, &s_pEngineEngine);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
|
||||
// create output mix
|
||||
const SLInterfaceID ids[1] = {SL_IID_ENVIRONMENTALREVERB};
|
||||
const SLboolean req[1] = {SL_BOOLEAN_FALSE};
|
||||
result = (*s_pEngineEngine)->CreateOutputMix(s_pEngineEngine, &s_pOutputMixObject, 1, ids, req);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
}
|
||||
|
||||
// realize the output mix
|
||||
result = (*s_pOutputMixObject)->Realize(s_pOutputMixObject, SL_BOOLEAN_FALSE);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
}
|
||||
|
||||
void OpenSLEngine::closeEngine()
|
||||
{
|
||||
// destroy background players
|
||||
destroyAudioPlayer(&musicPlayer);
|
||||
|
||||
// destroy effect players
|
||||
EffectList::iterator p = sharedList().begin();
|
||||
while (p != sharedList().end())
|
||||
{
|
||||
destroyAudioPlayer(p->second);
|
||||
p++;
|
||||
}
|
||||
sharedList().clear();
|
||||
|
||||
// destroy output mix interface
|
||||
if (s_pOutputMixObject != NULL) {
|
||||
(*s_pOutputMixObject)->Destroy(s_pOutputMixObject);
|
||||
s_pOutputMixObject = NULL;
|
||||
}
|
||||
|
||||
// destroy opensl engine
|
||||
if (s_pEngineObject != NULL) {
|
||||
(*s_pEngineObject)->Destroy(s_pEngineObject);
|
||||
s_pEngineObject = NULL;
|
||||
s_pEngineEngine = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************************
|
||||
* background music
|
||||
**********************************************************************************/
|
||||
bool OpenSLEngine::preloadBackgroundMusic(const char * filename)
|
||||
{
|
||||
if (musicPlayer.Asset != NULL)
|
||||
{
|
||||
if (musicPlayer.fdPlayerPlay != NULL)
|
||||
{
|
||||
SLresult result = (*(musicPlayer.fdPlayerPlay))->SetPlayState(musicPlayer.fdPlayerPlay, SL_PLAYSTATE_STOPPED);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
}
|
||||
free(musicPlayer.Asset);
|
||||
musicPlayer.Asset = NULL;
|
||||
}
|
||||
|
||||
return initAudioPlayer(&musicPlayer, filename);
|
||||
}
|
||||
|
||||
void OpenSLEngine::setBackgroundMusicState(int state)
|
||||
{
|
||||
SLresult result;
|
||||
if (NULL != musicPlayer.fdPlayerPlay) {
|
||||
result = (*(musicPlayer.fdPlayerPlay))->SetPlayState(musicPlayer.fdPlayerPlay, state);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
}
|
||||
}
|
||||
|
||||
int OpenSLEngine::getBackgroundMusicState()
|
||||
{
|
||||
SLresult result;
|
||||
SLuint32 state;
|
||||
if (musicPlayer.fdPlayerPlay != NULL)
|
||||
{
|
||||
result = (*(musicPlayer.fdPlayerPlay))->GetPlayState(musicPlayer.fdPlayerPlay, &state);
|
||||
assert(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
return (int)state;
|
||||
}
|
||||
|
||||
void OpenSLEngine::rewindBackgroundMusic()
|
||||
{
|
||||
SLresult result;
|
||||
|
||||
result = (*(musicPlayer.fdPlayerSeek))->SetPosition(musicPlayer.fdPlayerSeek, 0, SL_SEEKMODE_FAST);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
|
||||
result = (*(musicPlayer.fdPlayerPlay))->SetPlayState(musicPlayer.fdPlayerPlay, SL_PLAYSTATE_PLAYING);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
}
|
||||
|
||||
void OpenSLEngine::setBackgroundMusicLooping(bool isLooping)
|
||||
{
|
||||
SLresult result;
|
||||
if (NULL != musicPlayer.fdPlayerSeek)
|
||||
{
|
||||
result = (*(musicPlayer.fdPlayerSeek))->SetLoop(musicPlayer.fdPlayerSeek, (SLboolean) isLooping, 0, SL_TIME_UNKNOWN);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSLEngine::setBackgroundVolume(int volume)
|
||||
{
|
||||
m_musicVolume = volume;
|
||||
|
||||
SLresult result;
|
||||
if (NULL != musicPlayer.fdPlayerVolume) {
|
||||
result = (*(musicPlayer.fdPlayerVolume))->SetVolumeLevel(musicPlayer.fdPlayerVolume, m_musicVolume);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
}
|
||||
}
|
||||
|
||||
int OpenSLEngine::getBackgroundVolume()
|
||||
{
|
||||
return m_musicVolume;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************************
|
||||
* sound effect
|
||||
**********************************************************************************/
|
||||
#define NORMAL_EFFECT_CALLBACK 1
|
||||
#define REPLAY_EFFECT_CALLBACK 2
|
||||
|
||||
//typedef struct _CallbackContext
|
||||
//{
|
||||
// int type;
|
||||
// AudioPlayer* player;
|
||||
//} CallbackContext;
|
||||
//
|
||||
//void effectPlayCallback(SLPlayItf caller, void * context, SLuint32 event)
|
||||
//{
|
||||
// CallbackContext* callback = (CallbackContext*)context;
|
||||
// switch(callback->type)
|
||||
// {
|
||||
// case NORMAL_EFFECT_CALLBACK :
|
||||
// // TO-DO
|
||||
// break;
|
||||
// case REPLAY_EFFECT_CALLBACK :
|
||||
// destroyAudioPlayer(callback->player);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
void setSingleEffectState(AudioPlayer * player, int state)
|
||||
{
|
||||
SLresult result;
|
||||
if (player->fdPlayerPlay != NULL){
|
||||
result = (*(player->fdPlayerPlay))->SetPlayState(player->fdPlayerPlay, state);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
}
|
||||
}
|
||||
|
||||
int getEffectState(AudioPlayer * player)
|
||||
{
|
||||
SLuint32 state = 0;
|
||||
SLresult result;
|
||||
result = (*(player->fdPlayerPlay))->GetPlayState(player->fdPlayerPlay, &state);
|
||||
assert(result == SL_RESULT_SUCCESS);
|
||||
|
||||
return (int)state;
|
||||
}
|
||||
|
||||
void resumeSingleEffect(AudioPlayer * player)
|
||||
{
|
||||
int state = getEffectState(player);
|
||||
// only resume the effect that has been paused
|
||||
if (state == PLAYSTATE_PAUSED)
|
||||
{
|
||||
setSingleEffectState(player, PLAYSTATE_PLAYING);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int OpenSLEngine::preloadEffect(const char * filename)
|
||||
{
|
||||
unsigned int nID = _Hash(filename);
|
||||
// if already exists
|
||||
if (sharedList().find(nID) != sharedList().end())
|
||||
{
|
||||
/*AudioPlayer* newPlayer = new AudioPlayer(sharedList()[nID]);
|
||||
CallbackContext* context = new CallbackContext();
|
||||
context->player = newPlayer;
|
||||
context->
|
||||
(newPlayer->fdPlayerPlay)->RegisterCallback(newPlayer->fdPlayerPlay, effectPlayCallback, );*/
|
||||
return nID;
|
||||
}
|
||||
|
||||
AudioPlayer* player = new AudioPlayer();
|
||||
if (!initAudioPlayer(player, filename))
|
||||
{
|
||||
free(player);
|
||||
return FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
// set the new player's volume as others'
|
||||
SLresult result;
|
||||
result = (*(player->fdPlayerVolume))->SetVolumeLevel(player->fdPlayerVolume, m_effectVolume);
|
||||
assert(result == SL_RESULT_SUCCESS);
|
||||
|
||||
sharedList().insert(Effect(nID, player));
|
||||
return nID;
|
||||
}
|
||||
|
||||
void OpenSLEngine::unloadEffect(const char * filename)
|
||||
{
|
||||
unsigned int nID = _Hash(filename);
|
||||
|
||||
EffectList::iterator p = sharedList().find(nID);
|
||||
if (p != sharedList().end())
|
||||
{
|
||||
destroyAudioPlayer(p->second);
|
||||
sharedList().erase(nID);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSLEngine::setEffectState(unsigned int effectID, int state)
|
||||
{
|
||||
EffectList::iterator p = sharedList().find(effectID);
|
||||
if (p != sharedList().end())
|
||||
{
|
||||
setSingleEffectState(p->second, state);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSLEngine::setAllEffectState(int state)
|
||||
{
|
||||
EffectList::iterator iter;
|
||||
for (iter = sharedList().begin(); iter != sharedList().end(); iter++)
|
||||
{
|
||||
setSingleEffectState(iter->second, state);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSLEngine::resumeEffect(unsigned int effectID)
|
||||
{
|
||||
EffectList::iterator p = sharedList().find(effectID);
|
||||
if (p == sharedList().end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
resumeSingleEffect(p->second);
|
||||
}
|
||||
|
||||
void OpenSLEngine::resumeAllEffects()
|
||||
{
|
||||
int state;
|
||||
EffectList::iterator iter;
|
||||
for (iter = sharedList().begin(); iter != sharedList().end() ; ++ iter)
|
||||
{
|
||||
resumeSingleEffect(iter->second);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSLEngine::setEffectLooping(unsigned int effectID, bool isLooping)
|
||||
{
|
||||
SLresult result;
|
||||
AudioPlayer * player = sharedList()[effectID];
|
||||
assert(player != NULL);
|
||||
|
||||
if (NULL != player->fdPlayerSeek)
|
||||
{
|
||||
result = (*(player->fdPlayerSeek))->SetLoop(player->fdPlayerSeek, (SLboolean) isLooping, 0, SL_TIME_UNKNOWN);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSLEngine::setEffectsVolume(int volume)
|
||||
{
|
||||
m_effectVolume = volume;
|
||||
|
||||
SLresult result;
|
||||
EffectList::iterator iter;
|
||||
AudioPlayer * player;
|
||||
for (iter = sharedList().begin() ; iter != sharedList().end() ; ++ iter)
|
||||
{
|
||||
player = iter->second;
|
||||
result = (*(player->fdPlayerVolume))->SetVolumeLevel(player->fdPlayerVolume, m_effectVolume);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
}
|
||||
}
|
||||
|
||||
int OpenSLEngine::getEffectsVolume()
|
||||
{
|
||||
return m_effectVolume;
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
#ifndef _OPENSL_ENGINE_H_
|
||||
#define _OPENSL_ENGINE_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <jni.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <map>
|
||||
#include <SLES/OpenSLES.h>
|
||||
#include <SLES/OpenSLES_Android.h>
|
||||
#include <sys/types.h>
|
||||
#include <android/asset_manager.h>
|
||||
#include <android/asset_manager_jni.h>
|
||||
#include <android/log.h>
|
||||
#include <jni/JniHelper.h>
|
||||
|
||||
|
||||
class OpenSLEngine
|
||||
{
|
||||
public:
|
||||
OpenSLEngine();
|
||||
~OpenSLEngine();
|
||||
|
||||
void createEngine();
|
||||
|
||||
void closeEngine();
|
||||
|
||||
|
||||
bool preloadBackgroundMusic(const char * filename);
|
||||
|
||||
void setBackgroundMusicState(int state);
|
||||
|
||||
int getBackgroundMusicState();
|
||||
|
||||
void rewindBackgroundMusic();
|
||||
|
||||
void setBackgroundMusicLooping(bool isLooping);
|
||||
|
||||
void setBackgroundVolume(int volume);
|
||||
|
||||
int getBackgroundVolume();
|
||||
|
||||
|
||||
unsigned int preloadEffect(const char * filename);
|
||||
|
||||
void unloadEffect(const char * filename);
|
||||
|
||||
void setEffectState(unsigned int effectID, int state);
|
||||
|
||||
void setAllEffectState(int state);
|
||||
|
||||
void resumeEffect(unsigned int effectID);
|
||||
|
||||
void resumeAllEffects();
|
||||
|
||||
void setEffectLooping(unsigned int effectID, bool isLooping);
|
||||
|
||||
void setEffectsVolume(int volume);
|
||||
|
||||
int getEffectsVolume();
|
||||
|
||||
private:
|
||||
SLmillibel m_musicVolume;
|
||||
SLmillibel m_effectVolume;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,122 @@
|
|||
#include "SimpleAudioEngineOpenSL.h"
|
||||
|
||||
#define PLAYSTATE_STOPPED 1
|
||||
#define PLAYSTATE_PAUSED 2
|
||||
#define PLAYSTATE_PLAYING 3
|
||||
#define FILE_NOT_FOUND -1
|
||||
|
||||
static OpenSLEngine * s_pOpenSL = 0;
|
||||
static SimpleAudioEngineOpenSL * s_pEngine = 0;
|
||||
|
||||
SimpleAudioEngineOpenSL::SimpleAudioEngineOpenSL()
|
||||
{
|
||||
}
|
||||
|
||||
SimpleAudioEngineOpenSL::~SimpleAudioEngineOpenSL()
|
||||
{
|
||||
if (s_pOpenSL)
|
||||
{
|
||||
s_pOpenSL->closeEngine();
|
||||
|
||||
delete s_pOpenSL;
|
||||
s_pOpenSL = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool SimpleAudioEngineOpenSL::initEngine()
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
s_pOpenSL = new OpenSLEngine();
|
||||
s_pOpenSL->createEngine();
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
return bRet;
|
||||
}
|
||||
|
||||
SimpleAudioEngineOpenSL* SimpleAudioEngineOpenSL::sharedEngine()
|
||||
{
|
||||
if (! s_pEngine)
|
||||
{
|
||||
s_pEngine = new SimpleAudioEngineOpenSL();
|
||||
s_pEngine->initEngine();
|
||||
}
|
||||
return s_pEngine;
|
||||
}
|
||||
|
||||
void SimpleAudioEngineOpenSL::end()
|
||||
{
|
||||
if (s_pOpenSL)
|
||||
{
|
||||
s_pOpenSL->closeEngine();
|
||||
}
|
||||
}
|
||||
|
||||
float SimpleAudioEngineOpenSL::getEffectsVolume()
|
||||
{
|
||||
// TODO
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
void SimpleAudioEngineOpenSL::setEffectsVolume(float volume)
|
||||
{
|
||||
int attenuation = (1 - volume) * 100;
|
||||
int millibel = attenuation * -15;
|
||||
s_pOpenSL->setEffectsVolume(millibel);
|
||||
}
|
||||
|
||||
unsigned int SimpleAudioEngineOpenSL::playEffect(const char* pszFilePath, bool bLoop)
|
||||
{
|
||||
unsigned int soundID = s_pOpenSL->preloadEffect(pszFilePath);
|
||||
if (soundID != FILE_NOT_FOUND)
|
||||
{
|
||||
s_pOpenSL->setEffectState(soundID, PLAYSTATE_STOPPED);
|
||||
s_pOpenSL->setEffectLooping(soundID, bLoop);
|
||||
s_pOpenSL->setEffectState(soundID, PLAYSTATE_PLAYING);
|
||||
}
|
||||
|
||||
return soundID;
|
||||
}
|
||||
|
||||
void SimpleAudioEngineOpenSL::pauseEffect(unsigned int nSoundId)
|
||||
{
|
||||
s_pOpenSL->setEffectState(nSoundId, PLAYSTATE_PAUSED);
|
||||
}
|
||||
|
||||
void SimpleAudioEngineOpenSL::pauseAllEffects()
|
||||
{
|
||||
s_pOpenSL->setAllEffectState(PLAYSTATE_PAUSED);
|
||||
}
|
||||
|
||||
void SimpleAudioEngineOpenSL::resumeEffect(unsigned int nSoundId)
|
||||
{
|
||||
s_pOpenSL->resumeEffect(nSoundId);
|
||||
}
|
||||
|
||||
void SimpleAudioEngineOpenSL::resumeAllEffects()
|
||||
{
|
||||
s_pOpenSL->resumeAllEffects();
|
||||
}
|
||||
|
||||
void SimpleAudioEngineOpenSL::stopEffect(unsigned int nSoundId)
|
||||
{
|
||||
s_pOpenSL->setEffectState(nSoundId, PLAYSTATE_STOPPED);
|
||||
}
|
||||
|
||||
void SimpleAudioEngineOpenSL::stopAllEffects()
|
||||
{
|
||||
s_pOpenSL->setAllEffectState(PLAYSTATE_STOPPED);
|
||||
}
|
||||
|
||||
void SimpleAudioEngineOpenSL::preloadEffect(const char* pszFilePath)
|
||||
{
|
||||
s_pOpenSL->preloadEffect(pszFilePath);
|
||||
}
|
||||
|
||||
void SimpleAudioEngineOpenSL::unloadEffect(const char* pszFilePath)
|
||||
{
|
||||
s_pOpenSL->unloadEffect(pszFilePath);
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef _SIMPLE_AUDIO_ENGINE_OPENSL_H_
|
||||
#define _SIMPLE_AUDIO_ENGINE_OPENSL_H_
|
||||
|
||||
#include "OpenSLEngine.h"
|
||||
|
||||
class SimpleAudioEngineOpenSL
|
||||
{
|
||||
public:
|
||||
SimpleAudioEngineOpenSL();
|
||||
~SimpleAudioEngineOpenSL();
|
||||
|
||||
bool initEngine();
|
||||
|
||||
static SimpleAudioEngineOpenSL* sharedEngine();
|
||||
|
||||
static void end();
|
||||
|
||||
float getEffectsVolume();
|
||||
|
||||
void setEffectsVolume(float volume);
|
||||
|
||||
unsigned int playEffect(const char* pszFilePath, bool bLoop = false);
|
||||
|
||||
void pauseEffect(unsigned int nSoundId);
|
||||
|
||||
void pauseAllEffects();
|
||||
|
||||
void resumeEffect(unsigned int nSoundId);
|
||||
|
||||
void resumeAllEffects();
|
||||
|
||||
void stopEffect(unsigned int nSoundId);
|
||||
|
||||
void stopAllEffects();
|
||||
|
||||
void preloadEffect(const char* pszFilePath);
|
||||
|
||||
void unloadEffect(const char* pszFilePath);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -500,7 +500,7 @@ bool CCLayerColor::initWithColor(const ccColor4B& color)
|
|||
}
|
||||
|
||||
/// override contentSize
|
||||
void CCLayerColor::setContentSize(CCSize size)
|
||||
void CCLayerColor::setContentSize(CCSize & size)
|
||||
{
|
||||
m_pSquareVertices[1].x = size.width;
|
||||
m_pSquareVertices[2].y = size.height;
|
||||
|
|
|
@ -225,7 +225,7 @@ public:
|
|||
virtual ~CCLayerColor();
|
||||
|
||||
virtual void draw();
|
||||
virtual void setContentSize(CCSize var);
|
||||
virtual void setContentSize(CCSize & var);
|
||||
|
||||
/** creates a CCLayer with color, width and height in Points
|
||||
@deprecated: This interface will be deprecated sooner or later.
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.content.DialogInterface;
|
|||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
@ -41,6 +42,7 @@ public class Cocos2dxActivity extends Activity{
|
|||
private static Cocos2dxMusic backgroundMusicPlayer;
|
||||
private static Cocos2dxSound soundPlayer;
|
||||
private static Cocos2dxAccelerometer accelerometer;
|
||||
private static AssetManager assetManager;
|
||||
private static boolean accelerometerEnabled = false;
|
||||
private static Handler handler;
|
||||
private final static int HANDLER_SHOW_DIALOG = 1;
|
||||
|
@ -61,6 +63,9 @@ public class Cocos2dxActivity extends Activity{
|
|||
backgroundMusicPlayer = new Cocos2dxMusic(this);
|
||||
soundPlayer = new Cocos2dxSound(this);
|
||||
|
||||
// init asset manager for jni call
|
||||
assetManager = getAssets();
|
||||
|
||||
// init bitmap context
|
||||
Cocos2dxBitmap.setContext(this);
|
||||
|
||||
|
@ -75,6 +80,11 @@ public class Cocos2dxActivity extends Activity{
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
public static AssetManager getAssetManager() {
|
||||
return assetManager;
|
||||
}
|
||||
|
||||
public static String getCurrentLanguage() {
|
||||
String languageName = java.util.Locale.getDefault().getLanguage();
|
||||
return languageName;
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
::This script is used to finish a android automated compiler.
|
||||
::You should make sure have finished the environment setting.
|
||||
::Here are the environment variables you should set.
|
||||
::%ANT_HOME% %ANDROID_HOME% %JAVA_HOME% %CYGWIN% %GITBIN% %ANDROID_NDK%
|
||||
:: Don't change it until you know what you do.
|
||||
|
||||
::In order to prevent the problem of permission,make the current user group get the ownership of project.
|
||||
::Set the current user name.
|
||||
::set _USERNAME=
|
||||
|
||||
set _PROJECTNAME=TestCpp
|
||||
cd ..\..
|
||||
|
||||
:project
|
||||
::Copy build Configuration files to target directory
|
||||
copy %cd%\tools\JenkinsScript\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
copy %cd%\tools\JenkinsScript\build.xml %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
copy %cd%\tools\JenkinsScript\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
|
||||
::Modify the configuration files
|
||||
cd samples\%_PROJECTNAME%\proj.android
|
||||
rootconfig.sh %_PROJECTNAME%
|
||||
cd ..
|
||||
set _PROJECTLOCATION=%cd%
|
||||
|
||||
::A command line that make the current user get the ownrship of project.
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
|
||||
::Use cygwin compile the source code.
|
||||
cygpath "%_PROJECTLOCATION%\proj.android\build_native.sh"|call %CYGWIN%\Cygwin.bat
|
||||
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
::echo "%_PROJECTION%/proj.android/build_native.sh"|call %CYGWIN%\Cygwin.bat
|
||||
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
call android update project -p proj.android
|
||||
cd proj.android
|
||||
|
||||
::Make sure the original android build target is android-8
|
||||
for /f "delims=" %%a in ('findstr /i "target=android-" ant.properties') do set xx=%%a
|
||||
echo %xx%
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="%xx%" (echo/target=android-8)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
::Android ant build(debug,API level:8).
|
||||
call ant debug
|
||||
set result8=%ERROELEVEL%
|
||||
|
||||
::Change API level.(API level:10)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-8" (echo/target=android-10)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
::Android ant build(debug,API level:10).
|
||||
call ant debug
|
||||
set result10=%ERRORLEVEL%
|
||||
|
||||
::Change API level.(API level:11)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-10" (echo/target=android-11)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
::Android ant build(debug,API level:11).
|
||||
call ant debug
|
||||
set result11=%ERRORlEVEL%
|
||||
|
||||
::Change API level.(API level:12)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-11" (echo/target=android-12)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
::Android ant build(debug,API level:12).
|
||||
call ant debug
|
||||
set result12=%ERRORLEVEL%
|
||||
|
||||
::Change API level.(API level:13)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-12" (echo/target=android-13)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
::Android ant build(debug,API level:13).
|
||||
call ant debug
|
||||
set result13=%ERRORLEVEL%
|
||||
|
||||
::After all test versions completed,changed current API level to the original.(API level:8)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-13" (echo/target=android-8)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
::Calculate the errorlevel and change build target.
|
||||
cd ..\..\..
|
||||
IF "%_PROJECTNAME%"=="TestCpp" set /a testresult1=(result8+result10+result11+result12+result13) && set _PROJECTNAME=HelloCpp&& goto project
|
||||
IF "%_PROJECTNAME%"=="HelloCpp" set /a testresult2=(result8+result10+result11+result12+result13) && set _PROJECTNAME=HelloLua&& goto project
|
||||
IF "%_PROJECTNAME%"=="HelloLua" set /a testresult3=(result8+result10+result11+result12+result13)
|
||||
set /a testresult=(testresult1+result2+result3)
|
||||
IF %testresult% NEQ 0 goto error
|
||||
|
||||
goto success
|
||||
|
||||
:error
|
||||
echo Error.
|
||||
git checkout -f|%GITBIN%\sh.exe --login
|
||||
git clean -df -x|%GITBIN%\sh.exe --login
|
||||
pause
|
||||
exit 1
|
||||
goto end
|
||||
|
||||
:success
|
||||
echo Success.
|
||||
git checkout -f|%GITBIN%\sh.exe --login
|
||||
git clean -df|%GITBIN%\sh.exe --login
|
||||
pause
|
||||
exit 0
|
||||
goto end
|
||||
|
||||
::End.
|
|
@ -0,0 +1,98 @@
|
|||
::This script is used to finish a android automated compiler.
|
||||
::You should make sure have finished the environment setting.
|
||||
::Here are the environment variables you should set.
|
||||
::%ANT_HOME% %ANDROID_HOME% %JAVA_HOME% %CYGWIN% %GITBIN% %ANDROID_NDK%
|
||||
:: Don't change it until you know what you do.
|
||||
|
||||
::In order to prevent the problem of permission,make the current user group get the ownership of project.
|
||||
::Set the current user name.
|
||||
::set _USERNAME=
|
||||
|
||||
set _PROJECTNAME=TestCpp
|
||||
cd ..\..
|
||||
|
||||
:project
|
||||
::Copy build Configuration files to target directory
|
||||
copy %cd%\tools\JenkinsScript\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
copy %cd%\tools\JenkinsScript\build.xml %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
copy %cd%\tools\JenkinsScript\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
|
||||
::Modify the configuration files
|
||||
cd samples\%_PROJECTNAME%\proj.android
|
||||
rootconfig.sh %_PROJECTNAME%
|
||||
cd ..
|
||||
set _PROJECTLOCATION=%cd%
|
||||
|
||||
::A command line that make the current user get the ownrship of project.
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
|
||||
::Use cygwin compile the source code.
|
||||
cygpath "%_PROJECTLOCATION%\proj.android\build_native.sh"|call %CYGWIN%\Cygwin.bat
|
||||
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
::echo "%_PROJECTION%/proj.android/build_native.sh"|call %CYGWIN%\Cygwin.bat
|
||||
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
call android update project -p proj.android
|
||||
cd proj.android
|
||||
|
||||
for /f "delims=" %%a in ('findstr /i "target=android-" ant.properties') do set xx=%%a
|
||||
echo %xx%
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="%xx%" (echo/target=android-8)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
::Change API level.(API level:14)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-8" (echo/target=android-14)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
::Android ant build(debug,API level:14).
|
||||
call ant debug
|
||||
set result14=%ERRORLEVEL%
|
||||
|
||||
::Change API level.(API level:15)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-14" (echo/target=android-15)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
::Android ant build(debug,API level:15).
|
||||
call ant debug
|
||||
set result15=%ERRORLEVEL%
|
||||
|
||||
::After all test versions completed,changed current API level to the original.(API level:8)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-15" (echo/target=android-8)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
::Calculate the errorlevel and change build target.
|
||||
cd ../../..
|
||||
IF "%_PROJECTNAME%"=="TestCpp" set /a testresult1=(result8+result10+result11+result12+result13) && set _PROJECTNAME=HelloCpp&& goto project
|
||||
IF "%_PROJECTNAME%"=="HelloCpp" set /a testresult2=(result8+result10+result11+result12+result13) && set _PROJECTNAME=HelloLua&& goto project
|
||||
IF "%_PROJECTNAME%"=="HelloLua" set /a testresult3=(result8+result10+result11+result12+result13)
|
||||
set /a testresult=(testresult1+result2+result3)
|
||||
IF %testresult% NEQ 0 goto error
|
||||
|
||||
goto success
|
||||
|
||||
:error
|
||||
echo Error.
|
||||
git checkout -f|%GITBIN%\sh.exe --login
|
||||
git clean -df -x|%GITBIN%\sh.exe --login
|
||||
pause
|
||||
exit 1
|
||||
goto end
|
||||
|
||||
:success
|
||||
echo Success.
|
||||
git checkout -f|%GITBIN%\sh.exe --login
|
||||
git clean -df|%GITBIN%\sh.exe --login
|
||||
pause
|
||||
exit 0
|
||||
goto end
|
||||
|
||||
::End.
|
|
@ -0,0 +1,147 @@
|
|||
::This script is used to finish a android automated compiler.
|
||||
::You should make sure have finished the environment setting.
|
||||
::Here are the environment variables you should set.
|
||||
::%ANT_HOME% %ANDROID_HOME% %JAVA_HOME% %CYGWIN% %GITBIN% %ANDROID_NDK%
|
||||
:: Don't change it until you know what you do.
|
||||
|
||||
::In order to prevent the problem of permission,make the current user group get the ownership of project.
|
||||
::Set the current user name.
|
||||
::set _USERNAME=
|
||||
|
||||
set _PROJECTNAME=TestCpp
|
||||
cd ..\..
|
||||
|
||||
:project
|
||||
::Copy build Configuration files to target directory
|
||||
copy %cd%\tools\JenkinsScript\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
copy %cd%\tools\JenkinsScript\build.xml %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
copy %cd%\tools\JenkinsScript\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
|
||||
::Modify the configuration files
|
||||
cd samples\%_PROJECTNAME%\proj.android
|
||||
rootconfig.sh %_PROJECTNAME%
|
||||
cd ..
|
||||
set _PROJECTLOCATION=%cd%
|
||||
|
||||
::A command line that make the current user get the ownrship of project.
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
|
||||
::Use cygwin compile the source code.
|
||||
cygpath "%_PROJECTLOCATION%\proj.android\build_native.sh"|call %CYGWIN%\Cygwin.bat
|
||||
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
::echo "%_PROJECTION%/proj.android/build_native.sh"|call %CYGWIN%\Cygwin.bat
|
||||
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
call android update project -p proj.android
|
||||
cd proj.android
|
||||
|
||||
::Make sure the original android build target is android-8
|
||||
for /f "delims=" %%a in ('findstr /i "target=android-" ant.properties') do set xx=%%a
|
||||
echo %xx%
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="%xx%" (echo/target=android-8)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
for /f "delims=" %%a in (ant.properties) do set num=%%a&call :lis
|
||||
move ant1.properties ant.properties
|
||||
|
||||
::Android ant build(release,API level:8).
|
||||
call ant release
|
||||
set result8=%ERRORLEVEL%
|
||||
|
||||
::Change API level.(API level:10)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-8" (echo/target=android-10)else echo/%%a
|
||||
)>>"ant1.properties"
|
||||
move ant1.properties ant.properties
|
||||
|
||||
for /f "delims=" %%a in (ant.properties) do set num=%%a&call :lis
|
||||
move ant1.properties ant.properties
|
||||
|
||||
::Android ant build(release,API level:10).
|
||||
call ant release
|
||||
set result10=%ERRORLEVEL%
|
||||
|
||||
::Change API level.(API level:11)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-10" (echo/target=android-11)else echo/%%a
|
||||
)>>"ant1.properties"
|
||||
move ant1.properties ant.properties
|
||||
|
||||
for /f "delims=" %%a in (ant.properties) do set num=%%a&call :lis
|
||||
move ant1.properties ant.properties
|
||||
|
||||
::Android ant build(release,API level:11).
|
||||
call ant release
|
||||
set result11=%ERRORLEVEL%
|
||||
|
||||
::Change API level.(API level:12)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-11" (echo/target=android-12)else echo/%%a
|
||||
)>>"ant1.properties"
|
||||
move ant1.properties ant.properties
|
||||
|
||||
for /f "delims=" %%a in (ant.properties) do set num=%%a&call :lis
|
||||
move ant1.properties ant.properties
|
||||
|
||||
::Android ant build(release,API level:12).
|
||||
call ant release
|
||||
set result12=%ERRORLEVEL%
|
||||
|
||||
::Change API level.(API level:13)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-12" (echo/target=android-13)else echo/%%a
|
||||
)>>"ant1.properties"
|
||||
move ant1.properties ant.properties
|
||||
|
||||
for /f "delims=" %%a in (ant.properties) do set num=%%a&call :lis
|
||||
move ant1.properties ant.properties
|
||||
|
||||
::Android ant build(release,API level:13).
|
||||
call ant release
|
||||
set result13=%ERRORLEVEL%
|
||||
|
||||
::After all test versions completed,changed current API level to the original.(API level:8)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-13" (echo/target=android-8)else echo/%%a
|
||||
)>>"ant1.properties"
|
||||
move ant1.properties ant.properties
|
||||
|
||||
for /f "delims=" %%a in (ant.properties) do set num=%%a&call :lis
|
||||
move ant1.properties ant.properties
|
||||
|
||||
::Calculate the errorlevel and change build target.
|
||||
cd ..\..\..
|
||||
IF "%_PROJECTNAME%"=="TestCpp" set /a testresult1=(result8+result10+result11+result12+result13) && set _PROJECTNAME=HelloCpp&& goto project
|
||||
IF "%_PROJECTNAME%"=="HelloCpp" set /a testresult2=(result8+result10+result11+result12+result13) && set _PROJECTNAME=HelloLua&& goto project
|
||||
IF "%_PROJECTNAME%"=="HelloLua" set /a testresult3=(result8+result10+result11+result12+result13)
|
||||
set /a testresult=(testresult1+result2+result3)
|
||||
IF %testresult% NEQ 0 goto error
|
||||
|
||||
goto success
|
||||
|
||||
:lis
|
||||
if "%num%"=="" goto :eof
|
||||
if "%num:~-1%"==" " set num=%num:~0,-1%&goto lis
|
||||
echo %num%>>ant1.properties
|
||||
goto :eof
|
||||
|
||||
:error
|
||||
echo Error.
|
||||
git checkout -f|%GITBIN%\sh.exe --login
|
||||
git clean -df|%GITBIN%\sh.exe --login
|
||||
pause
|
||||
exit 1
|
||||
goto end
|
||||
|
||||
:success
|
||||
echo Success.
|
||||
git checkout -f|%GITBIN%\sh.exe --login
|
||||
git clean -df|%GITBIN%\sh.exe --login
|
||||
pause
|
||||
exit 0
|
||||
goto end
|
||||
|
||||
::End.
|
|
@ -0,0 +1,109 @@
|
|||
::This script is used to finish a android automated compiler.
|
||||
::You should make sure have finished the environment setting.
|
||||
::Here are the environment variables you should set.
|
||||
::%ANT_HOME% %ANDROID_HOME% %JAVA_HOME% %CYGWIN% %GITBIN% %ANDROID_NDK%
|
||||
:: Don't change it until you know what you do.
|
||||
|
||||
::In order to prevent the problem of permission,make the current user group get the ownership of project.
|
||||
::Set the current user name.
|
||||
::set _USERNAME=
|
||||
|
||||
set _PROJECTNAME=TestCpp
|
||||
cd ..\..
|
||||
|
||||
:project
|
||||
copy %cd%\tools\JenkinsScript\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
copy %cd%\tools\JenkinsScript\build.xml %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
copy %cd%\tools\JenkinsScript\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android
|
||||
cd samples\%_PROJECTNAME%\proj.android
|
||||
rootconfig.sh %_PROJECTNAME%
|
||||
cd ..
|
||||
set _PROJECTLOCATION=%cd%
|
||||
|
||||
::A command line that make the current user get the ownrship of project.
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
|
||||
::Use cygwin compile the source code.
|
||||
cygpath "%_PROJECTLOCATION%\proj.android\build_native.sh"|call %CYGWIN%\Cygwin.bat
|
||||
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
::echo "%_PROJECTION%/proj.android/build_native.sh"|call %CYGWIN%\Cygwin.bat
|
||||
|
||||
::cacls proj.android\*.* /T /E /C /P %_USERNAME%:F
|
||||
call android update project -p proj.android
|
||||
cd proj.android
|
||||
|
||||
for /f "delims=" %%a in ('findstr /i "target=android-" ant.properties') do set xx=%%a
|
||||
echo %xx%
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="%xx%" (echo/target=android-8)else echo/%%a
|
||||
)>>"anttmp.properties"
|
||||
move anttmp.properties ant.properties
|
||||
|
||||
::Change API level.(API level:14)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-8" (echo/target=android-14)else echo/%%a
|
||||
)>>"ant1.properties"
|
||||
move ant1.properties ant.properties
|
||||
|
||||
for /f "delims=" %%a in (ant.properties) do set num=%%a&call :lis
|
||||
move ant1.properties ant.properties
|
||||
|
||||
::Android ant build(release,API level:14).
|
||||
call ant release
|
||||
set result14=%ERRORLEVEL%
|
||||
|
||||
::Change API level.(API level:15)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-14" (echo/target=android-15)else echo/%%a
|
||||
)>>"ant1.properties"
|
||||
move ant1.properties ant.properties
|
||||
|
||||
for /f "delims=" %%a in (ant.properties) do set num=%%a&call :lis
|
||||
move ant1.properties ant.properties
|
||||
|
||||
::Android ant build(release,API level:15).
|
||||
call ant release
|
||||
set result15=%ERRORLEVEL%
|
||||
|
||||
::After all test versions completed,changed current API level to the original.(API level:8)
|
||||
for /f "delims=" %%a in (ant.properties) do (
|
||||
if "%%a"=="target=android-15" (echo/target=android-8)else echo/%%a
|
||||
)>>"ant1.properties"
|
||||
move ant1.properties ant.properties
|
||||
|
||||
for /f "delims=" %%a in (ant.properties) do set num=%%a&call :lis
|
||||
move ant1.properties ant.properties
|
||||
|
||||
cd ..\..\..
|
||||
IF "%_PROJECTNAME%"=="TestCpp" set /a testresult1=(result14+result15) && set _PROJECTNAME=HelloCpp&& goto project
|
||||
IF "%_PROJECTNAME%"=="HelloCpp" set /a testresult2=(result14+result15) && set _PROJECTNAME=HelloLua&& goto project
|
||||
IF "%_PROJECTNAME%"=="HelloLua" set /a testresult3=(result14+result15)
|
||||
set /a testresult=(testresult1+result2+result3)
|
||||
IF %testresult% NEQ 0 goto error
|
||||
|
||||
goto success
|
||||
|
||||
:lis
|
||||
if "%num%"=="" goto :eof
|
||||
if "%num:~-1%"==" " set num=%num:~0,-1%&goto lis
|
||||
echo %num%>>ant1.properties
|
||||
goto :eof
|
||||
|
||||
:error
|
||||
echo Error.
|
||||
git checkout -f|%GITBIN%\sh.exe --login
|
||||
git clean -df|%GITBIN%\sh.exe --login
|
||||
pause
|
||||
exit 1
|
||||
goto end
|
||||
|
||||
:success
|
||||
echo Success.
|
||||
git checkout -f|%GITBIN%\sh.exe --login
|
||||
git clean -df|%GITBIN%\sh.exe --login
|
||||
pause
|
||||
exit 0
|
||||
goto end
|
||||
|
||||
::End.
|
|
@ -0,0 +1,89 @@
|
|||
echo off
|
||||
rem =========Basic parameters============
|
||||
rem jdk path
|
||||
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_31
|
||||
rem jdk version
|
||||
set JDK_Version=1.6
|
||||
rem sdk path
|
||||
set AndroidHome=D:\Windows7\android-sdk-windows
|
||||
rem android version path
|
||||
set AndroidVersion=\platforms\android-8
|
||||
rem android project path
|
||||
set AndroidProject=D:\cocos2d-x\tests\proj.android
|
||||
rem unsigned apk name
|
||||
set unsign_apk=Tests.apk
|
||||
rem signed apk name
|
||||
set sign_apk=Tests-sign.apk
|
||||
rem sign keystore
|
||||
set apk_key=cdykeystore
|
||||
set apk_keypass=123456
|
||||
set apk_keystore=D:\cdykeystore
|
||||
|
||||
for %%x in ("%AndroidProject%") do set AndroidProject=%%~sx
|
||||
for %%x in ("%JAVA_HOME%") do set JAVA_HOME=%%~sx
|
||||
for %%x in ("%AndroidHome%") do set AndroidHome=%%~sx
|
||||
|
||||
rem jdk kit
|
||||
set EXE_JAVA=%JAVA_HOME%\bin\java
|
||||
set JAVAC=%JAVA_HOME%\bin\javac
|
||||
set JAR=%JAVA_HOME%\bin\jar
|
||||
set KeyTool=%JAVA_HOME%\bin\keytool
|
||||
set Jarsigner=%JAVA_HOME%\bin\jarsigner
|
||||
|
||||
rem sdk kit
|
||||
set AndroidAAPT=%AndroidHome%\platform-tools\aapt.exe
|
||||
set AndroidDx=%AndroidHome%\platform-tools\dx.bat
|
||||
set AndroidApkBuilder=%AndroidHome%\tools\apkbuilder.bat
|
||||
set AndroidJar=%AndroidHome%%AndroidVersion%\android.jar
|
||||
|
||||
rem android project directory
|
||||
set AndroidProjectDrive=D:
|
||||
set AndroidProjectRes=%AndroidProject%\res
|
||||
set AndroidProjectGen=%AndroidProject%\gen
|
||||
set AndroidProjectBin=%AndroidProject%\bin
|
||||
set AndroidProjectAsset=%AndroidProject%\assets
|
||||
set AndroidProjectLibs=%AndroidProject%\libs
|
||||
set AndroidProjectAndroidMainfest=%AndroidProject%\AndroidManifest.xml
|
||||
set AndroidProjectSrc=%AndroidProject%\src\org\cocos2dx\tests\*.java
|
||||
set AndroidProjectSrc=%AndroidProjectSrc% %AndroidProject%\src\org\cocos2dx\lib\*.java
|
||||
set AndroidProjectSrc=%AndroidProjectSrc% %AndroidProject%\gen\org\cocos2dx\tests\*.java
|
||||
|
||||
rem output file
|
||||
set AndroidProjectClassDex=%AndroidProject%\bin\classes.dex
|
||||
set AndroidProjectResources=%AndroidProject%\bin\resources.ap_
|
||||
set AndroidProjectApk="%AndroidProject%\bin\%unsign_apk%"
|
||||
set AndroidProjectSignApk="%AndroidProject%\bin\%sign_apk%"
|
||||
|
||||
mkdir %AndroidProject%\gen
|
||||
mkdir %AndroidProject%\src\org\cocos2dx\lib
|
||||
mkdir %AndroidProject%\bin
|
||||
::mkdir %AndroidProject%\bin\classes
|
||||
xcopy D:\cocos2d-x\cocos2dx\platform\android\java\src_common\org\cocos2dx\lib %AndroidProject%\src\org\cocos2dx\lib /s
|
||||
|
||||
echo generate R.java file
|
||||
%AndroidAAPT% package -f -m -J %AndroidProjectGen% -S %AndroidProjectRes% -I %AndroidJar% -M %AndroidProjectAndroidMainfest%
|
||||
|
||||
echo generate class file
|
||||
%JAVAC% -encoding UTF-8 -target %JDK_Version% -bootclasspath %AndroidJar% -d %AndroidProjectBin% %AndroidProjectSrc% %AndroidProjectGen%\org\cocos2dx\tests\R.java
|
||||
|
||||
echo generate dex file
|
||||
echo on
|
||||
%AndroidProjectDrive%
|
||||
cd %AndroidProjectBin%
|
||||
rem packaging the *.class file into *.jar file
|
||||
%JAR% cvf %AndroidProjectBin%\classes.jar *.*
|
||||
cd %AndroidProject%
|
||||
rem generate *.dex file
|
||||
call %AndroidDx% --dex --output=%AndroidProjectClassDex% %AndroidProjectBin%\classes.jar
|
||||
|
||||
echo package resources files
|
||||
%AndroidAAPT% package -f -M %AndroidProjectAndroidMainfest% -S %AndroidProjectRes% -A %AndroidProjectAsset% -I %AndroidJar% -F %AndroidProjectResources%
|
||||
|
||||
echo generate unsigned apk file
|
||||
call %AndroidApkBuilder% %AndroidProjectApk% -v -u -z %AndroidProjectResources% -f %AndroidProjectClassDex% -rf %AndroidProject%\src -nf %AndroidProjectLibs% -rj %AndroidProjectLibs%
|
||||
|
||||
echo generate signed apk file
|
||||
%Jarsigner% -verbose -keystore %apk_keystore% -keypass %apk_keypass% -storepass %apk_keypass% -signedjar %AndroidProjectSignApk% %AndroidProjectApk% cdykeystore
|
||||
|
||||
echo sign success!
|
||||
pause
|
|
@ -0,0 +1,20 @@
|
|||
# This file is used to override default values used by the Ant build system.
|
||||
#
|
||||
# This file must be checked in Version Control Systems, as it is
|
||||
# integral to the build system of your project.
|
||||
# This file is only used by the Ant script.
|
||||
# You can use this to override default values such as
|
||||
# 'source.dir' for the location of your java source folder and
|
||||
# 'out.dir' for the location of your output folder.
|
||||
# You can also use it define how the release builds are signed by declaring
|
||||
# the following properties:
|
||||
# 'key.store' for the location of your keystore and
|
||||
# 'key.alias' for the name of the key to use.
|
||||
# The password will be asked during the build when you use the 'release' target.
|
||||
key.store=C:/.android/debug.keystore
|
||||
key.alias=androiddebugkey
|
||||
key.store.password=android
|
||||
key.alias.password=android
|
||||
#proguard.config=proguard.cfg
|
||||
# Project target.
|
||||
target=android-8
|
|
@ -0,0 +1,95 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="Tests" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<loadproperties srcFile="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
|
||||
<!-- extension targets. Uncomment the ones where you want to do custom work
|
||||
in between standard targets -->
|
||||
|
||||
<target name="-pre-build">
|
||||
<copy todir="src/org/cocos2dx">
|
||||
<fileset dir="..\..\..\cocos2dx\platform\android\java\src_common\org\cocos2dx">
|
||||
<include name="lib/" />
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-pre-compile">
|
||||
<path id="android.target.classpath">
|
||||
<pathelement path="${sdk.dir}/platforms/${target}/android.jar"/>
|
||||
<pathelement path="${sdk.dir}/platforms/${target}/data/layoutlib.jar"/>
|
||||
</path>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
/* This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir} */
|
||||
<target name="-post-compile">
|
||||
</target>
|
||||
-->
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
#Change the path expression of current path to cygwin path.
|
||||
NDK_ROOT=$($CYGWIN/bin/cygpath.exe $ANDROID_NDK)
|
||||
echo $NDK_ROOT
|
||||
CUR=$(pwd)
|
||||
cd ../../..
|
||||
tmp=$(pwd)
|
||||
COCOS2DX=$($CYGWIN/bin/cygpath.exe $tmp)
|
||||
echo $COCOS2DX
|
||||
|
||||
var1=NDK_ROOT_LOCAL=
|
||||
_NDK_ROOT=${var1}${NDK_ROOT}
|
||||
|
||||
var2=COCOS2DX_ROOT_LOCAL=
|
||||
_COCOS2DX_ROOT=${var2}${COCOS2DX}
|
||||
echo $_NDK_ROOT
|
||||
echo $_COCOS2DX_ROOT
|
||||
|
||||
#Modify the configuration files
|
||||
sed -i '3,4d' $CUR/build_native.sh
|
||||
sed -i '13d' $CUR/project.properties
|
||||
sed -i "3 i\\$_NDK_ROOT" $CUR/build_native.sh
|
||||
sed -i "4 i\\$_COCOS2DX_ROOT" $CUR/build_native.sh
|
||||
|
||||
#Modify the project name
|
||||
if [ $1 = TestCpp ]; then
|
||||
sed -i '2d' $CUR/build.xml
|
||||
sed -i '2 i\<project name="Tests" default="help">' $CUR/build.xml
|
||||
elif [ $1 = HelloCpp ]; then
|
||||
sed -i '2d' $CUR/build.xml
|
||||
sed -i '2 i\<project name="HelloCpp" default="help">' $CUR/build.xml
|
||||
else
|
||||
sed -i '2d' $CUR/build.xml
|
||||
sed -i '2 i\<project name="HelloLua" default="help">' $CUR/build.xml
|
||||
fi
|
Loading…
Reference in New Issue