试图在Android上运行Python - 使用cmake

时间:2017-10-03 20:46:52

标签: android python android-studio gradle cmake

我知道这是一个很长的镜头。

因此,使用这个GitHub Python项目,我目前能够在Android构建上使用gradle的实验版本运行Python。我们正在尝试升级到主线gradle和最新的Android Studio,因此我们尝试使用cMake构建所有NDK内容。我们拥有一切以便它可以运行,但是一旦我们启动Python它就说它无法导入_socket。

我们在项目中拥有所有相同的assests和Python,我们已经包含了所有共享库,因此我们认为编译和链接。有什么想法,我无法导入套接字的东西?我认为这是一个c模块,它试图导入和运行,但无法理解它无法找到它的不同之处。

enter image description here



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)




1 个答案:

答案 0 :(得分:0)

Android Studio 3发布,大约在Gradle 4.1发布的同时发布。现在使用这两种方法,我可以毫无问题地构建和运行Python。

我假设Gradle 4.1版本有一些修改我的问题。