Development OS: windows XP
My phone: motorola droid
My setup: I doubt I could remember all the steps but in general
make a folder C:\PhoneDev
make folders C:\PhoneDev\workspace and C:\PhoneDev\sdks
SDK setup
Install the latest sdk to C:\PhoneDev\sdks\android-sdk by following the
instructions here
http://developer.android.com/intl/de/sd ... quickstart
I used the eclipse-java-galileo-SR2-win32.zip version of eclipse from
http://www.eclipse.org/downloads/downlo ... -win32.zip
NDK setup
install cygwin from
http://www.cygwin.com/
I installed all packages of cygwin
download and extract the ndk from
http://developer.android.com/intl/de/sd ... index.html
copy the contents of the extracted folder to C:\PhoneDev\sdks\android-ndk
run cygwin and cd to /cygdrives/c/PhoneDev/sdks/android-ndk/build/
execute command "export ANDROID_NDK_ROOT=/cygdrives/c/PhoneDev/sdks/android-ndk"
run the ndk setup with the command ./host-setup.sh
NOTE: I actually installed everything to my F: drive and had some issues with setting things up so in cygwin I made a directory /apps with the commad mkdir /apps then in the /etc/fstab file I added the line F:/PhoneDev/sdks/android-ndk /apps ntfs binary 0 0
this was so that the ndk apps directory was easilly accessable
once this is done make sure you can build hello-jni to make sure everything is installed and working
After working from the command line which is tedious I found a way to edit cpp files in eclipse and have it automatically build when the file is save and show the build results in eclipse..
If you like working from the eclipse gui instead of the command line follow the instructions at
http://www.rbgrn.net/content/348-get-yo ... ted-ndk-on
Debugging
I never found a good way to debug so I just use lots of logging and asserts
the logging does show up in eclipse Catlog so that I dont have to open a log file or anything
example of how to log a message in cpp
log_msg( 0, "Failed getting earth texture");
example of assert
vx_assert( NULL != poEarthTex);
here is my code I use
vx_debug.h
Code: Select all
#pragma once
//============================================================================
// Copyright (C) 2010-2011 Brett R. Jones
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brett.r.jones@gmail.com
// http://www.roguetreasure.com
//============================================================================
typedef void (*LOG_FUNCTION )( unsigned long, char * );
/// log message types
#define MSG_TYPE_STATUS 0x00
#define MSG_TYPE_ERR 0x01
#define MSG_TYPE_FATAL_ERR 0x02
#define MSG_TYPE_DEBUG 0x04
#define MSG_TYPE_LOG 0x08
#define MSG_TYPE_ASSERTION 0x10
// log message source flags.. should be or'd with log message types
// Applications should define their own source flags in available bits 17–32
#define MSG_SRC_UNKNOWN 0x00000000
#define MSG_SRC_TC 0x00000100
#define MSG_SRC_IRR 0x00000200
#define MSG_SRC_GAME 0x00000400
// handy macro to determine if log message is a fatal error
#define IS_FATAL_ERR( msgtype ) ( MSG_TYPE_FATAL_ERR & msgtype )
#define TC_STATUS (MSG_SRC_TC | MSG_TYPE_STATUS)
#define TC_ERR (MSG_SRC_TC | MSG_TYPE_ERR)
#define TC_FATAL_ERR (MSG_SRC_TC | MSG_TYPE_FATAL_ERR)
#define TC_DBG (MSG_SRC_TC | MSG_TYPE_DEBUG)
#define TC_LOG (MSG_SRC_TC | MSG_TYPE_LOG)
#define TC_ASSERTION (MSG_SRC_TC | MSG_TYPE_LOG)
#define IRR_STATUS (MSG_SRC_IRR | MSG_TYPE_STATUS)
#define IRR_ERR (MSG_SRC_IRR | MSG_TYPE_ERR)
#define IRR_FATAL_ERR (MSG_SRC_IRR | MSG_TYPE_FATAL_ERR)
#define IRR_DBG (MSG_SRC_IRR | MSG_TYPE_DEBUG)
#define IRR_LOG (MSG_SRC_IRR | MSG_TYPE_LOG)
#define GAME_STATUS (MSG_SRC_GAME | MSG_TYPE_STATUS)
#define GAME_ERR (MSG_SRC_GAME | MSG_TYPE_ERR)
#define GAME_FATAL_ERR (MSG_SRC_GAME | MSG_TYPE_FATAL_ERR)
#define GAME_DBG (MSG_SRC_GAME | MSG_TYPE_DEBUG)
#define GAME_LOG (MSG_SRC_GAME | MSG_TYPE_LOG)
/// set function that logs a message
void set_log_handler( LOG_FUNCTION pfuncLogHandler );
/// log a message
void log_msg( unsigned long u32MsgType, const char* msg, ...);
#define MAX_ERR_MSG_SIZE 2048
#ifdef _DEBUG
/// This function is called by vx_assert() when the assertion fails.
void vx_error_output(char* exp, char * file, int line);
// debug mode throws message if expression is false
#define vx_assert(exp) { if (!(exp)) vx_error_output((char*)#exp,(char*)__FILE__,__LINE__); }
#define vx_verify(exp) { if (!(exp)) vx_error_output((char*)#exp,(char*)__FILE__,__LINE__); }
#else
// release mode evaluates vx_assert ect to null
#define vx_assert(exp)
#define vx_verify(exp) (exp)
#endif // RELEASE_MODE
vx_debug.cpp
Code: Select all
//============================================================================
// Copyright (C) 2010-2011 Brett R. Jones
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brett.r.jones@gmail.com
// http://www.roguetreasure.com
//============================================================================#include "VxUtilLib.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#ifdef WIN_PLATFORM
#include "windows.h"
#endif// WIN_PLATFORM
#ifdef ANDROID_PLATFORM
#include <android/log.h>
#endif// ANDROID_PLATFORM
void default_log_handler( unsigned long u32MsgType, char * pLogMsg );
void vx_error( const char* msg, ...);
LOG_FUNCTION g_pfuncLogHandler = default_log_handler;
//------------------------------------------------------------------------------
/// This function sets the handler of log messages
void set_log_handler( LOG_FUNCTION pfuncLogHandler )
{
g_pfuncLogHandler = pfuncLogHandler;
}
//------------------------------------------------------------------------------
/// This function is called by vx_assert() when the assertion fails.
void vx_error_output(char* exp, char * file, int line)
{
vx_error("** RT ASSERTION **\r\nexpression: %s\r\nfile: %s\r\nline: %d\r\n", exp, file, line);
}
//------------------------------------------------------------------------------
/// This function is called by vx_assert2() when the assertion fails.
void vx_error_output2(char* exp, char* msg, char* file, int line)
{
vx_error("** RT ASSERTION ***\r\nprogrammer says: %s\r\nexpression: %s\r\nfile: %s\r\nline: %d\r\n", msg, exp, file, line);
}
//------------------------------------------------------------------------------
/// This function is called when a serious situation is encountered which
/// requires abortion of the program.
void vx_error( const char* msg, ...)
{
char as8Buf[ MAX_ERR_MSG_SIZE * 2 ];
va_list argList;
va_start(argList, msg);
vsprintf( as8Buf, msg, argList );
va_end(argList);
// append the module name
//strcat( as8Buf, "Module Name: " );
//char as8ModuleName[ MAX_PATH ];
//VxGetExecuteModuleName( as8ModuleName, sizeof( as8ModuleName ) );
//strcat( as8Buf, as8ModuleName );
//strcat( as8Buf, "\r\n\r\n" );
//printf( as8Buf ); // show the error
//std::string strAssertFile = g_strUserAppDataDir + "vx_assert.txt";
//VxWriteWholeFile( strAssertFile.c_str(), as8Buf, (U32)strlen( as8Buf ) );
// fflush(stdout);
log_msg( MSG_TYPE_ASSERTION, as8Buf ); // send to log
//if( wxTheApp )
//{
// // if widgets is running attept to show the error
// wxMessageBox( as8Buf, "Program Error", wxICON_ERROR | wxICON_STOP );
//}
abort();
};
//------------------------------------------------------------------------------
/// default log handler
void default_log_handler( unsigned long u32MsgType, char * pLogMsg )
{
#ifdef ANDROID_PLATFORM
__android_log_print(ANDROID_LOG_INFO, "AndroidNative", pLogMsg);
#else
printf( pLogMsg );
#endif// ANDROID_PLATFORM
}
//------------------------------------------------------------------------------
/// log a message
void log_msg( unsigned long u32MsgType, const char* msg, ... )
{
char as8Buf[ MAX_ERR_MSG_SIZE ];
va_list argList;
va_start(argList, msg);
vsprintf( as8Buf, msg, argList );
va_end(argList);
#ifdef WIN_PLATFORM
#ifdef _DEBUG
OutputDebugStringA(as8Buf);
#endif //_DEBUG
#endif // WIN_PLATFORM
// send to log handler
g_pfuncLogHandler( u32MsgType, as8Buf );
}
I have not completed my code for callback into c++ code for mouse and gyroscope events but here is the example I am using for the basics
http://android.wooyd.org/JNIExample/