ultimate_alarm_clock icon indicating copy to clipboard operation
ultimate_alarm_clock copied to clipboard

Fix: Android Build Failure Due to Deprecated Gradle Plugin Configuration

Open x15sr71 opened this issue 3 months ago • 2 comments

Fix: Android build fails due to deprecated Gradle plugin configuration

Description

The Android build is currently failing, preventing the app from being run or compiled on Android devices and emulators. This is blocking all Android development work.

Environment

  • Platform: Android
  • Build command: flutter run (debug mode)
  • Build target: sdk gphone64 arm64 emulator

Error Details

Attempting to build the app for Android results in an immediate Gradle failure during the configuration phase:

Launching lib/main.dart on sdk gphone64 arm64 in debug mode...

FAILURE: Build failed with an exception.

* Where:
Script '/Users/chandragupt/develop/flutter/packages/flutter_tools/gradle/app_plugin_loader.gradle' line: 9

* What went wrong:
A problem occurred evaluating script.
> You are applying Flutter's app_plugin_loader Gradle plugin imperatively using the apply script method, which is not possible anymore. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/to/flutter-gradle-plugin-apply

* 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'...                           2,014ms

Error: Gradle task assembleDebug failed with exit code 1
Click to view error screenshot
Error Screenshot

Root Cause Analysis

The project is using the deprecated imperative apply script method for loading Flutter's Gradle plugin. This approach was valid in older Flutter/Gradle versions but has been removed in favor of the modern declarative approach.

Key issues identified:

  1. Outdated plugin application method: The android/settings.gradle file is likely using apply from: statements to load Flutter plugins imperatively
  2. Build system version mismatch: Our current Gradle wrapper, Kotlin version, and Android Gradle Plugin (AGP) versions are likely incompatible with the latest Flutter SDK requirements
  3. Deprecated configuration patterns: The overall Android build configuration predates current Flutter best practices

The error message explicitly directs us to Flutter's migration guide, confirming this is a known breaking change that requires manual intervention.

Proposed Solution

Phase 1: Build System Modernization

  • Migrate android/settings.gradle to use the declarative plugins {} block as per Flutter's migration guide
  • Update android/build.gradle (project-level) to use modern plugin DSL
  • Update android/app/build.gradle (app-level) for compatibility
  • Bump Gradle wrapper to a current stable version (likely 7.x or 8.x)
  • Update Kotlin version to match Gradle requirements
  • Update Android Gradle Plugin (AGP) to a compatible version
  • Update compileSdkVersion, targetSdkVersion, and minSdkVersion as needed

Phase 2: Verification

  • Test build on multiple Android API levels
  • Verify both debug and release build configurations
  • Confirm hot reload and hot restart functionality

Expected Impact & Dependencies

Modernizing the core build system will have cascading effects across the project:

Package Updates Required

  • Many Flutter packages in pubspec.yaml will need version updates to maintain compatibility with the modernized build environment
  • Packages with native Android code may require specific minimum versions
  • Current dependency versions may be incompatible with updated Gradle/Kotlin versions

Potential Breaking Changes

  • google_sign_in: This package has undergone significant API changes in recent versions. The current implementation may need refactoring to use the new authentication flow
  • Other platform packages: Any packages with platform-specific code may have deprecated APIs that need updating
  • Build configuration: Custom Gradle configuration or third-party plugin integrations may need adjustment

Benefits

  • Brings the project into compliance with current Flutter standards
  • Enables use of modern Gradle features and optimizations
  • Improves build performance and developer experience
  • Positions the project for future Flutter SDK updates
  • Reduces technical debt

Priority

High - This is a blocking issue preventing all Android development. No Android builds can be completed until this is resolved.

Screenshots

Image

x15sr71 avatar Oct 23 '25 09:10 x15sr71

Hi! @x15sr71 👋 I’d love to work on this issue — thank you for maintaining such a great project. I’m a student developer experienced in React and API integrations, and I’ve contributed to several open-source projects focused on front-end optimization and performance improvements. For this issue, my plan is to first analyze the affected component’s current behavior, identify the root cause, and then implement a clean fix ensuring consistency across different states. I’ll verify the solution through manual testing and, if applicable, add or update relevant unit tests. I can have a pull request ready within 3–5 days.

Could you please assign me this issue? I’d be happy to start right away.

lakshay909 avatar Nov 07 '25 05:11 lakshay909

Hi @lakshay909! Thanks for your interest! I've already raised PR #853 that fixes this issue. Feel free to check out other open issues in the repo where you can contribute.

x15sr71 avatar Nov 09 '25 14:11 x15sr71