I know this is a long shot.
So using this GitHub Python project I am currently able to run Python on Android building with an experimental version of gradle. We are trying to upgrade to mainline gradle and the newest Android Studio, so we are trying to build all our NDK stuff with cMake. We have everything so that it will run, but as soon as we launch Python it says it fails to import _socket.
We have all the same assests and Python in the project, we have included all of the shared libraries so that thinks compile and link. Any ideas what is missing that I can't import the socket stuff? I assume this is a c module that it's trying to import and run, but can't understand what would be different that it can't find it.
cmake_minimum_required(VERSION 3.4.1)
project(workflow)
set(CMAKE_ANDROID_STL_TYPE gnustl_shared)
set(CMAKE_SYSTEM_VERSION 23)
# configure directory variables for use throughout this file
set(distribution_dir ${CMAKE_SOURCE_DIR}/../jniLibs)
set(jni_src_dir ${CMAKE_SOURCE_DIR}/../jni)
# set all our include directories (header locations)
include_directories(${jni_src_dir}/asr/inc
${jni_src_dir}/ext/android/audioin/inc
${jni_src_dir}/asr
${jni_src_dir}/python
${jni_src_dir}/pdd
${jni_src_dir}/pdd/os
${jni_src_dir}
)
# define the 3rd party libraries to include in this project
# this includes all Nuance stuff, and our custom built python lib
add_library(libgenericdca SHARED IMPORTED)
set_target_properties(libgenericdca PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libgenericdca.so)
add_library(libvocon3200_sem SHARED IMPORTED)
set_target_properties(libvocon3200_sem PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_sem.so)
add_library(libpal_audio SHARED IMPORTED)
set_target_properties(libpal_audio PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libpal_audio.so)
add_library(libpal_core SHARED IMPORTED)
set_target_properties(libpal_core PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libpal_core.so)
add_library(libpython35m SHARED IMPORTED)
set_target_properties(libpython35m PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libpython3.5m.so)
add_library(libvocon3200_asr SHARED IMPORTED)
set_target_properties(libvocon3200_asr PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_asr.so)
add_library(libvocon3200_base SHARED IMPORTED)
set_target_properties(libvocon3200_base PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_base.so)
add_library(libvocon3200_gram2 SHARED IMPORTED)
set_target_properties(libvocon3200_gram2 PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_gram2.so)
add_library(libvocon3200_platform SHARED IMPORTED)
set_target_properties(libvocon3200_platform PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_platform.so)
add_library(libvocon3200_pron SHARED IMPORTED)
set_target_properties(libvocon3200_pron PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_pron.so)
add_library(libvocon3200_sem3 SHARED IMPORTED)
set_target_properties(libvocon3200_sem3 PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_sem3.so)
add_library(libvocon_ext_heap SHARED IMPORTED)
set_target_properties(libvocon_ext_heap PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon_ext_heap.so)
add_library(libvocon_ext_stream SHARED IMPORTED)
set_target_properties(libvocon_ext_stream PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon_ext_stream.so)
# set various C and CXX(++) flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
# recursive wildcard search to find all the right cpp and c source files to compile
file(GLOB_RECURSE source_files ${jni_src_dir}/asr/*.cpp
${jni_src_dir}/ext/android/audioin/src/*.c
${jni_src_dir}/asr/*.cpp
${jni_src_dir}/pdd/*.cpp
${jni_src_dir}/pdd/os/*.cpp
${jni_src_dir}/*.cpp)
SET( workflow_source ${source_files})
# finally, set up our workflow library and attach the source files above (this causes cmake to compile the sources)
add_library(workflow SHARED ${workflow_source})
# set our workflow library to be C++
SET_TARGET_PROPERTIES (workflow PROPERTIES LINKER_LANGUAGE CXX)
# lastly, set to link against the 3rd party libs above
target_link_libraries(workflow
android
libgenericdca
libvocon3200_sem
libpal_audio
libpal_core
libpython35m
libvocon3200_asr
libvocon3200_base
libvocon3200_gram2
libvocon3200_platform
libvocon3200_pron
libvocon3200_sem3
libvocon_ext_heap
libvocon_ext_stream
log
atomic)
Android Studio 3 was released and around the same time Gradle 4.1 was released. Now with using both of these I'm able to build and run Python without issue.
I'm assuming the Gradle 4.1 release had some change that fixed my issue.
Related
I've been trying to compile and run an Android / ReactNative CMake project, but it fails to run whenever I make the library shared. I get the error that the header files for lib_gmath ,lib_gperf,libsqliteX cannot be found during build.
../../../../src/main/jni/hello-libs.cpp:21:10: fatal error: 'gmath.h' file not found
#include <gmath.h>
However, everything compiles OK when I change ${LIB_GEN_PERS} to static, but then I get a runtime error :
java.lang.UnsatisfiedLinkError: dlopen failed: library "lib-gen-lib-pers.so" not found
What am I doing wrong?
Thank you all in advance.
CMake.txt
cmake_minimum_required(VERSION 3.6.0)
project(gen-lib-pers)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(LIB_GEN_PERS "gen-lib-pers")
add_library(${LIB_GEN_PERS} SHARED)
find_library(log-lib log)
## LIB DIRECTORIES
set(RES_LIBS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/main/res/libs)
add_library(lib_gmath STATIC IMPORTED)
set_target_properties(lib_gmath PROPERTIES
IMPORTED_LOCATION ${RES_LIBS_DIR}/gmath/lib/${ANDROID_ABI}/libgmath.a
INCLUDE_DIRECTORIES ${RES_LIBS_DIR}/gmath/include
)
add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES
IMPORTED_LOCATION ${RES_LIBS_DIR}/gperf/lib/${ANDROID_ABI}/libgperf.so
INCLUDE_DIRECTORIES ${RES_LIBS_DIR}/gperf/include
)
add_library(libsqliteX SHARED IMPORTED)
set_target_properties(libsqliteX PROPERTIES
IMPORTED_LOCATION ${RES_LIBS_DIR}/sqlite3/lib/${ANDROID_ABI}/libsqliteX.so
INCLUDE_DIRECTORIES ${RES_LIBS_DIR}/sqlite3/include
)
add_library(hello-libs STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jni/hello-libs.cpp)
target_link_libraries(hello-libs
lib_gmath
lib_gperf
libsqliteX
android
${log-lib}
)
target_link_libraries(${LIB_GEN_PERS} hello-libs)
sorry bad english
cloned and compiled this project in Android Studio:
https://github.com/Pangu-Immortal/KeepAlivePerfect/
During compile, got the following error (using ndk 24.0.8215888):
KeepAlivePerfect/library/src/main/cpp/binder_libs/armeabi-v7a/libbinder.so: invalid sh_info in symbol table
tested both in linux and windows. Same error.
plz help
Finally could compile with changing SHARED to STATIC in CMakeLists.txt. And some more config.
Here are the changes:
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/)
add_compile_options(-fno-rtti -O3 -v)
message(###${CMAKE_CURRENT_SOURCE_DIR})
link_directories(binder_libs/${CMAKE_ANDROID_ARCH_ABI})
aux_source_directory(. SRC_LIST) # 搜索当前目录下的所有.cpp文件
add_library( # Sets the name of the library.
keep_alive
# Sets the library as a shared library.
STATIC # Changed from SHARED to STATIC
# 提供源文件的相对路径。
${SRC_LIST} main.cpp art.cpp)
# More Config
set_target_properties(keep_alive PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/binder_libs/${ANDROID_ABI}/libutils.so)
set_target_properties(keep_alive PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/binder_libs/${ANDROID_ABI}/libc.so)
set_target_properties(keep_alive PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/binder_libs/${ANDROID_ABI}/libcutils.so)
set_target_properties(keep_alive PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/binder_libs/${ANDROID_ABI}/libutils.so)
# The END
find_library(log-lib log)
target_link_libraries(
keep_alive
${log-lib}
)
More information in an issue in main project:
https://github.com/Pangu-Immortal/KeepAlivePerfect/issues/8#issuecomment-1107427875
I'm working on an Android native project where I'm using NDK + CMake to build a native solution based on POCO C++. I'm getting a super weird link error when I comment this line in my cpp file:
//std::ostream& o = session.sendRequest(request);
this is the link error:
../NetSSL_OpenSSL/src/SecureSocketImpl.cpp:381: error: undefined reference to 'Poco::Net::SocketAddress::~SocketAddress()'
But is even more weird that the file with the object where sendRequest is placed it is not being included in any other file. So, I have one isolated file (header and implementation) that is not being included in any other file (but it is build with CMake, I cannot remove it because of the issue) and if I comment one line of the implementation, it generates a link issue.
This is how I'm linking Poco:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_COMPILER_VERSION "5.0") # Unknown miss-detection of the compiler by CMake
find_library( # Defines the name of the path variable that stores the
# location of the NDK library.
log-lib
# Specifies the name of the NDK library that
# CMake needs to locate.
log )
add_library(PocoFoundation STATIC IMPORTED)
set_target_properties(PocoFoundation PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoFoundation.a)
add_library(PocoNet STATIC IMPORTED)
set_target_properties(PocoNet PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoNet.a)
add_library(PocoJSON STATIC IMPORTED)
set_target_properties(PocoJSON PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoJSON.a)
add_library(PocoNetSSL STATIC IMPORTED)
set_target_properties(PocoNetSSL PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoNetSSL.a)
add_library(PocoCrypto STATIC IMPORTED)
set_target_properties(PocoCrypto PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoCrypto.a)
add_library(PocoUtil STATIC IMPORTED)
set_target_properties(PocoUtil PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoUtil.a)
add_library(PocoXML STATIC IMPORTED)
set_target_properties(PocoXML PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoXML.a)
// ... SOURCES ...
target_include_directories(mylib PRIVATE /Users/user/dev/poco-2/install/include)
target_link_libraries(mylib
PocoNet
PocoNetSSL
PocoUtil
PocoJSON
PocoCrypto
PocoXML
PocoFoundation
Ssl
Crypto
${log-lib})
Also, I'm using Android Studio 3.6.2 with NDK version r19c. I have tried cleaning the build, rebuilding and cleaning .cxx, .gradle and build folder.
Any idea?
You need to recreate the inter-library dependencies such that CMake can construct the correct linker command line with dependencies after the libraries that depend on them.
Running through the libraries you listed, that should be at least the following (reconstructed from the Poco CMakeLists.txt).
target_link_libraries(PocoNet PocoFoundation)
target_link_libraries(PocoNetSSL PocoCrypto PocoUtil PocoNet)
target_link_libraries(PocoCrypto PocoFoundation Ssl Crypto)
target_link_libraries(PocoUtil PocoFoundation)
target_link_libraries(PocoJSON PocoFoundation)
target_link_libraries(PocoXML PocoFoundation)
I am getting null UnsatisfiedLinkError while building my app.
i am using openssl and some third party libraries to capture finger and verify them.
here is my cmake file
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
add_library(openssl SHARED IMPORTED)
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libcrypto.so )
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libssl.so )
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libidkit.so )
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libjnidispatch.so )
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libMSO100.so )
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libNativeMorphoSmartSDK_6.13.2.0-4.1.so )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
include_directories(openssl-armeabi-v7a/include/)
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
${CMAKE_CURRENT_SOURCE_DIR}/openssl-armeabi-v7a/lib/libcrypto.a
${CMAKE_CURRENT_SOURCE_DIR}/openssl-armeabi-v7a/lib/libssl.a
# Links the target library to the log library
# included in the NDK.
${log-lib} )
is this correct way of loading .so file in cmake or is there any method to load .so files . help with this issue
Each .so file that you list is a separate library. You must give each a separate name, e.g.
add_library(foo SHARED IMPORTED)
set_target_properties (foo PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libcrypto.so )
add_library(prebuilt_ssl SHARED IMPORTED)
set_target_properties (prebuilt_ssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libssl.so )
add_library(idkit SHARED IMPORTED)
set_target_properties (idkit PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libidkit.so )
and so on. As you can see above, the logical name is not necessarily related to the file name.
If your native-lib depends on some of them, you can use these names:
target_link_libraries( # Specifies the target library.
native-lib foo prebuilt_ssl
# Links the target library to the log library
# included in the NDK.
log )
Note that with NDK, you don't need find_library to add dependency on the android log library.
There is some self-contradiction in the CMake script that you posted. You should use OpenSSL libraries either as shared objects (as libssl.so), or static libraries (as libssl.a), but not both. It's OK to mix libjnidispatch.so together with libssl.a, but not libcrypto.a and libssl.so.
From google examples I'm trying to customize hello-libs example addind my shared library libofr_engine_core
but i receive this error...
Error:error: 'C:/Users/.../Downloads/android-ndk-master/hello-libs/distribution/ofr/lib/arm64-v8a/libofr_engine_core.so', needed by 'C:/Users/.../Downloads/android-ndk-master/hello-libs/app/build/intermediates/cmake/debug/obj/arm64-v8a/libhello-libs.so', missing and no known rule to make it
What I'm doing wrong?
Obviously I have added the .so and .h to my distribution folder
cmake_minimum_required(VERSION 3.4.1)
# configure import libs
set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../../distribution)
add_library(lib_gmath STATIC IMPORTED)
set_target_properties(lib_gmath PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/gmath/lib/${ANDROID_ABI}/libgmath.a)
# shared lib will also be tucked into APK and sent to target
# refer to app/build.gradle, jniLibs section for that purpose.
# ${ANDROID_ABI} is handy for our purpose here. Probably this ${ANDROID_ABI} is
# the most valuable thing of this sample, the rest are pretty much normal cmake
add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libgperf.so)
add_library(libofr_engine_core SHARED IMPORTED)
set_target_properties(libofr_engine_core PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/ofr/lib/${ANDROID_ABI}/libofr_engine_core.so)
# build application's shared lib
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
add_library(hello-libs SHARED
hello-libs.cpp)
target_include_directories(hello-libs PRIVATE
${distribution_DIR}/gmath/include
${distribution_DIR}/gperf/include
${distribution_DIR}/ofr/include
)
target_link_libraries(hello-libs
android
lib_gmath
lib_gperf
libofr_engine_core
log)