skip to Main Content

I’m using @capacitor/barcode-scanner in a reactjs project. The web version runs perfectly, but an error occurs for the mobile app ver.

I got this error when running the application

Execution failed for task ‘:capacitor-barcode-scanner:compileDebugKotlin’.
Inconsistent JVM-target compatibility detected for tasks ‘compileDebugJavaWithJavac’ (17) and ‘compileDebugKotlin’ (21).

I tried to change the java version in capacitor.build.gradle file but it will revert back to original when sync.

I also install jdk 17 and jdk 21 to try which one is suitable, but still received the same error.

Here are the solutions I’ve tried:
Link 1
Link 2
Link 3

Does the error come from Capacitor Barcode Scanner plugin or the Android?

2

Answers


  1. If you are using latest JDK to your project then you can make changes in build.gradle(app-level) and your project will run successfully.

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_21 // Adjust the version to the one that works for your project.
        targetCompatibility JavaVersion.VERSION_21 // Adjust the version to the one that works for your project.
    }
    

    and

    kotlinOptions {
        jvmTarget = '21'  // Adjust the version to the one that works for your project.
    }
    
    Login or Signup to reply.
  2. If jdk 21 version not works.
    Then java 17 is always safer option to choose.

    in gradle change source and target compatibility to 17 version for better stability

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search