react-native-keychain icon indicating copy to clipboard operation
react-native-keychain copied to clipboard

Method references are not supported in -source 1.7 in android

Open prakarti-shush opened this issue 2 years ago • 8 comments

method references are not supported in -source 1.7react-native-keychain/android/src/main/java/com/oblador/keychain/KeychainModule.java:157: error: method references are not supported in -source 1.7 final Thread warmingUp = new Thread(instance::internalWarmingBestCipher, "keychain-warming-up"); We are using Java 8 , still its showing error .

prakarti-shush avatar Jul 19 '22 10:07 prakarti-shush

We are also facing similar error

node_modules/react-native-keychain/android/src/main/java/com/oblador/keychain/KeychainModule.java:157: error: method references are not supported in -source 7 final Thread warmingUp = new Thread(instance::internalWarmingBestCipher, "keychain-warming-up"); ^ (use -source 8 or higher to enable method references)

marshal-truman avatar Jul 19 '22 14:07 marshal-truman

Go to KeychainModule.java and use the IDE suggestion to increase the language level to 8, this seemed to work for me, or at least allowed a successful build now.

nick-krause avatar Aug 04 '22 14:08 nick-krause

Adding this

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

Into the android section of node_modules/react-native-keychain/android/build.gradle

android {
  compileSdkVersion safeExtGet('compileSdkVersion', 31)
  buildToolsVersion safeExtGet('buildToolsVersion', '31.0.0')

  defaultConfig {
    minSdkVersion safeExtGet('minSdkVersion', 21)
    compileSdkVersion safeExtGet('compileSdkVersion', 31)
    targetSdkVersion safeExtGet('targetSdkVersion', 31)
    versionCode 1
    versionName "1.0"
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  lintOptions {
    abortOnError false
  }

  testOptions {
    unitTests {
      includeAndroidResources = true
    }
  }
}

esutton avatar Aug 19 '22 21:08 esutton

Go to KeychainModule.java and use the IDE suggestion to increase the language level to 8, this seemed to work for me, or at least allowed a successful build now.

I actually only saw this once and I don't think it worked for release builds. I had to add some other things like: kotlinOptions { jvmTarget="1.8" }

nick-krause avatar Aug 23 '22 15:08 nick-krause

I had the same issue when updating to the current version, adding the following to the android/build.gradle of the app itself solved the issue, no need to change the module directly:

allprojects {
    afterEvaluate { project ->
        if (project.hasProperty("android")) {
            android {
                compileOptions {
                    sourceCompatibility JavaVersion.VERSION_1_8
                    targetCompatibility JavaVersion.VERSION_1_8
                }
            }
        }
    }
}

stetbern avatar Aug 25 '22 09:08 stetbern

I had the same issue when updating to the current version, adding the following to the android/build.gradle of the app itself solved the issue, no need to change the module directly:

allprojects {
    afterEvaluate { project ->
        if (project.hasProperty("android")) {
            android {
                compileOptions {
                    sourceCompatibility JavaVersion.VERSION_1_8
                    targetCompatibility JavaVersion.VERSION_1_8
                }
            }
        }
    }
}

This works but if you try to create a release build, you're likely to get the Unsupported class file major version 59 error.

Balthazar33 avatar Sep 09 '22 10:09 Balthazar33

After an update to gradle 7 and RN 0.68.3 this issue is gone, so I believe this error is due to an outdated gradle version.

stetbern avatar Sep 20 '22 09:09 stetbern

I had the same issue when updating to the current version, adding the following to the android/build.gradle of the app itself solved the issue, no need to change the module directly:

allprojects {
    afterEvaluate { project ->
        if (project.hasProperty("android")) {
            android {
                compileOptions {
                    sourceCompatibility JavaVersion.VERSION_1_8
                    targetCompatibility JavaVersion.VERSION_1_8
                }
            }
        }
    }
}

this fixed my problem TY so much!

misaelriojasftf avatar Nov 20 '22 21:11 misaelriojasftf