編輯:關於Android編程
1編譯CCCommon.cpp
提示信息:
[armeabi] Compile++ thumb: cocos2dx_static <= CCCommon.cpp
D:/cocos2D/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/samples/HelloCpp/proj.android/../../../cocos2dx/platform/android/CCCommon.cpp: In function 'void cocos2d::CCLog(char const*, ...)':
D:/cocos2D/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/samples/HelloCpp/proj.android/../../../cocos2dx/platform/android/CCCommon.cpp:44:72: error: format not a string literal and no format arguments [-Werror=format-security]
cc1plus.exe: some warnings being treated as errors
解決方法:在jni/Application.mk後面加
APP_CFLAGS += -Wno-error=format-security
2.沒有指向jni/**/main.cpp錯誤
提示信息:make: *** No rule to make target 'jni/FX/main.cpp', needed by 'obj/local/armeabi/objs-debug/FX_shared/FX/main.o'。 停止。
解決方法:jni/Android.mk中的Local_SRC_PATH定義錯誤,具體的定義方法可以查看cocos2d-x下,自帶的sample實例。
3.NDK只支持少量的C或者C++庫造成的錯誤
提示:In file included from jni/FX/main.cpp:1:0:
jni/FX/main.h:7:21: fatal error: windows.h: No such file or directory
compilation terminated.
解決方法:main.cpp書寫錯誤,將main.h去掉
4.main.cpp錯誤
提示錯誤信息:[armeabi] Compile++ thumb: FX_shared <= main.cpp
jni/FX/main.cpp:10:14: error: expected initializer before '_tWinMain'
解決方案:按照cocos2d提供的實例去修改main.cpp
5.main.cpp包含了沒有的頭文件
提示信息:[armeabi] Compile++ thumb: FX_shared <= main.cpp
jni/FX/main.cpp:6:29: fatal error: HelloWorldScene.h: No such file or directory
compilation terminated.
解決方法:去掉沒有的頭文件
6.Android.mk中的Local_Src_Path定義錯誤
提示信息:[armeabi] Compile++ thumb: FX_shared <= main.cpp
[armeabi] Compile++ thumb: FX_shared <= *.cpp
arm-linux-androideabi-g++.exe: fatal error: cannot specify -o with -c, -S or -E with multiple files
compilation terminated.
解決方案:按照正確的方法書寫Android.mk中的Local_SRC_PATH
7.Box2D/Box2D.h No such file or directory
提示信息:In file included from jni/../../Classes/FX_PauseGameScene.h:2:0,
from jni/../../Classes/FX_PauseGameScene.cpp:1:
jni/../../Classes/FX_Global.h:8:25: fatal error: Box2D/Box2D.h: No such file or directory
compilation terminated.
解決方案:將包含的Box2D/Box2D.h頭文件去掉。或者將external下的Box2D目錄復制到要編譯項目的Class文件夾下。或者在Android.mk中增加
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
$(call import-module,external/Box2D)
8.SimpleAudioEngine:No such file or directory
提示信息:In file included from jni/../../Classes/FX_PauseGameScene.h:2:0,
from jni/../../Classes/FX_PauseGameScene.cpp:1:
jni/../../Classes/FX_Global.h:8:31: fatal error: SimpleAudioEngine.h: No such file or directory
compilation terminated.
解決方案:SimpleAudioEngine.cpp包含在CocosDenshion/android下因此要將加入import-module
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
$(call import-module,CocosDenshion/android)
9.build_native.sh中的NDK_BOOT定義格式錯誤
提示信息:
./build_native.sh: line 32: NDK_ROOT: command not found
定義NDK_ROOT路徑是,NDK_ROOT和等號之間沒有空格
10.NDK對於C的支持錯誤
提示信息:[armeabi] Compile++ thumb: FX_shared <= FX_StartGame.cpp
In file included from jni/../../Classes/FX_StartGame.cpp:1:0:
jni/../../Classes/FX_StartGameScene.h:25:2: error: 'CCArray' does not name a type
jni/../../Classes/FX_StartGame.cpp: In member function 'bool FX_StartGameScene::addPipeSprite()':
jni/../../Classes/FX_StartGame.cpp:63:2: error: 'pAniFrame' was not declared in this scope
jni/../../Classes/FX_StartGame.cpp:69:31: error: 'sprintf_s' was not declared in this scope
/cygdrive/D/android-ndk-r9d-windows-x86/android-ndk-r9d/build/core/build-binary.mk:393: recipe for target 'obj/local/armeabi/objs-debug/FX_sha
make: *** [obj/local/armeabi/objs-debug/FX_shared/__/__/Classes/FX_StartGame.o] Error 1
解決方案:提示有三個錯誤CCArray does not name a type錯誤時CCArray沒有定義類型,可以將CCArray改為cocos2d::CCArray
sprintf_s was not in this scope
NDK支持特定的C或者C++的庫,可以使用sprintf代替sprintf_s
其他常見錯誤
Q1:[armeabi] Compile++ thumb: FX_shared <= FXSharedMethod.cpp
jni/../../Classes/FXSharedMethod.cpp: In static member function 'static char* CFXSharedMethod::G2U(char const*)':
jni/../../Classes/FXSharedMethod.cpp:15:32: error: 'CP_ACP' was not declared in this scope
jni/../../Classes/FXSharedMethod.cpp:15:62: error: 'MultiByteToWideChar' was not declared in this scope
jni/../../Classes/FXSharedMethod.cpp:19:28: error: 'CP_UTF8' was not declared in this scope
jni/../../Classes/FXSharedMethod.cpp:19:69: error: 'WideCharToMultiByte' was not declared in this scope
/cygdrive/D/android-ndk-r9d-windows-x86/android-ndk-r9d/build/core/build-binary.mk:393: recipe for target 'obj/local/armeabi/objs-debug/FX_shad
make: *** [obj/local/armeabi/objs-debug/FX_shared/__/__/Classes/FXSharedMethod.o] Error 1
解決方案:使用了不支持的C++庫
問題:
創建項目後不能正常運行,提示錯誤:
fatal error C1083:無法打開包括文件:“CCStdC.h”:No such file or directory
fatal error C1083:無法打開包括文件:“SimpleAudioEngine.h”:No such file or directory
解決方法:
將 cocos2d-2.0-x-2.0.3中的 cocos2dx 及 CocosDenshion 文件夾整個復制到工程目錄下
Activities提供了一種方便管理的創建、保存、回復的對話框機制,例如 onCreateDialog(int), onPrepareDialog(int, Dialo
在Android開發當中,在界面上彈出一個Dialog對話框使我們經常需要做的,本篇做一下記錄,以備遺忘時查詢。dialog就是一個在屏幕上彈出一個可以讓用戶做出一個選擇
一、---框架---(1)新建布局,包括三個按鈕:播放、暫停、繼續播放,還有一個進度條(2)建立一個Service,其中有播放、暫停、繼續播放的方法(3)因為有進度條,所
說起Android 自定義View,網上的博客、視頻很多。鴻洋的博客和視頻還是很值得推薦的。本文打算結合Sdk源碼,來講解如何自定義一個View。本文結合TextView