微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flutter:任务':app:transformClassesAndResourcesWithProguardForRelease'

如何解决Flutter:任务':app:transformClassesAndResourcesWithProguardForRelease'

每次尝试运行Flutter build appbundle时,我都会不断收到错误消息。

这是在终端中显示错误消息:

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

不确定是什么意思。有什么想法吗?

解决方法

我希望你现在已经解决了这个问题,但想留下一个答案以供将来参考:

  1. 在 app 文件夹中创建一个名为 proguard-rules.pro 的文件(项目目录 -> android -> app -> proguard-rules.pro)
  2. 在文件里面,写
-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. 更新 build.gradle(项目目录 -> android -> app -> build.gradle),将此行添加到 buildTypes 块:
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'

来自 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'
        }
    }

然后运行 ​​flutter build appbundleflutter build apk --split-per-abi 应该不会导致任何问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。