androidflutterdartbuild.gradle

Flutter Gradle error and flutter_native_timezone version error


I run my app in Android and suddenly this error comes related to build error and flutter_native_timezone I tried to update the version of kotlin and build but still it didnt work and it still gets error

Warning: Flutter support for your project's Android Gradle Plugin version (Android Gradle Plugin version 8.1.0) will soon be dropped. Please upgrade your Android Gradle Plugin version to a version of at least Android Gradle Plugin version 8.3.0 soon.
Alternatively, use the flag "--android-skip-build-dependency-validation" to bypass this check.

Potential fix: Your project's AGP version is typically defined in the plugins block of the `settings.gradle` file (/Users/rajpurohittanu/Documents/GitHub/generic-quiz-flutter/android/settings.gradle), by a plugin with the id of com.android.application. 
If you don't see a plugins block, your project was likely created with an older template version. In this case it is most likely defined in the top-level build.gradle file (/Users/rajpurohittanu/Documents/GitHub/generic-quiz-flutter/android/build.gradle) by the following line in the dependencies block of the buildscript: "classpath 'com.android.tools.build:gradle:<version>'".


FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':flutter_native_timezone'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
   > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

     If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

* 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 1s
Running Gradle task 'assembleDebug'...                           1,792ms
Error: Gradle task assembleDebug failed with exit code 1

I Tried increasing the versions and also. changing the flutter time zone package but nothing worked for it if anyone knows please help me in this

Android/build.gradle

buildscript {
    ext.kotlin_version = '1.8.22' 
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:8.2.2" 
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.gms:google-services:4.3.15" 
    }
}

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
}

Android/app/build.gradle

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file("key.properties")
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    namespace = ""
    compileSdk = 35
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }

    defaultConfig {
        applicationId = ""
        minSdk = 26
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled false
            shrinkResources false
        }
    }
}

flutter {
    source = "../.."
}

yml file

name: generic_quiz_flutter
description: "A new Flutter project."

# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.1+11

environment:
  sdk: ^3.6.0

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.8
  percent_indicator: ^4.2.5
  shared_preferences: ^2.5.3
  vibration: ^3.1.3
  lottie: ^3.3.1
  http: ^1.4.0
  connectivity_plus: ^6.1.4
  superwallkit_flutter: ^2.2.2
  webview_flutter: ^4.12.0
  provider: ^6.1.5
  firebase_core: ^3.13.1
  firebase_messaging: ^15.2.6
  amplitude_flutter: ^4.3.1
  firebase_crashlytics: ^4.3.6
  purchases_flutter: ^8.8.1
  url_launcher: ^6.3.1
  flutter_native_timezone: ^2.0.0
  intl: ^0.20.0
  fl_chart: ^1.0.0
  in_app_review: ^2.0.10
  share_plus: ^11.0.0
  flutter_keyboard_visibility: ^6.0.0
  

dev_dependencies:
  flutter_test:
    sdk: flutter

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^6.0.0
  flutter_gen: ^5.10.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:
  uses-material-design: true
  generate: true

  assets:
    - assets/images/start.png
    - assets/images/mid.png
    - assets/images/end.png
    - assets/images/notification.png
    - assets/images/onboarding1.png
    - assets/images/onboarding2.png
    - assets/images/onboarding3.png
    - assets/images/onboarding4.png
    - assets/animations/progress.json
    - assets/animations/analysis.json
    - assets/images/morning.png
    - assets/images/noon.png
    - assets/images/after_work.png
    - assets/images/bedtime.png
    - assets/images/no_pref.png
    - assets/images/mode1.png
    - assets/images/mode2.png
    - assets/images/mode3.png
    - assets/images/time1.png
    - assets/images/time2.png
    - assets/images/time3.png
    - assets/images/time4.png

flutter_gen:
  localization:
    arb-dir: lib/l10n
    output-dir: lib/l10n
    template-arb-file: app_en.arb
    output-localization-file: app_localizations.dart
    nullable-getter: false
    use-escaping: true
    synthetic-package: false

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/docs/development/ui/assets-and-images#resolution-aware

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/docs/development/ui/assets-and-images#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/docs/cookbook/design/fonts#from-packages


Solution

  • The plugin flutter_native_timezone was last released four years ago. Since then, it has not been maintained.

    Because of this, it is missing the change Gradle brought for adding a namespace attribute to the build.gradle file.

    You have two choices here:

    1. Alter the plugin itself locally (the build.gradle file) and add the appropriate namespace attribute.
    android {
        namespace 'com.whelksoft.flutter_native_timezone' /// <----
        compileSdkVersion 30
    
        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }
        defaultConfig {
            targetSdkVersion 30
            minSdkVersion 16
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        lintOptions {
            disable 'InvalidPackage'
        }
    }
    

    Pay attention that there could also be other underlying issues.

    1. Choose a different plugin that achieves the same behavior flutter_native_timezone does