【问题标题】:needed by '../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so', missing and no known rule to make it'../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so'需要,缺少并且没有已知的规则来制作它
【发布时间】:2017-11-22 10:41:20
【问题描述】:

我想在我的项目中实现 AE 和 RSA。我下载了预构建的 openssl 并包含在我的项目中。在我的项目中包含 openssl 后,我收到了上面提到的错误。我在 SO 上搜索了一些提到在 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

【问题讨论】:

    标签: android android-ndk openssl java-native-interface


    【解决方案1】:

    我猜你得到了引用的错误,因为你没有jniLibs/x86_64/lib/libcrypto.a。尝试使用

    abiFilters "x86", "armeabi-v7a"
    

    【讨论】:

    • 请粘贴完整的错误日志,您在问题标题中输入的信息不够上下文
    • 非常好。您会看到错误消息表明文件 libcrypto.a../../../../jniLibs/armeabi-v7a/lib/libcrypto.a 不存在。所以试着给出这个文件的正确路径。
    • 谢谢你先生.. 现在检测到库。
    • @AlexCohn 我遇到了同样的问题。似乎 So 文件不可用。请检查以下错误是否相同。请指导我解决它。
    • 错误:'../../../../src/main/jniLibs/x86/libopencv_java3.so',需要'../../../.. /build/intermediates/cmake/release/obj/x86/libnative-lib.so',缺少并且没有已知的规则来制作它
    【解决方案2】:

    我在将 targetSDKversion 从 21 升级到 27 时发生了这个错误。作为一名 Android 程序员,我生命中这个可怕阶段的最后一次变化是这个错误:

    • 出了什么问题: 任务 ':myProject:externalNativeBuildDebug' 执行失败。 构建命令失败。 使用参数执行进程 C:\Users\myUser\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe 时出错 {--build D:\workspaces\android\myProject.externalNativeBuild\cmake\debug \armeabi-v7a --target myProject} 忍者:错误:'../../../../src/main/libs/armeabi-v7a/libcrypto.so',需要'../../../../build/intermediates /cmake/debug/obj/armeabi-v7a/libmyProject.so',缺少并且没有已知的规则来制作它

    我的应用程序使用自己的.so,它在他内部使用 libcrypto.so 的功能,因此 appers myproject.so

    将旧路径更改为新路径,为此,您需要转到 Android Studio 中的 External Build Files/CMakeLists.txt(如果您的 Android Studio 界面中没有应用,请转到您的文件系统并在您的项目中搜索它,并在实现此更改后编译)。

    如果不存在,添加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 )
    

    现在,构建项目并运行应用程序。

    事物相关

    • 不需要静态添加crypto(是libcrypto,但他的名字是crypto)。

    System.loadLibrary("crypto");

    相关信息

    希望对你有所帮助!

    【讨论】:

      猜你喜欢
      • 2019-07-18
      • 2022-12-15
      • 2023-01-31
      • 1970-01-01
      • 2018-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-25
      相关资源
      最近更新 更多