Reading QR Code crashes kotlin application

Ibanez1408 :

I am trying to create a QR scanner using Kotlin. This is the code I have so far

This is in my gradle

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.google.codelabs.mdc.kotlin.shrine"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
// barcode scanning
implementation 'com.journeyapps:zxing-android-embedded:4.1.0'

and this is how I call the scanning

val clickListener = View.OnClickListener { view ->
        when(view.id) {
            R.id.button_class1 -> textView_class.text = "1"
            R.id.button_class2 -> textView_class.text = "2"
            R.id.button_class3 -> textView_class.text = "3"
            R.id.button_scan -> {
                val scanner = IntentIntegrator(this.activity)
                scanner.initiateScan()
            }
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if(resultCode == Activity.RESULT_OK) {
            var result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
           if (result != null) {
               if (result.contents == null) {
                   Toast.makeText(context, "CANCELED", Toast.LENGTH_SHORT)
               } else {
                   println("QR CODE ${result.contents}")
               }
           } else {
               super.onActivityResult(requestCode, resultCode, data)
           }
        }
    }

When I click on my button_scan I momentarilly able to get to the scanning part very very briefly then it crashes with this error:

2020-03-20 16:05:40.280 29202-29202/? E/Zygote: isWhitelistProcess - Process is Whitelisted 2020-03-20 16:05:40.281 29202-29202/? E/Zygote: accessInfo : 1 2020-03-20 16:05:40.309 29202-29202/? E/c.kotlin.shrin: Unknown bits set in runtime_flags: 0x8000 2020-03-20 16:05:44.973 29202-29202/com.google.codelabs.mdc.kotlin.shrine E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.google.codelabs.mdc.kotlin.shrine, PID: 29202
    java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar)
        at com.journeyapps.barcodescanner.CaptureManager.<init>(CaptureManager.java:130)
        at com.journeyapps.barcodescanner.CaptureActivity.onCreate(CaptureActivity.java:23)
        at android.app.Activity.performCreate(Activity.java:7981)
        at android.app.Activity.performCreate(Activity.java:7970)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3594)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2146)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:7777)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)

Can you please tell me how to correct this?

Bruno :

Try to switch to Java 8 compatibility, requiring by some libraries:

android {

    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=336929&siteId=1