Forums - FastCV in Android Studio

15 posts / 0 new
Last post
FastCV in Android Studio
noexcuse0414
Join Date: 20 Jul 16
Posts: 4
Posted: Thu, 2016-08-04 11:33

Did anyone successfully build FastCV examples with Android Studio? I am having trouble with the compile.

 I already put fastcv.h into ~/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm64/usr/include and libfastcv.a into ~/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm64/usr/lib. But still get the error below when I try to compile the sample code.

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:prepareDebugUnitTestDependencies, :app:mockableAndroidJar, :app:generateDebugAndroidTestSources, :app:assembleDebug]
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:mockableAndroidJar UP-TO-DATE
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl
:app:processDebugAndroidTestManifest
:app:compileDebugAndroidTestRenderscript
:app:generateDebugAndroidTestBuildConfig
:app:mergeDebugAndroidTestShaders
:app:compileDebugAndroidTestShaders
:app:generateDebugAndroidTestAssets
:app:mergeDebugAndroidTestAssets
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources
:app:mergeDebugAndroidTestResources
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:app:compileDebugNdk
/Users/Airmada_Ian/AndroidStudioProjects/loadjpeg/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/objs-debug/app//Users/Airmada_Ian/AndroidStudioProjects/loadjpeg/app/src/main/jni/loadjpeg.o: In function `Java_com_qualcomm_loadjpeg_LoadJpeg_convertToLum':
/Users/Airmada_Ian/AndroidStudioProjects/loadjpeg/app/src/main/jni/loadjpeg.cpp
Error:(133) undefined reference to `fcvMemAlloc'
Error:(139) undefined reference to `fcvMemFree'
Error:error: ld returned 1 exit status
make: *** [/Users/Airmada_Ian/AndroidStudioProjects/loadjpeg/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/libapp.so] Error 1
Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/Airmada_Ian/Library/Android/sdk/ndk-bundle/ndk-build'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 1.573 secs
Information:4 errors
Information:0 warnings
Information:See complete output in console
  • Up1
  • Down0
Himanshu Aggarwal
Join Date: 8 Aug 16
Posts: 3
Posted: Mon, 2016-08-08 06:16

Hi,

For the compilation are you using eclipse+android studio or Gradle+android studio?

  • Up0
  • Down0
Himanshu Aggarwal
Join Date: 8 Aug 16
Posts: 3
Posted: Mon, 2016-08-08 06:16

Hi,

For the compilation are you using eclipse+android studio or Gradle+android studio?

  • Up0
  • Down0
noexcuse0414
Join Date: 20 Jul 16
Posts: 4
Posted: Mon, 2016-08-08 10:28

Hi Himanshu,

I am using Gradle+android studio.

Thanks

  • Up0
  • Down0
noexcuse0414
Join Date: 20 Jul 16
Posts: 4
Posted: Mon, 2016-08-08 10:29

Hi Himanshu,

I am using Gradle+android studio.

Thanks

  • Up0
  • Down0
mvpiaia
Join Date: 11 Aug 16
Posts: 1
Posted: Thu, 2016-08-11 10:33

Fellows,

at the end, was it possible to use FastCV with AndroidStudio ?

thks in advance
[]s
Piaia

  • Up0
  • Down0
noexcuse0414
Join Date: 20 Jul 16
Posts: 4
Posted: Thu, 2016-08-11 17:46

no I could not get it to work. I put it aside for now.

 

 

  • Up0
  • Down0
frisacher
Join Date: 7 Jan 14
Posts: 3
Posted: Thu, 2016-08-25 08:35

I am too trying to run the fastCV examples in Android Studio+gradle.

This is the relevant NDK build.gradle I use:

        ndk {
            moduleName "libfastcvsample"
            def OPENGLES_DEF  = "-DUSE_OPENGL_ES_2_0"
            cFlags "-I\$(TARGET_OUT_HEADERS)/fastcv -I/home/frisacher/dev/android/ndk/platforms/android-21/arch-arm64/usr/include -L/home/frisacher/dev/android/ndk/platforms/android-21/arch-arm64/usr/lib \$(OPENGLES_DEF) -Wl,--no-fix-cortex-a8 -Wno-write-strings"
            ldLibs "log", "GLESv2"
            stl "fastcv"
            abiFilter "armeabi"
        }

I think that I was able to solve the static library dependency adding stl "fastcv" but build still failed

/home/frisacher/dev/android/ndk/build/core/add-application.mk
Error:(287) *** Android NDK: Aborting    .  Stop.
Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/home/frisacher/dev/android/ndk/ndk-build'' finished with non-zero exit value 2
Information:BUILD FAILED

Android Studio does not import correctly the JNI part and most of the changes need to be ported from the jni/Android.mk to build.gradle

It would be good to have a fastCV example running on Android Studio as this is the only official tool chain supported by Google for a while now.

  • Up0
  • Down0
frisacher
Join Date: 7 Jan 14
Posts: 3
Posted: Fri, 2016-08-26 05:55

