[英]Problem in android studio prebuilt library
我正在使用带有 android studio 的预构建 C++ 库,该库没有被工作室采用。 我在相同版本的操作系统和工作室中使用 ndk-build 但在不同的机器上构建了这个 so 文件。 在新机器上复制 so 文件,然后 Studio 会为 lib 中的新 C++ 函数生成未定义的引用错误。 使用 nm 命令检查,符号存在于 so 文件中。 它从某处挑选旧库,旧函数不会产生此类错误。 尝试:
但没有成功。
我把 .so 文件放在myproject/app/libs/x86/libalgos.so和myproject/app/jni/libs/x86/libalgos.so
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 [位置: 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)
Application.mk [位置: myproject/app/jni ]
APP_CFLAGS += -Wno-error=format-security
APP_ABI := x86
APP_MODULES := algos
APP_OPTIM := debug
构建.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"
}
此问题是由于项目的不同文件夹中存在旧的 so 文件。 解决者:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.