Reputation: 81
I still don't know the solution to this but I change from using @capacitor/barcode-scanner
to html5-qrcode
npm package. It still gives off the same functionalities but I don't have to deal with the error anymore.
But if you know the solution to my issue, feel free to share.
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?
Upvotes: 0
Views: 393
Reputation: 2478
I don't know what would be the ultimate solution here, but I had to go to node_modules/@capacitor/android/build.gradle
and change the android.compileOptions
that were JavaVersion.VERSION_17
to JavaVersion.VERSION_21
.
I am not that familiar with native Android development that I could say if this is a bug in @capacitor/barcode-scanner
or should I config something in my project.
Upvotes: 0
Reputation: 967
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.
}
Upvotes: 0
Reputation: 1
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
Upvotes: 0