I have created android studio project with c++ support and installed native development kit and other required tools. How to import another prebuilt native library to include in c++ code. I want to do something like this
I have edited cmakelist.txt as given below and now it show shared library under cpp folder.
cmake_minimum_required(VERSION 3.4.1)
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)
add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libgperf.so)
add_library(lib_ocr SHARED IMPORTED)
set_target_properties(lib_ocr PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/ocr/lib/${ANDROID_ABI}/libLPROCR.so)
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)
target_link_libraries(hello-libs
android
lib_gmath
lib_gperf
lib_ocr
log)
But i am not able to include classes from that prebuilt library in my c++ code.
There are few things that I should mention here.
I suggest to switch to gradle+clang for building your code. Android.mk is somehow getting old and it is better to use newer build systems if you are starting new project.
Make sure that your prebuilt library can be used in android. If it is not, you need to build it first. For example I built openssl myself because I could not find a suitable prebuilt library.
In case your are using gradle+cmake, here is a simple CMakeLists.txt file for your prebuilt libraries:
cmake_minimum_required(VERSION 3.4.1)
add_library( core-api
SHARED
src/main/cpp/mysource.c )
# prebuilt libraries
add_library( crypto-lib
STATIC
IMPORTED )
set_target_properties( crypto-lib
PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_SOURCE_DIR}/../prebuilt/crypto/${ANDROID_ABI}/lib/libcrypto.a )
include_directories( src/main/cpp/
../prebuilt/crypto/common/include/
../prebuilt/crypto/${ANDROID_ABI}/include/ )
# other libraries
find_library( log-lib
log )
target_link_libraries( core-api
crypto-lib
${log-lib} )
And this is a gradle file that uses this CMakeLists.txt:
apply plugin: 'com.android.library'
android {
compileSdkVersion rootProject.ext.sdkVersion
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_static"
cFlags "-D__STDC_FORMAT_MACROS", "-fno-integrated-as"
}
}
ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
}
buildTypes {
release {
minifyEnabled true
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
externalNativeBuild {
cmake {
cFlags "-Wall","-DDEBUG"
}
}
debuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
Related
I am creating a project in android studio with using opencv library. my ndk is r23 and my cmake is 3.18.1.
this is my graddle.build(app):
plugins {
id 'com.android.application'
}
android {
namespace 'com.example.slam3'
compileSdk 33
defaultConfig {
applicationId "com.example.slam3"
minSdk 29
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags '-std=c++11'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.18.1'
}
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation project(path: ':openCV')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
i use CMakeLists.txt for using a simple native lib in my project. my CMakeLists.txt:
set(pathToProject C:/Users/HYPER_STOCK_TABRIZ/AndroidStudioProjects/Slam3)
set(pathToOpenCV C:/Users/HYPER_STOCK_TABRIZ/AndroidStudioProjects/OpenCV-android-sdk)
#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.18.1)
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
include_directories(${pathToOpenCV}/sdk/native/jni/include)
# Declares and names the project.
project("slam3")
# 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.
slam3
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp)
add_library(lib_opencv SHARED IMPORTED)
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.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.
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(slam3 ${log-lib} lib_opencv)
When i run project in device i see this error:
C/C++: ld: error: found local symbol '__bss_start' in global part of symbol table in file C:/Users/HYPER_STOCK_TABRIZ/AndroidStudioProjects/Slam3/app/src/main/jniLibs/arm64-v8a/libopencv_java3.so
i test this
but still i has the same error. how can i solve it?
I am trying to use these libraries in my Android project but I am getting many of these similar kind of errors. I have all the tools installed (NDK, LLDB and CMake) but I am still not able to use the library.
After trying to run the project, all the C++ functions in the header files are unrecognized and compiler shows Error:error: undefined reference to 'std::string::c_str() const' and similar other undefined reference errors of C++ functions. Find the complete log of errors here.
Here is my CMakeLists.txt
# 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 )
# 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.
include_directories(src/main/cpp/include/ src/main/cpp/include/alglib3 src/main/cpp/include/device src/main/cpp/include/gsl src/main/cpp/include/base)
add_library ( gsl STATIC IMPORTED)
add_library ( gslcblas STATIC IMPORTED)
add_library ( alglib STATIC IMPORTED)
add_library ( crystalport STATIC IMPORTED)
set_target_properties( crystalport PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/libs/armeabi-v7a/libcrystalport_android.a)
set_target_properties( gsl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/libs/armeabi-v7a/libgsl.a)
set_target_properties( gslcblas PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/libs/armeabi-v7a/libgslcblas.a)
set_target_properties( alglib PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/libs/armeabi-v7a/libalglib.a)
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib}
alglib
crystalport
gslcblas
gsl
)
Here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "sadboy.circadian"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -fexceptions"
}
}
ndk {
abiFilters "armeabi-v7a"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
repositories{
maven {url "https://jitpack.io"}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-annotations:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Using gnustl_* seems to be able to build:
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -fexceptions"
arguments "-DANDROID_STL=gnustl_static"
}
}
Also using extern "C" to avoid runtime error in my native-lib.cpp file.
I try import openCV with contrib on Android. I referenced this site:
http://www.cnblogs.com/fx-blog/p/8206737.html
I failed to build opencv with contrib for Android, so I downloaded opencv with contrib sdk. I imported module, set dependency and write CMakeLists and build.gradle
Here is my CMakeLists and build.gradle
CMakeLists.txt
# 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)
set(pathOPENCV E:/opencv/opencv3-android-sdk-with-contrib-master/OpenCV-android-sdk)
set(pathPROJECT C:/Users/sms28/Downloads/artoolkit-android-studio-example- master/MyApplication7)
set(pathLIBOPENCV_JAVA C:/Users/sms28/Downloads/artoolkit-android-studio-example- master/MyApplication7/app/src/main/JniLibs/${ANDROID_ABI}/libopencv_java3.so)
set(CMAKE_VERBOSE_MAKEFILE on)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
include_directories(${pathOPENCV}/sdk/native/jni/include)
# 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(libopencv_java3 SHARED IMPORTED )
set_target_properties(libopencv_java3 PROPERTIES
IMPORTED_LOCATION "${pathLIBOPENCV_JAVA}")
add_library( # Sets the name of the library.
xfeatures2d
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/xfeatures2d_init.cpp
src/main/cpp/sift.cpp
src/main/cpp/surf.cpp
src/main/cpp/freak.cpp )
# 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.
xfeatures2d android log libopencv_java3
# Links the target library to the log library
# included in the NDK.
${log-lib} )
build.gradle (app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.sms28.myapplication"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11", "-frtti", "-fexceptions"
abiFilters 'x86', 'x86_64','armeabi-v7a', 'arm64-v8a'
}
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':openCVLibrary340dev')
}
And I build it, but I got errors:
click and show error image
I'm trying to build ffmpeg static libraries and link them to an android project in order to implement a video player. Goal is to make a player capable of receiving video file from various sources similar to p2p file sharing networks. (target api is 21 level which is 1 level short from supposed official solution with MediaSource)
I managed to compile ffmpeg from this repo (all the code used as-is) but later i got stuck on a linking problem. Whenever I try to compile I get list of ffmpeg methods called in my code and a short eloquent message:
Linker command failed with exit code 1
I have no clue how to pass -v flag to the linker in android studio. Would be great if somebody hinted me that.
I use android studio, build with gradle and cmake.
There's my files:
build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (Module)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
productFlavors {
x86 {
ndk {
abiFilter "x86"
}
}
arm {
ndk {
abiFilters "armeabi-v7a"
}
}
armv7 {
ndk {
abiFilters "armeabi-v7a"
}
}
}
defaultConfig {
applicationId "com.example.ledo.ndkapplication"
minSdkVersion 22
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
arguments '-DANDROID_PLATFORM=android-16'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
compile 'com.writingminds:FFmpegAndroid:0.3.2'
testCompile 'junit:junit:4.12'
}
CMakeLists.txt
# 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 2.8)
# 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
src/main/cpp/NativePlayer.h
src/main/cpp/NativePlayer.cpp)
# 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 )
find_library(png-lib png)
# 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.
#avcodec
#avfilter
#avformat
#avutil
#swresample
#swscale
#${ANDROID_ABI}
message(${ANDROID_ABI})
set(FFMPEG_ROOT_DIR src/main/libs/ffmpeg/${ANDROID_ABI})
add_library(avcodec STATIC IMPORTED)
add_library(avformat STATIC IMPORTED)
add_library(avfilter STATIC IMPORTED)
add_library(avutil STATIC IMPORTED)
add_library(swresample STATIC IMPORTED)
add_library(swscale STATIC IMPORTED)
#SET_TARGET_PROPERTIES(avcodec PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavcodec.a)
#SET_TARGET_PROPERTIES(avfilter PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avfilter PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavfilter.a)
#SET_TARGET_PROPERTIES(avformat PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avformat PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavformat.a)
#SET_TARGET_PROPERTIES(avutil PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avutil PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavutil.a)
#SET_TARGET_PROPERTIES(swresample PROPERTIES LINKER_LANGUAGE C)
set_target_properties(swresample PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libswresample.a)
#SET_TARGET_PROPERTIES(swscale PROPERTIES LINKER_LANGUAGE C)
set_target_properties(swscale PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libswscale.a)
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/include )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib )
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib}
avcodec
avformat
#avfilter
#swresample
#swscale
#avutil
GLESv2)
I have .a files in following locations:
%PROJECT_DIR%/app/src/libs/ffmpeg/armeabi-v7a
%PROJECT_DIR%/app/src/libs/ffmpeg/armeabi-v7a-neon
%PROJECT_DIR%/app/src/libs/ffmpeg/x86
It doesn't look to me that linker misses files themselves. (I get different out put if I misplace them.)
The error 'Linker command failed with exit code 1' is usually followed by the more detailed error. To find more details, in Xcode click on the error under Buildtime and choose Reveal in log. This should give you extra hint. Without any specific error, it's not possible to know what's the problem.
I need to add a c project which can be compiled with gcc as follows
gcc -I/usr/include/epic5.1 -I/usr/include/i386-linux-gnu/epic5.1 -I./smproject/ -o code code.c ./smproject/smlib.so -lepic5.1
I have moved the code.c files content to my Android NDK .cpp file (src/main/cpp/native-lib.cpp) and also moved all files inside smproject directory to src/main/cpp/smproject/ directory
Here is my CMakeList.txt content
# 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.
include_directories( /usr/include/epic5.1 )
include_directories( /usr/include/i386-linux-gnu/epic5.1 )
include_directories( src/main/cpp )
set_target_properties( delorean PROPERTIES IMPORTED_LOCATION
src/main/cpp/smlib.so
)
add_library( smlib STATIC IMPORTED )
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
)
# 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, pre-built third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib}
smlib
)
I tried to follow Android NDK, CMake with other libraries but that didn't work for me it started throwing gradle error
tried following in build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "in.etpg.sampleapp"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-I/usr/include/epic5.1 -I/usr/include/i386-linux-gnu/epic5.1 -lepic5.1 -frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
Errors
Error:cannot find -lepic5.1
Error:error: linker command failed with exit code 1 (use -v to see
Warning:warning: -lepic5.1: 'linker' input unused
Error:A problem occurred configuring project ':app'.
> executing external native build for cmake /Users/laptop.user/AndroidStudioProjects/SampleApp/app/CMakeLists.txt
You simply need to add something to your module build.gradle, like this
ndk {
moduleName "code"
cFlags "-I/usr/include/epic5.1 -I/usr/include/i386-linux-gnu/epic5.1 -lepic5.1 -frtti -fexceptions"
ldLibs "log"
}
and place the source files in main/jni.
Perhaps, you need to change cFlags to cppFlags, but I recommend that you search for more information about this, the suggestion is based on the fact that you have -fnoexceptions flag, which is for c++.
You need of course libepic5.1.so binary to use it for compilation, if you can add it's source code it will work.