ISSUE: Running PCL Library with Android Project

丶灬走出姿态 提交于 2019-12-25 07:16:16

问题


I had compiled the PCL-SuperBuild folder as these links described:

Link 1: https://hcteq.wordpress.com/2014/07/14/compiling-pcl-for-android-in-windows-cmake-gui/# Link 2: http://www.hirotakaster.com/weblog/how-to-build-pcl-for-android-memo/

It Completed successfully. However, I don't know how to use the library in my project, Can anyone elaborate in this?

I'm trying to run the code in https://github.com/roomplan/tango-examples-java.git, the Point Cloud with PCL one, and I have tried to write an Android.mk file, but I have field.

Noting That, I'm using Android Studio with NDK, and Windows 8 as running operating System.

EDIT: I had fix my issue with PCL Linking to My Project, The library had recognized and the project build successfully. However, When I run the application on Tango device I got an UnsatisfiedLinkexception as follow:

? E/art: dlopen("/data/app-lib/com.projecttango.experiments.javapointcloud-2/libhelloPcl.so", RTLD_LAZY) failed: dlopen failed: could not load library "libflann.so" needed by "libhelloPcl.so"; caused by library "libflann.so" not found
? D/AndroidRuntime: Shutting down VM
? E/AndroidRuntime: FATAL EXCEPTION: main
   Process: com.projecttango.experiments.javapointcloud, PID: 2119
            java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "libflann.so" needed by "libhelloPcl.so"; caused by library "libflann.so" not found
            at java.lang.Runtime.loadLibrary(Runtime.java:364)
            at java.lang.System.loadLibrary(System.java:526)
            at com.projecttango.experiments.javapointcloud.PointCloudActivity.onCreate(PointCloudActivity.java:81)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2160)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2246)
            at android.app.ActivityThread.access$800(ActivityThread.java:136)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5030)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)

This is My Application.MK

APP_STL := gnustl_static
APP_ABI := armeabi-v7a
APP_PLATFORM := android-19
APP_CPPFLAGS := -frtti -fexceptions

Android.mk

LOCAL_PATH := $(call my-dir)
PROJECT_ROOT_FROM_JNI := ../../../../..
PROJECT_ROOT:= $(LOCAL_PATH)/$(PROJECT_ROOT_FROM_JNI)

PCL_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/pcl-android
BOOST_ANDROID_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/boost-android
FLANN_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/flann-android
EIGEN_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/eigen    

# PCL libraries
PCL_STATIC_LIB_DIR := $(PCL_INCLUDE)/lib
BOOST_STATIC_LIB_DIR := $(BOOST_ANDROID_INCLUDE)/lib
FLANN_STATIC_LIB_DIR := $(FLANN_INCLUDE)/lib

PCL_STATIC_LIBRARIES :=     pcl_common pcl_geometry pcl_kdtree pcl_octree pcl_sample_consensus pcl_surface \
                            pcl_features pcl_keypoints pcl_search pcl_tracking pcl_filters pcl_ml \
                            pcl_registration pcl_segmentation
BOOST_STATIC_LIBRARIES :=   boost_date_time boost_iostreams boost_regex boost_system \
                            boost_filesystem boost_program_options boost_signals boost_thread
FLANN_STATIC_LIBRARIES :=   flann_s flann_cpp_s


define build_pcl_static
    include $(CLEAR_VARS)
    LOCAL_MODULE:=$1
    LOCAL_SRC_FILES:=$(PCL_STATIC_LIB_DIR)/lib$1.a
    include $(PREBUILT_STATIC_LIBRARY)
endef

define build_boost_static
    include $(CLEAR_VARS)
    LOCAL_MODULE:=$1
    LOCAL_SRC_FILES:=$(BOOST_STATIC_LIB_DIR)/lib$1.a
    include $(PREBUILT_STATIC_LIBRARY)
endef

define build_flann_static
    include $(CLEAR_VARS)
    LOCAL_MODULE:=$1
    LOCAL_SRC_FILES:=$(FLANN_STATIC_LIB_DIR)/lib$1.a
    include $(PREBUILT_STATIC_LIBRARY)
endef

$(foreach module,$(PCL_STATIC_LIBRARIES),$(eval $(call build_pcl_static,$(module))))
$(foreach module,$(BOOST_STATIC_LIBRARIES),$(eval $(call build_boost_static,$(module))))
$(foreach module,$(FLANN_STATIC_LIBRARIES),$(eval $(call build_flann_static,$(module))))


include $(CLEAR_VARS)

# Project and linking

#opencv
#OPENCVROOT:= $(LOCAL_PATH)/../../../../../OpenCV-android-sdk
#OPENCV_CAMERA_MODULES:=on
#OPENCV_INSTALL_MODULES:=on
#OPENCV_LIB_TYPE:=SHARED
#include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := helloPcl

