Android ndk在eclipse中编译时出错

Posted

技术标签:

【中文标题】Android ndk在eclipse中编译时出错【英文标题】:Android ndk giving errors while compiling in eclipse 【发布时间】:2016-01-20 06:20:19 【问题描述】:

以下是我在 Eclipse 中的 android 应用程序的 Android.mk 文件。

    LOCAL_PATH := $(call my-dir)



include $(CLEAR_VARS)

OPENCV_CAMERA_MODULES := off

OPENCV_MK_PATH:=C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\OpenCV.mk


OPENCV_LIB_TYPE:=STATIC
OPENCV_INSTALL_MODULES:=on

include $(OPENCV_MK_PATH)

#Profiler 
#-include android-ndk-profiler.mk

#include ../includeOpenCV.mk
#ifeq ("$(wildcard $(OPENCV_MK_PATH))","")
#   #try to load OpenCV.mk from default install location
#   include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk
#else
#   include $(OPENCV_MK_PATH)
#endif

LOCAL_C_INCLUDES := C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include

LOCAL_MODULE    := native_wallet
LOCAL_SRC_FILES := jni_recognizer.cpp NativeVision/vision.cpp
LOCAL_CFLAGS=-ffast-math -O3 -funroll-loops
#LOCAL_CFLAGS=-O3 -funroll-loops

LOCAL_LDLIBS +=  -llog -ldl

#Profiling
#LOCAL_CFLAGS := -pg
#LOCAL_STATIC_LIBRARIES := andprof


include $(BUILD_SHARED_LIBRARY)

更新 opencv_mk_path 和 local_c_includes 后,应用程序没有通过 ndk 编译。我已经尝试了所有可能的解决方案,但没有运气。以下是发生的错误:

Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml    
[armeabi-v7a] Compile++ thumb: native_wallet <= jni_recognizer.cpp
jni/jni_recognizer.cpp: In function 'void Java_com_ndu_mobile_darwinwallet_Recognizer_nvTrainImage(JNIEnv*, jobject, jstring, jstring)':
jni/jni_recognizer.cpp:18:88: warning: format not a string literal and no format arguments [-Wformat-security]
 #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,   "JNI_DEBUGGING", __VA_ARGS__)
                                                                                        ^
jni/jni_recognizer.cpp:78:3: note: in expansion of macro 'LOGD'
   LOGD( out.str().c_str() );
   ^
jni/jni_recognizer.cpp:18:88: warning: format not a string literal and no format arguments [-Wformat-security]
 #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,   "JNI_DEBUGGING", __VA_ARGS__)
                                                                                        ^
jni/jni_recognizer.cpp:89:3: note: in expansion of macro 'LOGD'
   LOGD( out.str().c_str() );
   ^
jni/jni_recognizer.cpp: In function '_jstring* Java_com_ndu_mobile_darwinwallet_Recognizer_nvRecognize(JNIEnv*, jobject, jint, jint, jbyteArray)':
jni/jni_recognizer.cpp:18:88: warning: format not a string literal and no format arguments [-Wformat-security]
 #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,   "JNI_DEBUGGING", __VA_ARGS__)
                                                                                        ^
jni/jni_recognizer.cpp:216:4: note: in expansion of macro 'LOGD'
    LOGD( (char*) out.str().c_str());
    ^
[armeabi-v7a] Compile++ thumb: native_wallet <= vision.cpp
jni/NativeVision/vision.cpp: In function 'cv::Ptr<cv::ORB> getQueryDetector()':
jni/NativeVision/vision.cpp:18:76: error: cannot allocate an object of abstract type 'cv::ORB'
     Ptr<ORB> detector1 = new ORB(DEFAULT_QUERY_FEATURES, 1.2f, 5U, 10, 1, 2);
                                                                            ^
