【问题标题】:Flutter with AWS CloudBuild fails to compile apkFlutter with AWS CloudBuild 无法编译 apk
【发布时间】:2021-03-03 18:51:18
【问题描述】:

生日快乐!

我正在尝试使用 AWS 开发人员工具为 Flutter android 应用程序创建 CI/CD 管道。 但我无法使用 AWS Codebuild 编译 apk 包。你能帮帮我们吗?

设置非常简单。 enter image description here

为简单起见,我使用了 Flutter HelloWorld dart 代码

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Welcome to Flutter'),
        ),
        body: Center(
          child: Text('Hello World'),
        ),
      ),
    );
  }
}

buildspec.yml

version: 0.2
phases:
  install:
    runtime-versions:
      android: 29
      java: openjdk8
    commands:
      - pwd
pre_build:
    commands:
      - echo Pre Build started on `date`
      - git clone https://github.com/flutter/flutter.git -b stable
      - export PATH="$PATH:`pwd`/flutter/bin"
      - flutter precache
      - flutter doctor
build:
    commands:
      - echo Build started on `date`
      - flutter build apk
      - ls -al
post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - "**/*"

CodeBuild 过程成功,但每次运行后它都会创建新的随机名称输出工件,但不会创建 .apk 文件。

我尝试了几种组合,但最终都出现了错误。

artifacts:
  files:
    - "**/app-release.apk"

artifacts:
  type: apk
  files:
    - "**/*"

enter image description here

【问题讨论】:

    标签: android flutter aws-codebuild


    【解决方案1】:

    找到解决方案。将工作目录更改为 helloworld 后,我设法编译了 apk 文件。

    正确的 buildspec.yml 应该如下所示:

    version: 0.2
    phases:
      install:
        runtime-versions:
          android: 29
          java: openjdk8
        commands:
          - pwd
      pre_build:
        commands:
        - echo Pre Build started on `date`
        - git clone https://github.com/flutter/flutter.git -b stable
        - export PATH="$PATH:`pwd`/flutter/bin"
        - flutter precache
        - flutter doctor
      build:
        commands:
        - cd helloworld
        - pwd
        - ls -al
        - echo Build started on `date`
        - flutter build apk
      post_build:
        commands:
          - echo Build completed on `date`
    artifacts:
      files:
      - helloworld/build/app/outputs/flutter-apk/app-release.apk
      discard-paths: yes
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-06
      • 2022-11-09
      • 1970-01-01
      • 2019-05-09
      • 1970-01-01
      • 2020-01-27
      • 2016-08-08
      相关资源
      最近更新 更多