'Can build app in debug mode but not in release mode Flutter

I am facing following error in console when running in release mode.

C:\Users\Bilal Saeed\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\google_maps_flutter-2.1.0\android\src\main\java\io\flutter\plugins\googlemaps\Googl
eMapsPlugin.java:19: error: cannot find symbol
import io.flutter.embedding.engine.plugins.lifecycle.FlutterLifecycleAdapter;
                                                    ^
  symbol:   class FlutterLifecycleAdapter
  location: package io.flutter.embedding.engine.plugins.lifecycle
C:\Users\Bilal Saeed\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\google_maps_flutter-2.1.0\android\src\main\java\io\flutter\plugins\googlemaps\Googl
eMapsPlugin.java:92: error: cannot find symbol
    lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(binding);
                ^
  symbol:   variable FlutterLifecycleAdapter
  location: class GoogleMapsPlugin
Note: C:\Users\Bilal Saeed\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\google_maps_flutter-2.1.0\android\src\main\java\io\flutter\plugins\googlemaps
\Convert.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\Bilal Saeed\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\google_maps_flutter-2.1.0\android\src\main\java\io\flutter\plugins\googlemaps
\TileProviderController.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':google_maps_flutter:compileReleaseJavaWithJavac'.
> 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

BUILD FAILED in 3m 14s
Running Gradle task 'assembleRelease'...                          195.8s
Gradle task assembleRelease failed with exit code 1

What I have tried so far.

  1. Added this line to gradle.properties.
org.gradle.jvmargs=-Xmx4608m
  1. In Android Studio
File > Invalidate Caches/Restart... 
    • Deleted the complete pub_cache folder.
    • Restarted my Android Studio.
    • Ran flutter clean, flutter pub get, flutter upgrade.
  1. Ran flutter pub cache repair command also.

But no solution worked.



Solution 1:[1]

What worked for me might help some one else.

1. Delete .gradle file present in android folder of project.

2. Update classpath in project level build.gradle file by hovering over it to the latest version.

3. Upgraded distribution URL in gradle-wrapper.properties

4. Clicked File/Invalidate Caches & restart option. And it started to release my app once again.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bilal Saeed