In file included from C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/calib3d.hpp:48:0,
                 from C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/calib3d/calib3d.hpp:48,
                 from jni/NativeVision/vision.h:2,
                 from jni/NativeVision/vision.cpp:1:
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:254:20: note:   because the following virtual functions are pure within 'cv::ORB':
 class CV_EXPORTS_W ORB : public Feature2D
                    ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:292:26: note:   virtual void cv::ORB::setMaxFeatures(int)
     CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;
                          ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:293:25: note:   virtual int cv::ORB::getMaxFeatures() const
     CV_WRAP virtual int getMaxFeatures() const = 0;
                         ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:295:26: note:   virtual void cv::ORB::setScaleFactor(double)
     CV_WRAP virtual void setScaleFactor(double scaleFactor) = 0;
                          ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:296:28: note:   virtual double cv::ORB::getScaleFactor() const
     CV_WRAP virtual double getScaleFactor() const = 0;
                            ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:298:26: note:   virtual void cv::ORB::setNLevels(int)
     CV_WRAP virtual void setNLevels(int nlevels) = 0;
                          ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:299:25: note:   virtual int cv::ORB::getNLevels() const
     CV_WRAP virtual int getNLevels() const = 0;
                         ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:301:26: note:   virtual void cv::ORB::setEdgeThreshold(int)
     CV_WRAP virtual void setEdgeThreshold(int edgeThreshold) = 0;
                          ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:302:25: note:   virtual int cv::ORB::getEdgeThreshold() const
     CV_WRAP virtual int getEdgeThreshold() const = 0;
                         ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:304:26: note:   virtual void cv::ORB::setFirstLevel(int)
     CV_WRAP virtual void setFirstLevel(int firstLevel) = 0;
                          ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:305:25: note:   virtual int cv::ORB::getFirstLevel() const
     CV_WRAP virtual int getFirstLevel() const = 0;
                         ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:307:26: note:   virtual void cv::ORB::setWTA_K(int)
     CV_WRAP virtual void setWTA_K(int wta_k) = 0;
                          ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:308:25: note:   virtual int cv::ORB::getWTA_K() const
     CV_WRAP virtual int getWTA_K() const = 0;
                         ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:310:26: note:   virtual void cv::ORB::setScoreType(int)
     CV_WRAP virtual void setScoreType(int scoreType) = 0;
                          ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:311:25: note:   virtual int cv::ORB::getScoreType() const
     CV_WRAP virtual int getScoreType() const = 0;
                         ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:313:26: note:   virtual void cv::ORB::setPatchSize(int)
     CV_WRAP virtual void setPatchSize(int patchSize) = 0;
                          ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:314:25: note:   virtual int cv::ORB::getPatchSize() const
     CV_WRAP virtual int getPatchSize() const = 0;
                         ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:316:26: note:   virtual void cv::ORB::setFastThreshold(int)
     CV_WRAP virtual void setFastThreshold(int fastThreshold) = 0;
                          ^
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:317:25: note:   virtual int cv::ORB::getFastThreshold() const
     CV_WRAP virtual int getFastThreshold() const = 0;
                         ^
jni/NativeVision/vision.cpp: In function 'cv::Ptr<cv::ORB> getTrainerDetector(int)':
jni/NativeVision/vision.cpp:29:76: error: cannot allocate an object of abstract type 'cv::ORB'
     Ptr<ORB> detector2 = new ORB(DEFAULT_QUERY_FEATURES, 1.2f, 5U, 10, 1, 2);
                                                                            ^
In file included from C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/calib3d.hpp:48:0,
                 from C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/calib3d/calib3d.hpp:48,
                 from jni/NativeVision/vision.h:2,
                 from jni/NativeVision/vision.cpp:1:
C:\Users\rabbia\Downloads\OpenCV300androidsdk1\OpenCV-android-sdk\sdk\native\jni\include/opencv2/features2d.hpp:254:20: note:   since type 'cv::ORB' has pure virtual functions
 class CV_EXPORTS_W ORB : public Feature2D
                    ^
jni/NativeVision/vision.cpp: In function 'cv::Mat trainImage(const cv::Mat&, cv::Ptr<cv::ORB>&, cv::Ptr<cv::DescriptorMatcher>&)':
jni/NativeVision/vision.cpp:149:24: error: 'class cv::ORB' has no member named 'operator()'
     detector->operator()( img, cv::noArray(), keypoints, descriptors, false );
                        ^
jni/NativeVision/vision.cpp: In function 'RecognitionResult recognize(const cv::Mat&, bool, cv::Mat*, cv::Ptr<cv::ORB>&, cv::Ptr<cv::DescriptorMatcher>&, std::vector<std::basic_string<char> >&, bool, int*)':
jni/NativeVision/vision.cpp:177:24: error: 'class cv::ORB' has no member named 'operator()'
     detector->operator()( queryImg, cv::noArray(), queryKeypoints, queryDescriptors, false );
                        ^
make.exe: *** [obj/local/armeabi-v7a/objs/native_wallet/NativeVision/vision.o] Error 1

请帮帮我。

【问题讨论】:

【参考方案1】:

    对于LOGD(),使用

    LOGD("%s", out.str().c_str());

    要获取Ptr&lt;ORB&gt; detector1,您应该使用ORB::create(),而不是new ORB()

【讨论】:

感谢您抽出宝贵时间,先生,但它不起作用。 LOGD() 方法包含与您相同的参数,除了这一行:#define LOGD(...) android_log_print(ANDROID_LOG_DEBUG, "JNI_DEBUGGING", __VA_ARGS) 请帮帮我。 LOGD 是一个宏,你粘贴的是它的定义。试试亚历克斯的建议。还有,out是什么类型的?

以上是关于Android ndk在eclipse中编译时出错的主要内容,如果未能解决你的问题,请参考以下文章

windows下eclipse搭建android_ndk开发环境

android NDK编译问题,在将项目中的JNI部分编译时,报出了错误,不能成功生成SO文件,

Eclipse下Android的NDK开发环境配置

我的Android进阶之旅解决Android Studio 编译NDK项目出错:clang++: error: no such file or directory

我的Android进阶之旅解决Android Studio 编译NDK项目出错:clang++: error: no such file or directory

如何用Android NDK编译FFmpeg