При попытке создать подписанный APK, он терпит неудачу с повторением ~ 100 строк:
Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: PLT offset too large, try linking with --long-plt
Я добавил --long-plt к аргументам:
externalNativeBuild {
cmake {
...
arguments '-DANDROID_STL=c++_static', '-Wl,--long-plt'
cppFlags "-frtti -fexceptions", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_shared"
}
}
Но, похоже, это ничего не меняет.
Работает с не подписанным (отладочным) генерацией apk и работает с arm64-v8a
.
Я имею дело с> 1 ГБ нативного кода, поэтому я предполагаю, что это главная причина.
Кажется, что почти нет документации или результатов поиска по этому поводу.
Нужно ли поставить --long-plt
куда-нибудь еще?Если нет, есть ли другой параметр, который можно изменить?Или поможет разделение кода на отдельные библиотеки?
Вот CMakeLists.txt для справки:
string(REPLACE "." "/" JAVA_GEN_SUBDIR ${JAVA_GEN_PACKAGE})
set(JAVA_GEN_DIR ${Project_SOURCE_DIR}/src/main/java/${JAVA_GEN_SUBDIR}/../../../../../generated)
# configure import libs
set(distribution_DIR ${PROJECT_SOURCE_DIR}/distribution)
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Note: One could use a 'GLOB' here, but newly added source files won't auto-regen build files
# After adding files, you'd need to 'touch' the CMakeLists.txt to re-gen
# SWIG required for build. Easy install is "brew install swig"
#Site: http://swig.org
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
# Remove old java files, in case we don't need to generate some of them anymore
#file(REMOVE_RECURSE ${JAVA_GEN_DIR})
# Ensure file recognized as C++ (otherwise, exported as C file)
set_property(SOURCE src/main/cpp/${LIBRARY_NAME}.i PROPERTY CPLUSPLUS ON)
# Setup SWIG flags and locations
set(CMAKE_SWIG_FLAGS -c++ -package ${JAVA_GEN_PACKAGE})
set(CMAKE_SWIG_OUTDIR ${JAVA_GEN_DIR})
# Export a wrapper file to Java, and link with the created C++ library
swig_add_module(${LIBRARY_NAME}_Wrapper java ${SWIG_I_FILE})
swig_link_libraries(${LIBRARY_NAME}_Wrapper ${LIBRARY_NAME})
# Include a location to the header files
include_directories(
src/main/cpp
${NativeLibPath}
${LUAPATH}
)
set(LUAPATH ${NativeLibPath}/lua)
file(GLOB ALL_SOURCE_FILES
"src/main/cpp/*.cpp"
"${NativeLibPath}/*.cpp"
"${LUAPATH}/*.c"
)
# 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.
${LIBRARY_NAME}
# Sets the library as a shared library.
SHARED
# Provides the list of files to compile.
${ALL_SOURCE_FILES} )
target_include_directories(${LIBRARY_NAME} PRIVATE)
# 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.
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.
${LIBRARY_NAME}
android
# Links the target library to the log library
# included in the NDK.
${log-lib}
)