I’m working on a mobile app project using Flutter and Dart. I’m now adding Firebase but to help with storing and managing data from multiple users. I did all the setup using Android as my app. However, I seem to get errors during initialization.
Here’s the error:
C:flutter_projectsUHS-StudentToolsandroidappsrcdebugAndroidManifest.xml Error:
uses-sdk:minSdkVersion 19 cannot be smaller than version 21 declared in library [com.google.firebase:firebase-analytics:22.0.2] C:UsersName.gradlecachestransforms-38c1b88baa8add63807a0e07d3d434f97transformedjetified-firebase-analytics-22.0.2AndroidManifest.xml as the library might be using APIs not available in 19
Suggestion: use a compatible library with a minSdk of at most 19,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="com.google.firebase.firebase_analytics" to force usage (may lead to runtime failures)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 19 cannot be smaller than version 21 declared in library [com.google.firebase:firebase-analytics:22.0.2] C:UsersName.gradlecachestransforms-38c1b88baa8add63807a0e07d3d434f97transformedjetified-firebase-analytics-22.0.2AndroidManifest.xml as the library might be using APIs not available in 19
Suggestion: use a compatible library with a minSdk of at most 19,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="com.google.firebase.firebase_analytics" to force usage (may lead to runtime failures)
* 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
BUILD FAILED in 4s
Exception: Gradle task assembleDebug failed with exit code 1
My build.gradle, where the error occurs:
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.google.gms:google-services:4.4.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.android.tools.build:gradle:7.1.3"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
app/build.gradle:
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id 'com.google.gms.google-services'
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
namespace "com.name.unionville_student_tools"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.name.unionville_student_tools"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:33.1.2')
implementation 'com.google.firebase:firebase-analytics:'
}
I’ve tried changing minSdk from flutter.minSdkVersion to 21. However, this error then occurs.
e: C:/Users/Name/.gradle/caches/transforms-3/3248fbcca8f97a1a99810080888e4df2/transformed/jetified-play-services-measurement-api-22.0.2-api.jar!/META-INF/java.com.google.android.gmscore.integ.client.measurement_api_measurement_api.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
> Compilation error. See log for more 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
BUILD FAILED in 8s
┌─ Flutter Fix ──────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin. │
│ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then │
│ update C:flutter_projectsUHS-StudentToolsandroidbuild.gradle: │
│ ext.kotlin_version = '<latest-version>' │
└────────────────────────────────────────────────────────────────────────────────────────────┘
Exception: Gradle task assembleDebug failed with exit code 1
Okay so let’s update Kotlin Gradle by changing ext.kotlin_version = 2.0.10
. Then I get another error
Launching libmain.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
√ Built buildappoutputsflutter-apkapp-debug.apk.
Installing buildappoutputsflutter-apkapp-debug.apk...
E/AndroidRuntime(11440): FATAL EXCEPTION: main
E/AndroidRuntime(11440): Process: com.edisoncai.unionville_student_tools, PID: 11440
E/AndroidRuntime(11440): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.edisoncai.unionville_student_tools/com.edisoncai.unionville_student_tools.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.edisoncai.unionville_student_tools.MainActivity" on path: DexPathList[[zip file "/data/app/~~rmTgfNhuyubW5OCKgEcZGQ==/com.edisoncai.unionville_student_tools-Iqt4jnFiG8P_dyu3MMC3yA==/base.apk"],nativeLibraryDirectories=[/data/app/~~rmTgfNhuyubW5OCKgEcZGQ==/com.edisoncai.unionville_student_tools-Iqt4jnFiG8P_dyu3MMC3yA==/lib/x86_64, /data/app/~~rmTgfNhuyubW5OCKgEcZGQ==/com.edisoncai.unionville_student_tools-Iqt4jnFiG8P_dyu3MMC3yA==/base.apk!/lib/x86_64, /system/lib64, /system_ext/lib64]]
E/AndroidRuntime(11440): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3954)
E/AndroidRuntime(11440): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4235)
E/AndroidRuntime(11440): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:112)
E/AndroidRuntime(11440): at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:174)
E/AndroidRuntime(11440): at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:109)
E/AndroidRuntime(11440): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:81)
E/AndroidRuntime(11440): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2636)
E/AndroidRuntime(11440): at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(11440): at android.os.Looper.loopOnce(Looper.java:232)
E/AndroidRuntime(11440): at android.os.Looper.loop(Looper.java:317)
E/AndroidRuntime(11440): at android.app.ActivityThread.main(ActivityThread.java:8705)
E/AndroidRuntime(11440): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11440): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
E/AndroidRuntime(11440): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
E/AndroidRuntime(11440): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.edisoncai.unionville_student_tools.MainActivity" on path: DexPathList[[zip file "/data/app/~~rmTgfNhuyubW5OCKgEcZGQ==/com.edisoncai.unionville_student_tools-Iqt4jnFiG8P_dyu3MMC3yA==/base.apk"],nativeLibraryDirectories=[/data/app/~~rmTgfNhuyubW5OCKgEcZGQ==/com.edisoncai.unionville_student_tools-Iqt4jnFiG8P_dyu3MMC3yA==/lib/x86_64, /data/app/~~rmTgfNhuyubW5OCKgEcZGQ==/com.edisoncai.unionville_student_tools-Iqt4jnFiG8P_dyu3MMC3yA==/base.apk!/lib/x86_64, /system/lib64, /system_ext/lib64]]
E/AndroidRuntime(11440): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
E/AndroidRuntime(11440): at java.lang.ClassLoader.loadClass(ClassLoader.java:637)
E/AndroidRuntime(11440): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime(11440): at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
E/AndroidRuntime(11440): at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
E/AndroidRuntime(11440): at android.app.Instrumentation.newActivity(Instrumentation.java:1448)
E/AndroidRuntime(11440): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3941)
E/AndroidRuntime(11440): ... 13 more
So what now?
Recognized by Mobile Development Collective and Google Cloud Collective