错误:错误:(3,10)找不到'opencv2 / opencv.hpp'文件

时间:2016-12-21 10:25:23

标签: android opencv android-ndk

我正在使用Android studio 2.2.3和OpenCV 3.1.0。我解决了很多错误,但无法找到解决方案。

这是我的Build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "com.example.ahmedarif.fyp3"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    sourceSets.main {
        jni.srcDirs = [] //disable automatic ndk-build call
    }
    task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
        commandLine "C:\\Android\\sdk1\\ndk-bundle/ndk-build.cmd",
                'NDK_PROJECT_PATH=build/intermediates/ndk',
                'NDK_LIBS_OUT=src/main/jniLibs',
                'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
                'NDK_APPLICATION_MK=src/main/jni/Application.mk'
    }
    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } }


    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:25.1.0'
        testCompile 'junit:junit:4.12'
        compile project(':openCVLibrary310')
    }
}

enter image description here

我还尝试了来自ph0b

的buigl.gradle

但是build.gradle显示有关ndk-bulid.cmd的错误。我几乎尝试了所有的东西,但没有为我工作。帮助摆脱这一点。 Tahnx

2 个答案:

答案 0 :(得分:1)

enter image description here

然后我的build.gradle;

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.c.a.engineer.imageprocessingpre"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets { main { jni.srcDirs = []
        jniLibs.srcDir 'src/main/jniLibs' } }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile project(':openCVLibrary310')
}

这对我有用。你可以试试这个。我开发了图像处理应用程序。这是我的应用截图;

enter image description here

答案 1 :(得分:0)

如果您使用的是最新版本的android studio,请使用here中内置的c和c ++支持 而且我使用相同的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "com.example.ahmedarif.fyp3"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    sourceSets.main {
        jni.srcDirs = [] //disable automatic ndk-build call
    }
    task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
        commandLine "C:\\Android\\sdk1\\ndk-bundle/ndk-build.cmd",
                'NDK_PROJECT_PATH=build/intermediates/ndk',
                'NDK_LIBS_OUT=src/main/jniLibs',
                'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
                'NDK_APPLICATION_MK=src/main/jni/Application.mk'
    }
    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } }


    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:25.1.0'
        testCompile 'junit:junit:4.12'
        compile project(':openCVLibrary310')
    }
}