[英]Problem in android studio prebuilt library
I am using a prebuilt c++ library with android studio which is not being picked up by studio.我正在使用带有 android studio 的预构建 C++ 库,该库没有被工作室采用。 I built this so file using ndk-build in same version of OS and studio but on different machine.
我在相同版本的操作系统和工作室中使用 ndk-build 但在不同的机器上构建了这个 so 文件。 Copied so files on new machine then Studio is generating undefined reference errors for new c++ functions in lib.
在新机器上复制 so 文件,然后 Studio 会为 lib 中的新 C++ 函数生成未定义的引用错误。 Checking with nm command, symbol is present in so file.
使用 nm 命令检查,符号存在于 so 文件中。 It is picking old lib from somewhere and old functions are producing no such errors.
它从某处挑选旧库,旧函数不会产生此类错误。 Tried:
尝试:
But no success.但没有成功。
I put .so file in myproject/app/libs/x86/libalgos.so and also in myproject/app/jni/libs/x86/libalgos.so我把 .so 文件放在myproject/app/libs/x86/libalgos.so和myproject/app/jni/libs/x86/libalgos.so
cmakelists: cmakelists:
.
.
.
add_library(algos SHARED IMPORTED)
set_target_properties(algos PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../libs/x86/libalgos.so)
target_include_directories(native-lib PRIVATE ${CMAKE_SOURCE_DIR}/ )
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
algos ${log-lib})
Android.mk [Location: myproject/app/jni ] Android.mk [位置: myproject/app/jni ]
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := algos
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libalgos.so
LOCAL_EXPORT_C_INCLUDES := include
include $(PREBUILT_SHARED_LIBRARY)
Applicattion.mk [Location: myproject/app/jni ] Application.mk [位置: myproject/app/jni ]
APP_CFLAGS += -Wno-error=format-security
APP_ABI := x86
APP_MODULES := algos
APP_OPTIM := debug
build.gradle构建.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.cryptotrading"
//minSdkVersion 15
minSdkVersion 26 //---changed for rhino implementation (invoke customs)
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
ndk {
abiFilters 'x86'
}
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
sourceSets {
main {
jniLibs.srcDirs = ['jni/', 'libs/', 'app/libs/', '${CMAKE_SOURCE_DIR}/../../..//libs/']
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.preference:preference:1.1.0-alpha05'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.android.material:material:1.0.0'
//implementation files('./libs/js.jar')
implementation 'org.mozilla:rhino:1.7.12'
//implementation 'org.apache.commons:commons-text:1.7'
//compile group: 'commons-codec', name: 'commons-codec', version: '1.7'
//compile 'com.squareup.okhttp3:okhttp:3.4.1'
implementation("com.squareup.okhttp3:okhttp:4.4.0")
implementation 'com.googlecode.json-simple:json-simple:1.1'
//compile 'com.alibaba.fastjson:1.2.47'
def room_version = "2.2.4"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
// optional - RxJava support for Room
implementation "androidx.room:room-rxjava2:$room_version"
implementation 'androidx.annotation:annotation:1.1.0'
compile "com.androidplot:androidplot-core:1.5.7"
}
This issue was due to presence of old so files in different folders of project.此问题是由于项目的不同文件夹中存在旧的 so 文件。 Solved by:
解决者:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.