Karzel
Karzel

Reputation: 1508

Initializing OpenCv on Android (Studio 3.2.1), target SDK 28

I've been following this steps to setup OpenCv in my Android Studio project: https://stackoverflow.com/a/27421494/8713068

I've tried both OpenCv 3.4.2 and 3.4.3. I've tried with and without Kotlin support. Despite every step made a few times, I'm still having "Gradle project sync failed." But in Build Window everything is "SUCCESSFUL".

Have any of you tried creating new OpenCv project lately ? What am doing wrong ?

build.gradle of OpenCV

apply plugin: 'com.android.library'

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
    minSdkVersion 23
    targetSdkVersion 28
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

build.gradle of app:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myname.test2"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation project(':openCVLibrary342')
}

Steps again:

  1. Created new project
  2. Unpacked OpenCV SDK
  3. File -> New -> Import Module -> java folder of SDK
  4. Changed build.gradle of OpenCv (sdk versions)
  5. Right Click on app -> "Open Module Settings" -> Dependencies (of app) -> + -> added openCv
  6. Created "jniLibs" folder under "main" folder, added all folders from OpenCVSDK's "libs" folder

I've tried to add NDK, didn't help too

Upvotes: 0

Views: 1134

Answers (1)

Karzel
Karzel

Reputation: 1508

If anyone is also struggling with that, OpenCv brings its own AndroidManifest and it has declared sdk-version on its own.. just remove <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> line and everything should work

Upvotes: 2

Related Questions