Search code examples
flutterflutter-dependenciessqflite

When I add the sqflite package to my flutter project, the Android application cannot run


I have a problem with the sqflite package. I couldn't find a solution anywhere. I'm creating a new Flutter project. I install the sqflite package using the "flutter pub add sqflite" command. Then, when I try to run the application on the Android emulator, I get the following errors. When I try the same code in the IOS emulator, it does not give an error.

Errors:

/Users/receparda/.pub-cache/hosted/pub.dev/sqflite-2.3.0/android/src/main/java/com/tekartik/sqflite/Database.java:107: error: cannot find symbol
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                                                            ^
  symbol:   variable TIRAMISU
  location: class VERSION_CODES
/Users/receparda/.pub-cache/hosted/pub.dev/sqflite-2.3.0/android/src/main/java/com/tekartik/sqflite/Database.java:108: error: cannot find symbol
                applicationInfo = context.getPackageManager().getApplicationInfo(packageName, PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA));
                                                                                          ^
  symbol:   variable ApplicationInfoFlags
  location: class PackageManager
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sqflite:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUİLD FAILED in 1s
Exception: Gradle task assembleDebug failed with exit code 1

For the solution, I changed the SDK version to 33 and 34 (compileSdkVersion = 33 and targetSdkVersion = 33). I upgraded the Gradle version to 8.5. The same error continues.


Solution

  • Try go to the .pub-cache/hosted/pub.dev/sqflite-2.3.0/android directory and check if the gradle file has the 'namespace' entry?