首页 > 解决方案 > 构建 Flutter Android 应用时 AppCenter 构建崩溃

问题描述

我正在使用 AppCenter 构建 Flutter Android 应用程序。

我有以下从这里获取的构建脚本

#!/usr/bin/env bash
#Place this script in project/android/app/
cd ..
# fail if any command fails
set -e
# debug log
set -x
cd ..
git clone -b dev https://github.com/flutter/flutter.git
export PATH=`pwd`/flutter/bin:$PATH
flutter doctor
echo "Installed flutter to `pwd`/flutter"
flutter build apk --release
#copy the APK where AppCenter will find it
mkdir -p android/app/build/outputs/apk/; mv build/app/outputs/apk/release/app-release.apk $_

以下是构建日志的摘录:

...    
Downloading ios-deploy...                                           0.4s
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel dev, v1.9.7, on Mac OS X 10.14.6 18G87, locale en)
    [!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
        ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
    [✓] Xcode - develop for iOS and macOS (Xcode 10.3)
    [!] Android Studio (not installed)
    [!] Connected device
        ! No devices available

    ! Doctor found issues in 3 categories.
    ++ pwd
    + echo 'Installed flutter to /Users/vsts/agent/2.155.1/work/1/s/flutter'
    + flutter build apk --release
    Installed flutter to /Users/vsts/agent/2.155.1/work/1/s/flutter
    Running "flutter pub get" in s...                                   4.1s
    You are building a fat APK that includes binaries for android-arm, android-arm64.
    If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
        To generate an app bundle, run:
            flutter build appbundle --target-platform android-arm,android-arm64
            Learn more on: https://developer.android.com/guide/app-bundle
        To split the APKs per ABI, run:
            flutter build apk --target-platform android-arm,android-arm64 --split-per-abi
            Learn more on:  https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
    Initializing gradle...                                          

    Sending crash report to Google.

...

看起来 AppCenter 无法初始化 Gradle。有什么建议么?.gitignore 文件:

# Android related
#**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
#**/android/gradlew
#**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

标签: androidgradlefluttercontinuous-integrationvisual-studio-app-center

解决方案


我也面临着类似的问题。另一种方法是将 apk 发布到 appcenter 的发布部分。


推荐阅读