Android Studio with opencv for android ndk, opencv header files not found

后端 未结 1 1039
北荒
北荒 2021-01-06 14:41

I\'m getting to Android Studio for Android OpenCV developing, but when I compile the project which was ok in eclipse, I got this error:

D:\\software\\

1条回答
  •  臣服心动
    2021-01-06 15:14

    as you're using Android Studio, your Makefiles are ignored by default and new ones are generated on-the-fly, without properly referencing OpenCV as it's not supported.

    This is how NDK builds are currently working from Android Studio and it's deprecated while a better way to do it is in the work.

    You can deactivate this built-in NDK support and get your Makefiles to be used instead, by doing this inside your build.gradle:

    import org.apache.tools.ant.taskdefs.condition.Os
    
    apply plugin: 'com.android.application'
    
    android {
        ...
    
        sourceSets.main {
            jniLibs.srcDir 'src/main/libs' //set .so files directory to libs
            jni.srcDirs = [] //disable automatic ndk-build call
        }
    
        // call regular ndk-build(.cmd) script from app directory
        task ndkBuild(type: Exec) {
            if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
            } else {
                commandLine 'ndk-build', '-C', file('src/main').absolutePath
            }
        }
    
        tasks.withType(JavaCompile) {
            compileTask -> compileTask.dependsOn ndkBuild
        }
    }
    

    btw, I see you set APP_ABI only to armeabi-v7a, but OpenCV also supports x86 and mips, so you can also easily extend your support to these platforms.

    0 讨论(0)
提交回复
热议问题