MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.42k stars 1.36k forks source link

Unable to Add 'com.android.tools.build:gradle:7.3.1' to android/build.gradle in Flutter 3 #2361

Open baigle0 opened 2 weeks ago

baigle0 commented 2 weeks ago

Hello,

I am currently configuring a package in my Flutter 3 application for Android. I have reached the step where I need to add:

classpath 'com.android.tools.build:gradle:7.3.1'

to the android/build.gradle file. However, this file does not contain a buildscript section like:

buildscript {
    dependencies {}
}

Here is my android/build.gradle:

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
}

I also have a settings.gradle file in the root directory. Should I add com.android.tools.build:gradle:7.3.1 there instead?

If you have an example of the correct configuration, that would be very helpful.

Thanks.

capc0307 commented 2 weeks ago

I'm using Flutter 3.22.2 and facing the same problem right now. Somebody already encountered this issue in March, but it was unresolved at the time: https://github.com/MaikuB/flutter_local_notifications/issues/2255#issuecomment-1991301291. I will try to include the "classpath 'com.android.tools.build:gradle:7.3.1'" inside "dependencies" block alone. I will comment if that works.

capc0307 commented 2 weeks ago

I made it work. I got a local notification using the package. I included all the permissions they indicated in the Readme. I don't know if I'm implementing the notification feature correctly/efficiently, but here are my configuration files:

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.example.borrar" compileSdk = 34 ndkVersion = flutter.ndkVersion

compileOptions {
    coreLibraryDesugaringEnabled = true
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId = "com.example.borrar"
    // 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.
    multiDexEnabled = true
    minSdk = flutter.minSdkVersion
    targetSdk = 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 { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2' implementation 'androidx.window:window:1.0.0' implementation 'androidx.window:window-java:1.0.0' }


- android/build.gradle:
```gradle
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
}
baigle0 commented 1 week ago

ok thanks for your feedback, finally you didn't add this line in your project: classpath 'com.android.tools.build:gradle:7.3.1'.

bleonard252 commented 1 week ago

It looks like that section is only present in android/build.gradle if your project is using Kotlin.

baigle0 commented 1 week ago

yes indeed it's a flutter project that uses kotlin , so I don't need to add this line ? com.android.tools.build:gradle:7.3.1 in my emulator it works without adding this line just so you know, I'm a backend developer and I'm new to mobile development. thx

MaikuB commented 3 days ago

The step for this is specifically on ensuring that AGP 7.3.1 is used at a minimum. If you cannot see that line there then it's likely that your app is on following new syntax. The Flutter docs cover this new syntax at https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply. They capture where you can specify the AGP version