android “../../../../build/intermediates/cmake/debug/obj/armeabi-v7 a/libnative-lib.so”需要,缺少并且没有已知的规则来创建它

ktecyv1j  于 2023-03-11  发布在  Android
关注(0)|答案(3)|浏览(190)

我想在我的项目中实现AE和RSA。我下载了预先构建的openssl并包含在我的项目中。在我的项目中包含openssl后,我得到如上所述的错误。我搜索了SO一些答案,提到包括set_target_properties在CMake中(U可以检查我的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} )

还有我的身材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
t3psigkw

t3psigkw1#

我可以猜测,您得到引用的错误是因为您没有jniLibs/x86_64/lib/libcrypto.a

abiFilters "x86", "armeabi-v7a"
c3frrgcw

c3frrgcw2#

这个错误发生在我身上,当升级targetSDK版本从21到27.最后的变化,这个可怕的阶段,我的生活作为一个Android程序员是这个错误:

  • 出了什么问题:任务“:myProject:externalNativeBuildDebug”的执行失败。生成命令失败。使用参数{--build D:\workspace\android\myProject.externalNativeBuild\cmake\debug\armeabi-v7 a--target myProject}执行进程C时出错:错误:“../../../../../src/main/libs/armeabi-v7 a/libcrypto.so”需要的../../../../build/intermediates/cmake/debug/obj/armeabi-v7 a/libmyProject.so“,缺少并且没有用于创建它的已知规则

我的应用程序使用了一个自己的.so,它使用了www.example.com的函数libcrypto.so,因此应用了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 )

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

相关事项

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

系统.加载库(“加密”);

相关信息

希望这能有所帮助!

5us2dqdw

5us2dqdw3#

我的解决方案是:如果项目的父文件夹有空格或文件夹名称中不支持的字符,这一切都是因为这个。
示例:C:/users/用户/桌面/Android Studio项目/应用程序文件夹更改:Android Studio项目=〉Android Studio项目
对我很有效

相关问题