I am trying to get the flutter app to build in AppCenter.ms but I'm stuck with a gradle command cleaning the intermediates folder.
I have followed these tutorials to set it up:
- https://www.rocksolidknowledge.com/articles/using-appcenter-for-flutter-projects
- https://buildflutter.com/deploying-flutter-apps-via-appcenter/
- https://medium.com/@subodhpushpak/flutter-continuous-build-deployment-using-appcenter-e105d00e6f9c
I have added a productFlavor
called appCenter
to accommodate this library: https://pub.dev/packages/flutter_appcenter_bundle
Here is my appcenter-post-clone.sh
:
#!/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 stable https://github.com/flutter/flutter.git
export PATH=`pwd`/flutter/bin:$PATH
flutter channel stable
flutter doctor
# prevent missing flutter.jar error
flutter precache `pwd`/flutter/bin/cache/artifacts/engine
# Set APP_CENTER_VERSION_MODIFIER if you want to modify the version name
# to x.y.z-${APP_CENTER_VERSION_MODIFIER}
BUILD_NAME=$(grep -E '^version' pubspec.yaml | cut -d':' -f2 | tr -d '[:space:]')
if [ ! -z "$APPCENTER_BUILD_ID" ]
then
BUILD_NAME=${BUILD_NAME}.${APPCENTER_BUILD_ID}
fi
if [ ! -z "$APP_CENTER_VERSION_MODIFIER" ]
then
BUILD_NAME=${BUILD_NAME}-${APP_CENTER_VERSION_MODIFIER}
fi
flutter build apk --debug --flavor appCenter
flutter build apk --release --flavor appCenter --build-name=${BUILD_NAME} -t lib/main.dart
mkdir -p android/app/build/outputs/apk/
mv build/app/outputs/flutter-apk/app-appcenter-release.apk $_
The error occurs when the appcenter-post-clone.sh
script has finished and it is running gradle afterwards:
+ flutter build apk --debug --flavor appCenter
Running "flutter pub get" in s... 11.2s
Building with sound null safety
Running Gradle task 'assembleAppCenterDebug'...
Gradle 6.7
...
Running Gradle task 'assembleAppCenterDebug'... 193.4s
✓ Built build/app/outputs/flutter-apk/app-appcenter-debug.apk.
+ flutter build apk --release --flavor appCenter --build-name=1.42 -t lib/main.dart
Running "flutter pub get" in s... 15.7s
Building with sound null safety
Running Gradle task 'assembleAppCenterRelease'...
Gradle 6.7
...
Running Gradle task 'assembleAppCenterRelease'... 104.7s
✓ Built build/app/outputs/flutter-apk/app-appcenter-release.apk (25.9MB).
+ mkdir -p android/app/build/outputs/apk/
+ mv build/app/outputs/flutter-apk/app-appcenter-release.apk android/app/build/outputs/apk/
+ mv -v android/app/build/outputs/apk/app-appcenter-release.apk android/app/build/outputs/apk/app-release.apk
android/app/build/outputs/apk/app-appcenter-release.apk -> android/app/build/outputs/apk/app-release.apk
//SCRIPT HAS FINISHED
//RUNNING NORMAL GRADLE
Description : Build using a Gradle wrapper script
Version : 1.128.0
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613720)
==============================================================================
(node:3364) Warning: Use Cipheriv for counter mode of aes-256-ctr
...
(node:3364) Warning: Use Cipheriv for counter mode of aes-256-ctr
SYSTEMVSSCONNECTION exists true
[command]/.../android/gradlew -DAPPCENTER_BUILD_VERSION=42 -DMOBILECENTER_BUILD_VERSION=42 -p android clean :app:assembleAppCenterRelease :app:lintAppCenterRelease
...
> Task :app:lintVitalAppCenterRelease FAILED
Resolved com.android.tools.lint:lint-gradle:27.1.0 in :app:lintClassPath
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lintVitalAppCenterRelease'.
> Could not resolve all artifacts for configuration ':app:appCenterDebugRuntimeClasspath'.
> Failed to transform libs.jar to match attributes {artifactType=processed-jar, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for JetifyTransform: /.../build/app/intermediates/flutter/appCenterDebug/libs.jar.
> Transform's input file does not exist: /.../build/app/intermediates/flutter/appCenterDebug/libs.jar. (See https://issuetracker.google.com/issues/158753935)
The issue:
Transform's input file does not exist: /.../intermediates/flutter/appCenterDebug/libs.jar
I have come across this SO post: Generate signed apk fails with build\app\intermediates\flutter\profile\libs.jar (The system cannot find the path specified) which points to https://github.com/flutter/flutter/issues/58247#issuecomment-636500680
The "solution" there is to first run flutter build apk --debug
and then flutter build apk --release
This will in theory generate the intermediates
directory for both appCenterDebug
and appCenterRelease
with the required files.
Testing it locally by running gradlew lintAppCenterDebug
and then gradlew lintAppCenterRelease
works.
Both the flutter commands builds successfully.
The problem is with this line when gradle starts to run:
[command]/.../android/gradlew -DAPPCENTER_BUILD_VERSION=42 -DMOBILECENTER_BUILD_VERSION=42 -p android clean :app:assembleAppCenterRelease :app:lintAppCenterRelease
It does a clean in the command, which deletes the intermediates
directory (so this /.../appCenterDebug/libs.jar
does not exist anymore) and only builds the :app:...Release
versions. It then continues and breaks giving the input file does not exist
error.
How can this problem be resolved?
How is it possible to remove the clean
part from the gradle command? (I can't find it anywhere)
- I have tested this exact command locally, and breaks.
- Regenerate the
intermediates
content by running the two gradle lint commands - Run the same gradle command but without the
clean
and it works.
Debug, Release builds works fine locally and in appcenter(until gradle is run and removes the required files)
ADDITIONAL INFO
pubspec.yaml:
environment:
sdk: ">=2.12.0 <3.0.0"
gradle.properties
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
build.gradle
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
signingConfigs {
defaultKey {
/* truncated */
}
}
defaultConfig {
applicationId "com.example.app"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
signingConfig = signingConfigs.defaultKey
}
}
flavorDimensions "distribute"
productFlavors {
appCenter {
dimension "distribute"
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
gradle/wrapper/gradle-wrapper.properties
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip