在建立项目时,获取源和目标必须是不同的错误。

问题描述 投票:0回答:1

我在建立项目时得到这个错误。试图在android-studio中添加一个新的库。有没有人有一个想法,基本上我试图在这里创建一个新的库。

尝试过的选项。

  1. 手动删除构建

  2. 訪問日期 cacherestart

  3. Gradle清理构建缓存

  4. 建设和gt;清洁项目

    但构建失败。

    来源C:/Users/abc/AndroidStudioProjects/Events/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so和目的地C:/Users/abc/AndroidStudioProjects/Events/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so一定是不同的。

我也在使用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).
             native-lib.cpp
        )

add_library (
        testLib
        SHARED
        TestClassesManager.cpp
)
# 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.

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

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib}

        )

target_link_libraries(
        testLib

        native-lib
)

如果我替换掉

target_link_libraries(
        testLib

        native-lib
)

target_link_libraries(
        testLib
    ${log-lib}

)

但我想链接两个库。但却出现了上述错误。请帮助我。

android-studio cmake android-ndk
1个回答
2
投票

这是一个 诡异 BUG,不过还是要感谢你简明扼要的重现项目。其实前几天就有人跟我提过这个问题,但我一直没能重现这个故障。

我还在调查 此处但目前看来,一个变通的办法是运行clean,然后刷新链接的c++项目,再进行构建。如果你需要使用 "刷新链接的c++项目 "按钮,同样,运行clean。第一.

一个修正已经被挑选出来,并将在4.0.1中。


0
投票

我也遇到了同样的问题。问题似乎出在SHARED属性上,我猜测所有的共享库都被认为是JNI库的 "最终 "库。我猜测所有的共享库都被认为是JNI库的 "最终 "库。

开发中的一个变通方法是将依赖的库标记为STATIC。

此外,做一个新的构建(删除.cxx和所有构建目录)似乎没有这个问题,但之后的每次重建。


-1
投票

我的理解和感觉是你的插件版本不适合你当前的SDK版本,或者是不可压缩的。

试着降低插件的版本或应用较新的版本可能也有帮助。确保使用最新的Android Studion,再试着检查一下。如果有进一步的错误日志,请粘贴在这里。

© www.soinside.com 2019 - 2024. All rights reserved.