標籤:
在AndroidNDK開發過程中,工程目錄下的jni檔案夾下編寫的c/c++代碼,通常會出現如下的幾種類型的報錯:
1、Unresolved inclusion:<XXX>
2、syntax error
3、Function ‘XXX‘ could not be resolved
4、Type ‘XXX‘ could not be resolved
5、Symbol ‘XXX‘ could not be resolved
6、Method ‘XXX‘ could not be resolved
7、Invalid arguments ‘Candidates are: ...‘
1 錯誤形式一:沒有匯入標頭檔(這是最大的錯誤,會引起一系列下面的報錯)。通常會有如下表現形式:
1、Unresolved inclusion: <jni.h>、Unresolved inclusion: <stdio.h>、Unresolved inclusion: <malloc.h>、Unresolved inclusion: <Android/log.h>、...
2、Function ‘__android_log_print‘ could not be resolved、Type ‘JNIEnv‘ could not be resolved、Type ‘jstring‘ could not be resolved、Type ‘jclass‘ could not be resolved、Function ‘malloc‘ could not be resolved、Function ‘memcpy‘ could not be resolved、Method ‘FindClass‘ could not be resolved、Type ‘jsize‘ could not be resolved、Symbol ‘NULL‘ could not be resolved、...
解決方案:右擊項目 --> Properties --> 左側C/C++ General --> Paths and Symbols --> 右側Includes --> GNU C++(.cpp) --> Add——>${NDKROOT}\platforms\android-18\arch-arm\usr\include(tips:這裡的NDK platforms\android-18一定要和你的工程的properties裡的target一致)。
2 錯誤形式二:
1、Unresolved inclusion: <iostream>、Unresolved inclusion: <fstream>、Symbol ‘std‘ could not be resolved、..
2、Type ‘fstream‘ could not be resolved、Symbol ‘in‘ could not be resolved、Method ‘seekg‘ could not be resolved、Method ‘read‘ could not be resolved、...
解決方案: 添加路徑(步驟見上述解決方案):${NDKROOT}\sources\cxx-stl\gnu-libstdc++\4.8\include 、${NDKROOT}\sources\cxx-stl\gnu-libstdc++\4.8\libs\armeabi\include。
3 錯誤形式三: Invalid arguments ‘Candidates are:void * malloc(?)‘、Invalid arguments ‘Candidates are:void * memcpy(void *, const void *, ?)‘
解決方案: 添加路徑(步驟見上述解決方案):${NDKROOT}\toolchains\arm-linux-androideabi-4.8\prebuilt\windows\lib\gcc\arm-linux-androideabi\4.8\include
解決了錯誤,大家have fun
Android NDK報錯(Eclipse)及解決方案