0

I tryed import OpenCV module in my project. I find some nice tutorial and create new project to test OpenCV implementation. Problem, when I import library OpenCV in a new project all works well (tutorial here).

But when I have done the same whit existing project I got an error

enter image description here

I try fix it but without success. How can I fix it?

Gradle file

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

apply plugin: 'com.android.application'

repositories {
    jcenter()
}

dependencies {
    compile 'com.android.support:support-v4:23.2.0'
    compile 'com.android.support:support-v13:23.2.0'
    compile 'com.android.support:cardview-v7:23.2.0'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile files('libs/svgandroid.jar')
    compile files('libs/svg-android.jar')
    compile files('libs/guava-16.0.1.jar')
}

// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
    'main',     // main sample code; look here for the interesting stuff.
    'common',   // components that are reused by multiple samples
    'template' // boilerplate code that is generated by the sample  template process
]

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 22
        targetSdkVersion 23
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    sourceSets {
        main {
            dirs.each { dir ->
                java.srcDirs "src/${dir}/java"
                res.srcDirs "src/${dir}/res"
            }
        }
        androidTest.setRoot('tests')
        androidTest.java.srcDirs = ['tests/src']
    }
}
Sven R.
  • 1,049
  • 17
  • 24
Sirop4ik
  • 4,543
  • 2
  • 54
  • 121

2 Answers2

1

Latest Gradle: 2.11

Check with: gradle -v

Download here: http://services.gradle.org/distributions/gradle-2.11-bin.zip

Latest Android Build Tools: 1.5.0

If you add the following code snippet to the top of your build.gradle file, gradle will update the build tools.

buildscript {
    repositories {
        jcenter() // or mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

Read more here: http://tools.android.com/tech-docs/new-build-system

Adnan Amjad
  • 2,553
  • 1
  • 20
  • 29
  • i still don't understand exsactly, what the problem... but i just add code snippet in build.gradle and problem disappear... But why? what this code snippet means? – Sirop4ik Mar 13 '16 at 10:30
0

Are you sure it's apply plugin: 'com.android.library'? You can try replacing that with apply plugin: 'com.android.application'. If you changed so you have to give applicationId "package path" in defaultconfig like

   defaultConfig {
        applicationId "full package"
      //extra stuffs
    }

And another thing to notice is why aren't you just compiling it in dependency? like here

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
      //Other extra compilations 
    compile 'nu.pattern:opencv:2.4.9-4' //OpenCV compilation
}
Shree Krishna
  • 8,474
  • 6
  • 40
  • 68