#LOCAL_SHARED_LIBRARIES := tango_client_api

LOCAL_CFLAGS    := -std=gnu++11
#-Werror -std=c++11

LOCAL_SRC_FILES := hello-pcl.ccp

LOCAL_C_INCLUDES := $(PROJECT_ROOT)/tango-gl/include \
                    $(PROJECT_ROOT)/third-party/glm/ \
                    $(PCL_INCLUDE)/include/pcl-1.6 \
                    $(BOOST_ANDROID_INCLUDE)/include \
                    $(EIGEN_INCLUDE) \
                    $(FLANN_INCLUDE)/include


LOCAL_LDFLAGS += -L$(PCL_INCLUDE)/lib  \
                 -L$(BOOST_ANDROID_INCLUDE)/lib \
                 -L$(FLANN_INCLUDE)/lib

LOCAL_SHARED_LIBRARIES   += pcl_common pcl_geometry pcl_search pcl_kdtree pcl_octree pcl_sample_consensus \
                            pcl_surface pcl_features pcl_filters pcl_keypoints pcl_tracking pcl_ml \
                            pcl_registration pcl_segmentation

LOCAL_SHARED_LIBRARIES   += boost_date_time boost_iostreams boost_regex boost_system \
                            boost_filesystem boost_program_options boost_signals boost_thread

LOCAL_SHARED_LIBRARIES   += flann flann_cpp

LOCAL_LDLIBS    += -L$(SYSROOT)/usr/lib \
                   -lstdc++ -lc -lm -llog -landroid -ldl -lGLESv2 -lEGL \
                   -lpcl_common -lpcl_geometry -lpcl_search -lpcl_kdtree -lpcl_octree -lpcl_sample_consensus \
                   -lpcl_surface -lpcl_features -lpcl_filters -lpcl_keypoints -lpcl_tracking -lpcl_ml \
                   -lpcl_registration -lpcl_segmentation \
                   -lflann -lflann_cpp

LOCAL_CFLAGS += -mfloat-abi=softfp -mfpu=neon -march=armv7 -mthumb -O3

include $(BUILD_SHARED_LIBRARY)

#$(call import-add-path, $(PROJECT_ROOT))
#$(call import-module,tango_client_api)

Note: I have Changed the PCL code to the HelloPCL Sample found in the link: https://github.com/otherlab/pcl/blob/master/mobile_apps/android/PCLAndroidSample

My app.gradle as follow:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"


    defaultConfig {
        applicationId "com.projecttango.experiments.javapointcloud"
        minSdkVersion 19
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"

        ndk {
            moduleName 'helloPcl'
        }
    }

    sourceSets.main {
        jni.srcDirs = [];
        jniLibs.srcDir 'src/main/libs'
    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
    }
}

task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
    def ndkDir = android.ndkDirectory
    commandLine "$ndkDir/ndk-build.cmd",
            '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
            '-j', Runtime.runtime.availableProcessors(),
            'all',
            'NDK_DEBUG=1'
}

task cleanNative(type: Exec, description: 'Clean JNI object files') {
    def ndkDir = android.ndkDirectory
    commandLine "$ndkDir/ndk-build.cmd",
            '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
            'clean'
}

clean.dependsOn 'cleanNative'

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn buildNative
}

def external_lib_prefix = null
if (project.hasProperty("Tango.catkin_devel_prefix")) {
    external_lib_prefix = project.property("Tango.catkin_devel_prefix")
} else {
    // Building in standalone sample form.
    external_lib_prefix = "../../TangoReleaseLibs"
}


repositories{
    flatDir{
        dirs external_lib_prefix + '/aar'
    }
}

dependencies {
    compile(name: 'tango-ux-support-library', ext: 'aar')
    compile(name: 'tango_support_java_lib', ext: 'aar')
    compile 'org.rajawali3d:rajawali:1.0.294-SNAPSHOT@aar'
    compile(name: 'TangoUtils', ext: 'aar')
    testCompile 'junit:junit:4.12'
}

Anyone advice me in this error


回答1:


I had fix my issue above, actually I had write the hello-pcl.ccp instead of hello-pcl.cpp.

Now, I have a build problem in PCL files. Sample:

C:\Users\M\Desktop\Android_Projects_(Master)\tango-examples-java-master\PCL\pcl-android\include\pcl-1.6\pcl\pcl_base.h
Error:(303, 40) error: use of deleted function 'boost::shared_ptr<const sensor_msgs::PointCloud2>::shared_ptr(const boost::shared_ptr<const sensor_msgs::PointCloud2>&)'
Error:(329, 39) error: use of deleted function 'boost::shared_ptr<std::vector<int> >::shared_ptr(const boost::shared_ptr<std::vector<int> >&)'
       getIndices () { return (indices_); }

