OpenCV 4.11.0 issues integrating with Android

I am having issue when integrating the OpenCV to the jetpack compose android studio. It shows error
Execution failed for task ‘:opencv:compileDebugKotlin’.

A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction

Currently using “org.jetbrains.kotlin.android” version “2.0.21”
This is the OpenCV gradle I have made the java version into 17 and minSDk and targetSdk the same as the app gradle

plugins {
    alias(libs.plugins.kotlin.android)
}

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

try {
    apply plugin: 'kotlin-android'
    println "Configure OpenCV with Kotlin"
} catch (Exception e) {
    println "Configure OpenCV without Kotlin"
}

def openCVersionName = "4.11.0"
def openCVersionCode = ((4 * 100 + 11) * 100 + 0) * 10 + 0

println "OpenCV: " +openCVersionName + " " + project.buildscript.sourceFile

android {
    namespace 'org.opencv'
    compileSdkVersion 34

    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 34

        versionCode openCVersionCode
        versionName openCVersionName

        externalNativeBuild {
            cmake {
                arguments "-DANDROID_STL=c++_shared"
                targets "opencv_jni_shared"
            }
        }
    }
    
    android {
        buildFeatures {
            buildConfig true
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_17
            targetCompatibility JavaVersion.VERSION_17
        }

        kotlinOptions {
            jvmTarget = "17"
        }
    }
1 Like

please raise an official issue about it, ty :wink:

1 Like

For anyone who is having the same issue it is written on here
Issues when integrating opencv using kotlin version 2.0++

This issues occur only when you download the opencv from website and import it as module
For now you can fix it by downgrading your kotlin version below 2.0
And if there is compiler issue you can implement the

    composeOptions {
        kotlinCompilerExtensionVersion = "your version"
    }
3 Likes