我想在我的项目中实现AEs和RSA。我下载了预构建的openssl并包含在我的项目中。在我的项目中包含openssl后,我收到了上面提到的错误。我搜索了一些提到的答案,包括CMake中的 set_target_properties (你可以查看我下面的cmake),但仍然没有用。
我的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 )
add_library(openssl SHARED IMPORTED)
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libcrypto.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.
include_directories(jni/include/)
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.
native-lib
${CMAKE_CURRENT_SOURCE_DIR}/jniLibs/${ANDROID_ABI}/lib/libcrypto.a
${CMAKE_CURRENT_SOURCE_DIR}/jniLibs/${ANDROID_ABI}/lib/libssl.a
# Links the target library to the log library
# included in the NDK.
${log-lib} )
和我的build.graddle在这里
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.manvish.prebuiltcrypto"
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
abiFilters "x86_64", "armeabi-v7a"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
帮我解决这个问题?
完整的错误日志在这里
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process /home/manvish/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/manvish/Gajanand/PrebuiltCrypto/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target native-lib}
ninja: error: '../../../../jniLibs/armeabi-v7a/lib/libcrypto.a', needed by '../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so', missing and no known rule to make it
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
答案 0 :(得分:1)
我猜你得到引用的错误,因为你没有jniLibs/x86_64/lib/libcrypto.a
。尝试使用
abiFilters "x86", "armeabi-v7a"
答案 1 :(得分:0)
当我将targetSDKversion从21升级到27时,发生了这个错误。作为Android程序员,我这个可怕的生活阶段的最后一个改变是这个错误:
- 出了什么问题: 任务':myProject:externalNativeBuildDebug'的执行失败。 生成命令失败。 使用参数{--build D:\ workspaces \ android \ myProject.externalNativeBuild \ cmake \ debug执行进程C:\ Users \ myUser \ AppData \ Local \ Android \ Sdk \ cmake \ 3.6.4111459 \ bin \ cmake.exe时出错\ armeabi-v7a --target myProject} 忍者:错误:'../../../../build/intermediates需要'../../../../src/main/libs/armeabi-v7a/libcrypto.so' /cmake/debug/obj/armeabi-v7a/libmyProject.so',缺少并且没有已知的规则可以实现
我的应用程序使用一个自己的.so,该文件在他内部使用libcrypto.so的函数,因此appers myproject.so
更改新路径的旧路径,为此,您需要转到Android Studio中的External Build Files / CMakeLists.txt(如果您不喜欢Android Studio界面,请转到FileSystem并在项目内对其进行搜索,并在实现此更改后进行编译)。
如果不存在,请添加set_target_properties:
set_target_properties( # Specifies the target library.
crypto-lib
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libcrypto.so )
收件人:
set_target_properties( # Specifies the target library.
crypto-lib
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libcrypto.so )
现在,构建项目并运行应用程序。
相关事物:
System.loadLibrary(“ crypto”);
相关信息:
希望有帮助!