Jason Lloyd
Jason Lloyd

Reputation: 458

Flutter: Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'

I keep getting the error whenever I try to run flutter build appbundle.

Here's the error message that gets displayed in the terminal:

Warning: there were 10 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.

* 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 2m 2s

Not sure what that means. Any ideas?

Upvotes: 2

Views: 801

Answers (1)

Shachindra
Shachindra

Reputation: 41

I hope you'd have resolved this issue by now but thought to leave an answer for future references:

  1. Create a file inside the app folder named proguard-rules.pro (project dir -> android -> app -> proguard-rules.pro)
  2. Inside the file, write
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
-ignorewarnings
  1. Update the build.gradle (project dir -> android -> app -> build.gradle) adding this line to the buildTypes block:
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

Example Snippet from build.gradle:

defaultConfig {
        applicationId "com.company.appname"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

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

    buildTypes {
        release {
            signingConfig signingConfigs.release
            shrinkResources true
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

Then running flutter build appbundle or flutter build apk --split-per-abi shouldn't cause any problems.

Upvotes: 4

Related Questions