I was able to compile the fastCV demo and run it on my Android device. The app build.gradle file is below.

The key point is to disable the automatic call to ndk-build using "jni.srcDirs = []"

Some tweaks still need to be done in the Android.mk file(s) to point to your header and library file of the fastCV SDK and to get rid of some old flags not supported anymore by the latest NDK (e.g. -Wl,--no-fix-cortex-a8)

 

import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.qualcomm.fastcorner"
        minSdkVersion 22
        targetSdkVersion 23

       ndk {
            moduleName "libfastcvsample"
            abiFilter "armeabi"
        }
    }
    sourceSets.main {
        jni.srcDirs = [] //disable automatic ndk-build call
        jniLibs.srcDir 'src/main/libs'
    }
    // call regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        workingDir file('src/main')
        commandLine getNdkBuildCmd(), 'APP_PLATFORM=android-23'
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }

    task cleanNative(type: Exec) {
        workingDir file('src/main')
        commandLine getNdkBuildCmd(), 'clean'
    }

    clean.dependsOn cleanNative

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    dependencies {
        compile fileTree( dir: 'libs')
    }
}
def getNdkDir() {
    if (System.env.ANDROID_NDK_ROOT != null)
        return System.env.ANDROID_NDK_ROOT

    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkdir = properties.getProperty('ndk.dir', null)
    if (ndkdir == null)
        throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")

    return ndkdir
}

def getNdkBuildCmd() {
    def ndkbuild = getNdkDir() + "/ndk-build"
    if (Os.isFamily(Os.FAMILY_WINDOWS))
        ndkbuild += ".cmd"

    return ndkbuild
}

  • Up0
  • Down0
gvigelet
Join Date: 30 Aug 16
Posts: 1
Posted: Sat, 2016-09-24 05:29

Hi All,

Steps that I took for successfully porting FastCV example to Android Studion

  1. I was looking to play with FastCV and ported the fastcorners example to Android Studio, you must add the headers and library from the SDK to your NDK build as mentioned previously in this post.  
  2. Import the eclipse project into Android Studio.  
  3. Right-click on the module you would like to link to your native library, such as the app module, and select Link C++ Project with Gradle from the menu. Select the NDK_BUILD and point to the Android.mk file.  The Android.mk file must be updated mine looks like this:
  4. Update Android.mk
  5. LOCAL_PATH:= $(call my-dir)
    
    include $(CLEAR_VARS)
    LOCAL_PRELINK_MODULE:= false
    
    # This variable determines the OpenGL ES API version to use:
    # If set to true, OpenGL ES 1.1 is used, otherwise OpenGL ES 2.0.
    
    USE_OPENGL_ES_1_1 := false
    
    # Set OpenGL ES version-specific settings.
    
    ifeq ($(USE_OPENGL_ES_1_1), true)
        OPENGLES_LIB  := -lGLESv1_CM
        OPENGLES_DEF  := -DUSE_OPENGL_ES_1_1
    else
        OPENGLES_LIB  := -lGLESv2
        OPENGLES_DEF  := -DUSE_OPENGL_ES_2_0
    endif
    
    # An optional set of compiler flags that will be passed when building
    # C ***AND*** C++ source files.
    #
    # NOTE: flag "-Wno-write-strings" removes warning about deprecated conversion
    #       from string constant to 'char*'
    
    LOCAL_CFLAGS := -Wno-write-strings $(OPENGLES_DEF)
    
    # The list of additional linker flags to be used when building your
    # module. This is useful to pass the name of specific system libraries
    # with the "-l" prefix.
    
    LOCAL_LDLIBS := \
         -llog $(OPENGLES_LIB) -lfastcv
    
    
    LOCAL_MODULE    := libfastcvsample
    LOCAL_CFLAGS    := -Werror
    LOCAL_SRC_FILES := \
        About.cpp \
        FastCVSample.cpp \
        FPSCounter.cpp \
        CameraRendererRGB565GL2.cpp \
        CameraUtil.cpp \
        FastCVSampleRenderer.cpp
    
    LOCAL_STATIC_LIBRARIES := libfastcv
    LOCAL_SHARED_LIBRARIES := liblog libGLESv2
    LOCAL_C_INCLUDES += $(TARGET_OUT_HEADERS)/fastcv
    
    
    LOCAL_MODULE_OWNER := qcom
    LOCAL_PROPRIETARY_MODULE := true
    
    include $(BUILD_SHARED_LIBRARY)
    
    
    include $(CLEAR_VARS)
    
    LOCAL_STATIC_JAVA_LIBRARIES :=
    LOCAL_JNI_SHARED_LIBRARIES := libfastcvsample
    LOCAL_SRC_FILES := $(call all-subdir-java-files)
    LOCAL_PACKAGE_NAME := FastCVSample
    
    include $(BUILD_PACKAGE)
    
    
  6. Add Application.mk file with the following contents  
    APP_ABI := armeabi, arm64-v8a 
  7. I also changed my permission block in AndroidManifest.xml 
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-feature android:name="android.hardware.camera" />
        <uses-feature android:name="android.hardware.camera.autofocus" />
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  8. Sync and Build Application
  9. Note for Android OS >= 6 I had to add checkSelfPermission to the splash screen to prompt user for camera permission or your application will not be able to connect to the camera. 
            if (ContextCompat.checkSelfPermission(this,
                    Manifest.permission.CAMERA)
                    != PackageManager.PERMISSION_GRANTED) {
    
                requestCameraPermission();
    
            }else{
    
                Log.i(TAG,
                        "CAMERA permission has already been granted.");
            }
    
            if (ContextCompat.checkSelfPermission(this,
                    Manifest.permission.RECORD_AUDIO)
                    != PackageManager.PERMISSION_GRANTED) {
    
                requestAudioPermission();
    
            }else{
    
                Log.i(TAG,
                        "RECORD_AUDIO permission has already been granted.");
            }

 

