I am encountering an error while running my Flutter application. The error message I receive is:
C:UsersIntelAppDataLocalPubCachehostedpub.devfirebase_core-2.32.0androidsrcmainjavaioflutterpluginsfirebasecoreGeneratedAndroidFirebaseCore.java:45:
error: pattern matching in instanceof is not supported in -source 8
if (exception instanceof FlutterError error) {
^
(use -source 16 or higher to enable pattern matching in instanceof)
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':firebase_core:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
I am using Java 16, which should support pattern matching with instanceof
. The error points to a line in GeneratedAndroidFirebaseCore.java
:
protected static ArrayList<Object> wrapError(@NonNull Throwable exception) {
ArrayList<Object> errorList = new ArrayList<Object>(3);
if (exception instanceof FlutterError error) {
errorList.add(error.code);
errorList.add(error.getMessage());
errorList.add(error.details);
} else {
errorList.add(exception.toString());
errorList.add(exception.getClass().getSimpleName());
errorList.add(
"Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception));
}
return errorList;
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}