【问题标题】:How can I publish my VIsual Studio Code built application as an APK?如何将我的 VIsual Studio Code 构建的应用程序发布为 APK?
【发布时间】:2021-11-06 16:10:22
【问题描述】:

我正在尝试在 Visual Studio Code 中构建 App Bundle,但它总是失败并显示:

    FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:shrinkReleaseResources'.
> org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 7; Attribute "keep" bound to namespace "http://schemas.android.com/tools" was already specified for element "resources".

* 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

这是我在项目中使用的依赖项:

  dependencies:
  flutter:
    sdk: flutter

  sqflite: ^2.0.0+3
  intl: ^0.17.0
  syncfusion_flutter_calendar: ^19.2.62
  provider: ^5.0.0
  cupertino_icons: ^1.0.2  
  material_design_icons_flutter: ^5.0.5955-rc.1
  curved_navigation_bar: ^1.0.1
  responsive_text_field: ^0.1.4
  flutter_datetime_picker: ^1.5.1
  datetime_picker_formfield: ^2.0.0
  flutter_local_notifications: ^8.1.1+1
  table_calendar: ^3.0.2
  shared_preferences: ^2.0.8
  shared_preferences_web: ^2.0.2
  firebase_auth: ^3.1.2
  cloud_firestore: ^2.5.3
  firebase_core: ^1.7.0
  flutter_spinkit: ^5.1.0
  fluttertoast: ^8.0.8
  image_picker: ^0.8.4+2
  image_cropper: ^1.4.1
  photo_view: ^0.13.0
  rxdart: ^0.27.2
  badges: ^2.0.1
  profanity_filter: ^2.0.0

当我遇到问题时,我什么时候运行--stacktrace 来找出错误。我在终端中尝试过,但那里似乎没有 stacktrace 命令。

【问题讨论】:

  • 请将代码和数据添加为文本 (using code formatting),而不是图像。图片:A)不允许我们复制粘贴代码/错误/数据进行测试; B) 不允许根据代码/错误/数据内容进行搜索;和many more reasons。除了代码格式的文本之外,只有在图像添加了一些重要的东西,而不仅仅是文本代码/错误/数据传达的内容时,才应该使用图像。
  • 看起来你必须检查你的 android XML 资源。也许你添加了工具:保持两次。
  • 分享你的 AndroidManifest.xml 文件,我猜问题出在你的 XML 文件上,你在配置 firebase 时是否对其进行了编辑?

标签: flutter


【解决方案1】:

首先,

使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

请使用--debug--scan 运行并在此处粘贴输出。没有太多信息,很难发现错误。

其次,

org.xml.sax.SAXParseException;行号:6;列号:7;已为元素“resources”指定了绑定到命名空间“http://schemas.android.com/tools”的属性“keep”。

这与资源文件有关。请列出您在 Flutter 应用中使用的插件(例如粘贴您的 pubspec.yaml)。同时列出你对flutter app的android目录做了哪些修改。

【讨论】:

  • 抱歉,我现在更新了我的问题。你可以再看一遍
  • @AdrianAlejo 请使用 --debug 或 --scan 显示日志详细信息
  • 我应该在哪里运行--debug--scan
  • @AdrianAlejo 这是一个 android studio 选项
【解决方案2】:

为了构建一个没有错误的颤振 apk,我总是执行以下操作(在终端上):

flutter build apk --no-shrink

【讨论】:

  • 它对我不起作用
  • 它给出了什么错误?一样吗?
  • 是的,同样的错误
【解决方案3】:

你也可以试试这个:

  1. 在 android 平台上清理、构建和运行项目。
  2. 然后在this之类的android文件夹中打开它。
  3. 然后按照生成普通的android签名.apk步骤,如this

注意:确保打开项目的android文件夹必须是同步、干净、构建和无错误的,然后才能生成android singed apk。

【讨论】:

    【解决方案4】:

    对于调试 APK:

    flutter build apk
    

    对于发布 APK:

    flutter build apk --release
    

    对于应用程序包:

    flutter build appbundle
    

    【讨论】:

      【解决方案5】:

      从项目根目录中删除 .idea 文件夹。删除 pubspec.lock。运行flutter clean,然后flutter pub get再试一次。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-20
        • 1970-01-01
        • 2015-03-28
        • 2013-11-06
        • 1970-01-01
        相关资源
        最近更新 更多