2017-08-17 3 views
1

Ich versuche, this project zu erweitern, aber es wurde mit ANT gebaut und in diesen Tagen verwenden wir Android Studio und Gradle in der Praxis. Ich möchte es in Android Studio für weitere Implementierungen verschieben. Also hier ist meine Projektstruktur ...Fehler: org.gradle.internal.UncheckedException: Build-Befehl fehlgeschlagen

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) 

Aber Fehler bekommen, während Projekt bauen, einen Blick auf diese ...

Nachricht anzeigen

enter image description here

Gradle Console

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. 

Bitte helfen Sie mir, dieses Projekt einzurichten!

+0

Ihre Anwendung hat keine OpenCV als Abhängigkeit lib in CMakeLists.txt. Müssen Sie es in target_link_libraries (...) mit dem richtigen Pfad für jedes von Ihnen erstellte ABI hinzufügen. – Gerry

+0

Können Sie bitte CMakeLists.txt hier als Referenz neu schreiben? – Khan

+0

Ihr cmake-Skript hat kein Äquivalent von: "include $ (OPENCVSDK)/native/jni/OpenCV.mk ", CMake Build unterstützt nicht die gemischten Systeme (CMake und ndk-build im selben Projekt). Also die Wahl ist, OpenCV.mk in CMake Build-Skripte zu konvertieren oder Android Studio" ndkbuild "Plugin zu verwenden könnte beziehen sich auf: https://github.com/googlesamples/android-ndk, Zweig-Master-ndkbuild [Master Zweig ist nur für CMake Build] – Gerry

Antwort

0

Nach einer Menge Suche habe ich this Projekt gefunden. Vielen Dank an Adrien Lescourt. Dieses Demo-Projekt beschreibt, wie wir OpenCV mit Android Studio & Gradle verwenden können. Problem war mit jniLibs Verzeichnis und CMakeLists.txt Datei. Hier ist die richtige Version ...

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}) 

Und endlich habe ich jniLibs Ordner App und kopiert hinzugefügt Alle .so Dateien in diesem Ordner gespeichert in OpenCV-2.4.10-Android-SDK/SDK/native/libs.

enter image description here

Ich hoffe, dass diese Lösung die Menschen zur Einrichtung OpenCV mit gradle helfen. Bitte kommentieren Sie, wenn weitere Informationen benötigt werden.

Danke

Verwandte Themen