Hope this helps those trying to get this to work in Android Studio (I couldn't find much out there on it)

- George

  • Up1
  • Down0
drampelt
Join Date: 1 Dec 16
Posts: 2
Posted: Thu, 2016-12-01 11:37

I followed George's steps but I'm still having trouble getting it to work. Where are the fastcv.h and the two fastcv.a files supposed to be placed?

  • Up0
  • Down0
drampelt
Join Date: 1 Dec 16
Posts: 2
Posted: Thu, 2016-12-01 11:49

I've figured it out now.

I added fastcv.h to src/main/jni/fastcv/fastcv.h and put the 2 libfastcv.a files in src/main/libs/armeabi and src/main/libs/arm64-v8a.

Then I added the following to the ndk section of build.gradle file

abiFilters 'armeabi', 'arm64-v8a'

Finally, I added this after the first line of the android.mk file:

include $(CLEAR_VARS)
LOCAL_MODULE    := libfastcv
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/libfastcv.a

include $(PREBUILT_STATIC_LIBRARY)
  • Up0
  • Down0
usmanstpk
Join Date: 15 Jul 17
Posts: 1
Posted: Sat, 2017-07-15 03:48

I was also not able to use it. Needs to be debugged. 

https://droidfirmware.com

  • Up0
  • Down0
akshata.powar
Join Date: 28 Jan 18
Posts: 2
Posted: Wed, 2018-02-07 01:42

I am having trouble with compilation of  FastCV example with android studio.Im getting  below error


Build command failed.
Error while executing process /home/usr/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {-H/home/usr/Samplefast/app/src/main/jniLibs -B/home/usr/Samplefast/app/.externalNativeBuild/cmake/debug/armeabi-v7a -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-19 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/usr/Samplefast/app/build/intermediates/cmake/debug/obj/armeabi-v7a -DCMAKE_BUILD_TYPE=Debug -DANDROID_NDK=/home/usr/Android/Sdk/ndk-bundle -DCMAKE_TOOLCHAIN_FILE=/home/usr/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=/home/usr/Android/Sdk/cmake/3.6.4111459/bin/ninja -GAndroid Gradle - Ninja}
-- Check for working C compiler: /home/usr/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /home/usr/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- 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: /home/usr/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-- Check for working CXX compiler: /home/usr/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error at CMakeLists.txt:13 (add_library):
Corner.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: About.cpp
-- Generating done
-- Build files have been written to: /home/usr/Samplefast/app/.externalNativeBuild/cmake/debug/armeabi-v7a
Build command failed.
Error while executing process /home/usr/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {-H/home/usr/Samplefast/app/src/main/jniLibs -B/home/usr/Samplefast/app/.externalNativeBuild/cmake/release/armeabi-v7a -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-19 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/usr/Samplefast/app/build/intermediates/cmake/release/obj/armeabi-v7a -DCMAKE_BUILD_TYPE=Release -DANDROID_NDK=/home/usr/Android/Sdk/ndk-bundle -DCMAKE_TOOLCHAIN_FILE=/home/usr/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=/home/usr/Android/Sdk/cmake/3.6.4111459/bin/ninja -GAndroid Gradle - Ninja}
-- Check for working C compiler: /home/usr/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /home/usr/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- 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: /home/usr/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-- Check for working CXX compiler: /home/usr/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error at CMakeLists.txt:13 (add_library):
Corner.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: About.cpp
-- Generating done
-- Build files have been written to: /home/usr/Samplefast/app/.externalNativeBuild/cmake/release/armeabi-v7a

 

 

 

  • Up0
  • Down0
akshata.powar
Join Date: 28 Jan 18
Posts: 2
Posted: Thu, 2018-02-08 00:52

Hello,

I am getting below error during compilation of  fastcv example with android studio.Please can anyone help me out.

Error:Execution failed for task ':app:ndkBuild'.
> Process 'command '/home/akshata/Android/Sdk/ndk-bundle/ndk-build'' finished with non-zero exit value 2

Thanks

 

 

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.