在Android Studio Project中编译外部C ++库时出错

时间:2018-06-18 16:28:24

标签: java android c++ cmake

我正在尝试将此C++ GitHub repo编译到我的android studio项目中。我将它作为外部C ++库添加到我的项目中,并且可以编译并运行CMake构建;但是,如果我尝试将Java绑定依赖项"-DDNP3_JAVA=ON"作为参数添加到CMake中,则在尝试运行make projectbuild APK(s)时会出现编译错误。

这是我的build.gradle

android {
    defaultConfig {
        . . . 
        externalNativeBuild {
            cmake {
                arguments "-DDNP3_JAVA=ON" // This is the argument that casues the build to fail
            }
        }
    }
    . . . 
    externalNativeBuild {
        cmake {
            path '../../../../../dnp3/CMakeLists.txt'
        }
    }
}

dependencies {
    . . .
}

这是构建失败时得到的输出。我不确定为什么它会在控制台中重复两次。

Build command failed.

Error while executing process E:\Android\SDK\cmake\3.6.4111459\bin\cmake.exe with arguments {-HE:\dnp3 -BE:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\.externalNativeBuild\cmake\debug\armeabi-v7a -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-24 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\build\intermediates\cmake\debug\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Debug -DANDROID_NDK=E:\Android\SDK\ndk-bundle -DCMAKE_TOOLCHAIN_FILE=E:\Android\SDK\ndk-bundle\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=E:\Android\SDK\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja -DDNP3_JAVA=ON}

-- Check for working C compiler: E:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe

-- Check for working C compiler: E:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- works

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Detecting C compile features

-- Detecting C compile features - done

-- Check for working CXX compiler: E:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe

-- Check for working CXX compiler: E:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -- works

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

-- Detecting CXX compile features

-- Detecting CXX compile features - done

CMake build is: Debug

-- Looking for pthread.h

-- Looking for pthread.h - found

-- Looking for pthread_create

-- Looking for pthread_create - found

-- Found Threads: TRUE  

-- Found Java: C:/Program Files/Java/jre-10.0.1/bin/java.exe (found version "10.0.1") found components:  Development 

 (find_package) 
Open File

-- Configuring incomplete, errors occurred!

See also "E:/Users/xxxxx/AndroidStudioProjects/MyApplication/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log".

Build command failed.

Error while executing process E:\Android\SDK\cmake\3.6.4111459\bin\cmake.exe with arguments {-HE:\dnp3 -BE:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\.externalNativeBuild\cmake\release\armeabi-v7a -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-24 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\build\intermediates\cmake\release\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Release -DANDROID_NDK=E:\Android\SDK\ndk-bundle -DCMAKE_TOOLCHAIN_FILE=E:\Android\SDK\ndk-bundle\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=E:\Android\SDK\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja -DDNP3_JAVA=ON}

-- Check for working C compiler: E:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe

-- Check for working C compiler: E:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- works

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Detecting C compile features

-- Detecting C compile features - done

-- Check for working CXX compiler: E:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe

-- Check for working CXX compiler: E:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -- works

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

-- Detecting CXX compile features

-- Detecting CXX compile features - done

CMake build is: Release

-- Looking for pthread.h

-- Looking for pthread.h - found

-- Looking for pthread_create

-- Looking for pthread_create - found

-- Found Threads: TRUE  

-- Found Java: C:/Program Files/Java/jre-10.0.1/bin/java.exe (found version "10.0.1") found components:  Development 

 (find_package) 
Open File

-- Configuring incomplete, errors occurred!

See also "E:/Users/xxxxx/AndroidStudioProjects/MyApplication/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeOutput.log".

Open File链接到Android的SDK文件夹中FindPackageHandleStandardArgs.cmake的第147行。

macro(_FPHSA_FAILURE_MESSAGE _msg)
    if (${_NAME}_FIND_REQUIRED)    // Throws error to this line
        message(FATAL_ERROR "${_msg}")
    else ()
        if (NOT ${_NAME}_FIND_QUIETLY)
            message(STATUS "${_msg}")
        endif ()
     endif ()
endmacro()

以下是CMakeOutput.log

我已经尝试将我的JAVAHOME系统变量设置为以下4个文件夹,但我得到了相同的错误。

  • jdk1.8.0_121
  • JDK-10.0.1
  • jre1.8.0_121
  • JRE-10.0.1

我也尝试在虚拟64位Ubuntu系统上运行它,但得到相同的结果

0 个答案:

没有答案