Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio can't find opencv modules, but compiles ok

My project compiles fine, but Android Studio panics because it thinks it can't find opencv's modules:

enter image description hereenter image description here

OpenCV is included as a separate module, and it's listed as a dependency. As far as I can tell it's all set up fine. OpenCV's build.gradle is as follows:

apply plugin: 'android-library'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.11.+'
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 2480
        versionName "2.4.8"
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
            aidl.srcDirs = ['src']
        }
    }
}

Any idea what's going on? I'm not too bugged as I said, it compiles and runs absolutely fine. It is very annoying though.

like image 278
fredley Avatar asked Jun 20 '14 16:06

fredley


1 Answers

Finally cracked this one. Following some online guides (I can't remember now which one), I'd installed opencv into /libraries/opencv/ in my project. The problem was that the code was in the directory ./src/main/java/org/opencv/[module], and this was causing classpath problems.

To solve the problem, I moved ./src/main/java/org to ./src/org. I did this in my file manager, not in Android Studio, and then rebuilt the project.

The project compiles fine, and all the errors are gone.

like image 76
fredley Avatar answered Nov 02 '22 12:11

fredley