and

C:\Users\M\Desktop\Android_Projects_(Master)\tango-examples-java-master\PCL\pcl-android\include\pcl-1.6\pcl\kdtree\kdtree_flann.h
Error:(386, 25) error: use of deleted function 'boost::shared_ptr<const std::vector<int> >::shared_ptr(const boost::shared_ptr<const std::vector<int> >&)'
Error:(393, 23) error: use of deleted function 'boost::shared_ptr<const pcl::PointCloud<Eigen::Matrix<float, -1, -1> > >::shared_ptr(const boost::shared_ptr<const pcl::PointCloud<Eigen::Matrix<float, -1, -1> > >&)'
         return (input_);

I don't get why it gives me errors and other warning in the library files themselves?

Thanks

EDIT I had changed my boost version to 1.55 in source folder. Also, I had changed my Android.mk to the following:

LOCAL_PATH := $(call my-dir)
PROJECT_ROOT_FROM_JNI := ../../../../..
PROJECT_ROOT:= $(LOCAL_PATH)/$(PROJECT_ROOT_FROM_JNI)

PCL_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/pcl-android
BOOST_ANDROID_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/boost
FLANN_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/flann-android
EIGEN_INCLUDE := $(LOCAL_PATH)/../../../../../PCL/eigen
BOOST_ANDROID := $(LOCAL_PATH)/../../../../../PCL/boost-android



include $(CLEAR_VARS)

# Project and linking

#opencv
#OPENCVROOT:= $(LOCAL_PATH)/../../../../../OpenCV-android-sdk
#OPENCV_CAMERA_MODULES:=on
#OPENCV_INSTALL_MODULES:=on
#OPENCV_LIB_TYPE:=SHARED
#include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := helloPcl

#LOCAL_SHARED_LIBRARIES := tango_client_api

LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_CFLAGS    := --std=c++11 -fexceptions
#-std=gnu++11
#-Werror -std=c++11

LOCAL_SRC_FILES := hello-pcl.cpp

LOCAL_ALLOW_UNDEFINED_SYMBOLS := true

LOCAL_C_INCLUDES := $(PCL_INCLUDE)/include/pcl-1.6/ \
                    $(BOOST_ANDROID_INCLUDE)/boost_1_45_0/ \
                    $(EIGEN_INCLUDE)/ \
                    $(FLANN_INCLUDE)/include/


LOCAL_LDFLAGS += -L$(PCL_INCLUDE)/lib  \
                 -L$(BOOST_ANDROID_INCLUDE)/lib \
                 -L$(FLANN_INCLUDE)/lib


LOCAL_SHARED_LIBRARIES   += pcl_common pcl_geometry pcl_search pcl_kdtree pcl_octree pcl_sample_consensus \
                            pcl_surface pcl_features pcl_filters pcl_keypoints pcl_tracking pcl_ml \
                            pcl_registration pcl_segmentation

LOCAL_SHARED_LIBRARIES   += boost_date_time boost_iostreams boost_regex boost_system \
                            boost_filesystem boost_program_options boost_signals boost_thread

LOCAL_SHARED_LIBRARIES   += flann flann_cpp

#LOCAL_CFLAGS += -mfloat-abi=softfp -mfpu=neon -march=armv7 -mthumb -O3

LOCAL_LDLIBS    := -llog -lGLESv2 -L$(BOOST_ANDROID)/lib -lboost_system
# Boost Libraries
LOCAL_LDLIBS    += -L$(BOOST_ROOT)/libs/armeabi-v7a/


# PCL Libraries
LOCAL_LDLIBS    += -L$(PCL_ROOT)/lib/ -lpcl_io -lpcl_io_ply -lpcl_common -lpcl_octree \
                                   -lstdc++ -lc -lm -llog -landroid -ldl -lGLESv2 -lEGL \
                                   -lpcl_common -lpcl_geometry -lpcl_search -lpcl_kdtree -lpcl_octree -lpcl_sample_consensus \
                                   -lpcl_surface -lpcl_features -lpcl_filters -lpcl_keypoints -lpcl_tracking -lpcl_ml \
                                   -lpcl_registration -lpcl_segmentation \
                                   -lflann -lflann_cpp

include $(BUILD_SHARED_LIBRARY) 

as I said in the comment below, all problems are solved, but I have a running problem

could not load library "libflann.so" needed by "libhelloPcl.so"



来源:https://stackoverflow.com/questions/35491012/issue-running-pcl-library-with-android-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!