gpt4 book ai didi

android - 错误 :org. gradle.internal.UncheckedException: 构建命令失败

转载 作者:太空宇宙 更新时间:2023-11-03 22:46:48 25 4
gpt4 key购买 nike

我正在尝试扩展 this project ,但它是使用 ANT 构建的,这些天我们在实践中使用 Android Studio 和 Gradle。我想将它移动到 Android Studio 上以进一步实现。所以这是我的项目结构...

enter image description here

app/build.gradle

apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "tum.andrive"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi", "armeabi-v7a"
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/cpp']
}
}
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile project(':opencv')
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)
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 )

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 )

SET(OpenCV_DIR $ENV{OPENCVSDK}/native/jni)

message(STATUS "opencv found: ${OpenCV_LIBS}")

include_directories( ${OpenCV_DIR}/include/)

target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

#OpenCv
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on

include $(OPENCVSDK)/native/jni/OpenCV.mk

LOCAL_MODULE := AndriveNative
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_LDLIBS += -llog -ldl

include $(BUILD_SHARED_LIBRARY)

但是在构建项目时出错,看看这个...

消息 View

enter image description here

Gradle 控制台

D:\Android\workspace\Local\Andrive\app\.externalNativeBuild\cmake\debug\armeabi
--target
native-lib
jvmArgs :

Starting process 'command 'Z:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe''. Working directory: D:\Android\workspace\Local\Andrive\app Command: Z:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe --build D:\Android\workspace\Local\Andrive\app\.externalNativeBuild\cmake\debug\armeabi --target native-lib
Successfully started process 'command 'Z:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe''
[1/1] Linking CXX shared library ..\..\..\..\build\intermediat
es\cmake\debug\obj\armeabi\libnative-lib.so
FAILED: cmd.exe /C "cd . && Z:\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv5te-none-linux-androideabi --gcc-toolchain=Z:/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=Z:/Android/sdk/ndk-bundle/sysroot -fPIC -isystem Z:/Android/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=14 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -frtti -fexceptions -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot Z:/Android/sdk/ndk-bundle/platforms/android-14/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -lm "Z:/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/libgnustl_static.a" "-latomic" && cd ."
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:27: error: undefined reference to 'DetectionBasedTracker::Parameters::Parameters()'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:30: error: undefined reference to 'DetectionBasedTracker::DetectionBasedTracker(std::string const&, DetectionBasedTracker::Parameters const&)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeCreateObject+0xe4): error: undefined reference to 'typeinfo for cv::Exception'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:54: error: undefined reference to 'DetectionBasedTracker::getParameters()'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:56: error: undefined reference to 'DetectionBasedTracker::setParameters(DetectionBasedTracker::Parameters const&)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeSetDetectionSize+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeDestroyObject+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeStart+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:188: error: undefined reference to 'cv::_OutputArray::_OutputArray(cv::Mat&)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:188: error: undefined reference to 'cv::Mat::copyTo(cv::_OutputArray const&) const'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:298: error: undefined reference to 'cv::Mat::copySize(cv::Mat const&)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:27
8: error: undefined reference to 'cv::fastFree(void*)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:367: error: undefined reference to 'cv::Mat::deallocate()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
:app:externalNativeBuildDebug FAILED
:app:externalNativeBuildDebug (Thread[Daemon worker Thread 2,5,main]) completed. Took 8.011 secs.
:app:buildInfoGeneratorDebug (Thread[Daemon worker Thread 2,5,main]) started.
:app:buildInfoGeneratorDebug
Putting task artifact state for task ':app:buildInfoGeneratorDebug' into context took 0.0 secs.
Executing task ':app:buildInfoGeneratorDebug' (up-to-date check took 0.0 secs) due to:
Task has not declared any outputs.
:app:buildInfoGeneratorDebug (Thread[Daemon worker Thread 2,5,main]) completed. Took 0.018 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process Z:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build D:\Android\workspace\Local\Andrive\app\.externalNativeBuild\cmake\debug\armeabi --target native-lib}
[1/1] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi\libnative-lib.so
FAILED: cmd.exe /C "cd . && Z:\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv5te-none-linux-androideabi --gcc-toolchain=Z:/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=Z:/Android/sdk/ndk-bundle/sysroot -fPIC -isystem Z:/Android/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=14 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -frtti -fexceptions -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot Z:/Android/sdk/ndk-bundle/platforms/android-14/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -lm "Z:/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/libgnustl_static.a" "-latomic" && cd ."
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:27: error: undefined reference to 'DetectionBasedTracker::Parameters::Parameters()'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:30: error: undefined reference to 'DetectionBasedTracker::DetectionBasedTracker(std::string const&, DetectionBasedTracker::Parameters const&)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeCreateObject+0xe4): error: undefined reference to 'typeinfo for cv::Exception'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:54: error: undefined reference to 'DetectionBasedTracker::getParameters()'
D:\Android\workspace\Local\Andrive\app\src\main\cpp/native-lib.cpp:56: error: undefined reference to 'DetectionBasedTracker::setParameters(DetectionBasedTracker::Parameters const&)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeSetDetectionSize+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeDestroyObject+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o(.ARM.extab.text.Java_tum_andrive_DetectionBasedTracker_nativeStart+0xa4): error: undefined reference to 'typeinfo for cv::Exception'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:188: error: undefined reference to 'cv::_OutputArray::_OutputArray(cv::Mat&)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:188: error: undefined reference to 'cv::Mat::copyTo(cv::_OutputArray const&) const'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:298: error: undefined reference to 'cv::Mat::copySize(cv::Mat const&)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:278: error: undefined reference to 'cv::fastFree(void*)'
D:/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include\opencv2/core/mat.hpp:367: error: undefined reference to 'cv::Mat::deallocate()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

任何人请帮助我设置这个项目!

最佳答案

经过大量搜索,我找到了 this项目。非常感谢Adrien Lescourt .此演示项目描述了我们如何将 OpenCV 与 Android Studio 和 Gradle 结合使用。问题出在 jniLibs 目录和 CMakeLists.txt 文件上。这是正确的版本...

app/build.gradle

apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "tum.andrive"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a"
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile project(':opencv')
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)

# OpenCV stuff
include_directories(D:\\Android\\OpenCV-2.4.10-android-sdk\\sdk\\native\\jni\\include)
add_library( lib_opencv SHARED IMPORTED )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java.so)

add_library( native-lib
SHARED
src/main/cpp/native-lib.cpp )

find_library( log-lib
log )

target_link_libraries( native-lib
lib_opencv
${log-lib} )

最后,我将 jniLibs 文件夹添加到应用程序并将所有 .so 文件复制到存储在 OpenCV-2.4.10-android-sdk/sdk/native/libs 中的该文件夹中.

enter image description here

我希望这个解决方案能帮助人们使用 gradle 设置 OpenCV。如果需要任何其他信息,请发表评论。

谢谢

关于android - 错误 :org. gradle.internal.UncheckedException: 构建命令失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45728032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com