Android NDK報錯(Eclipse)及解決方案

來源:互聯網
上載者:User

標籤:

      在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)及解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.