0
votes

I have an Android project which uses an aar file. It contains flutter code previously built. In my gradle file there is a relative path to the aar:

...
repositories {
    maven { url '\''https://maven.fabric.io/public'\'' }
    maven { url '\''https://jitpack.io'\'' }
    maven { url '\''../../flutter_aar/build/host/outputs/repo'\''}
    maven { url '\''https://storage.googleapis.com/download.flutter.io'\''}
    flatDir(dirs: '\''libs'\'')
}
...

Building project locally everything works fine. Now I'm using azure pipelines to build both projects. My yaml on azure is this:

# Android
# Build your Android project with Gradle.
# Add steps that test, sign, and distribute the APK, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/android
trigger:
  batch: true
  branches:
    include:
      - release-version-3.0
    exclude:
      - bug-*
      - master
      - develop

pool:
  vmImage: 'macos-latest'

variables: 
- group: TestApp.Mobile
- name: PAT
- name: FLUTTER_VERSION

steps:
- task: JavaToolInstaller@0
  displayName: Install JDK
  inputs:
    versionSpec: '8'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: 'PreInstalled'

- checkout: self
  submodules: true
  
- bash: |
   set -e
   set -x

   git clone -b 1.22.2 --single-branch https://github.com/flutter/flutter.git
   export PATH=`pwd`/flutter/bin:$PATH

   B64_PAT=$(printf ":generated_pat" | base64)

   git config --global credential.helper store
   git config --global user.name "test_user"
   git config --global http.extraheader "Authorization: Basic ${B64_PAT}"
   git clone -b development https://[email protected]/base_arch/_git/flutter_aar
   cd flutter_aar
   
   flutter pub upgrade
   flutter build aar

   pwd
   ls -la

   cd ..
   pwd
   ls -la
   echo "$(cat app/build.gradle)"
  displayName: Build AAR

- task: Gradle@2
  displayName: Build Android App
  inputs:
    workingDirectory: '$(Build.SourcesDirectory)'
    gradleWrapperFile: 'gradlew'
    gradleOptions: '-Xmx3072m'
    publishJUnitResults: false
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'assembleHomoProfile'

When the Gradle@2 task is executed build fails because it cannot locate project.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileHomoProfileJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:homoProfileCompileClasspath'.
   > Could not find com.project.flutter_aar:flutter_profile:1.0.
     Required by:
         project :app

* 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.

I checked if the project is there and if it was generated doing a single ls -la. Files are ok but the gradle build insists to fail on locate them. Is there another configuration or task do I need to do?

I've read the links:

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/publish-build-artifacts?view=azure-devops

1

1 Answers

1
votes

The folder structure in azure agent might be different with your local machine. This will cause the relative path you defined in gradle file doesnot work in azure agent.

You probably already know that the default current working directory(ie. System.DefaultWorkingDirectory) is the s folder(ie. c:\agent_work\1\s) for all the pipeline tasks. Your Android project source codes will be download in this s folder.

In above pipeline. The bash task will clone and build flutter_aar project in the s folder too, which means the flutter_aar project will be cloned within your Android project as a subdirectory. The folder structure is like below:

- s(Android project)
  - flutter_aar
  

If the flutter_aar project and Android project is under the same level on your local machine like below:

- Mainfolder
  - flutter_aar
  - Android project

Then the gradle task will not be able to locate project in the azure agent machine.

If it is the case for this issue. You can have a try with below workarounds:

1, Change the working directory of Bash task to upper level of the s folder, which is Agent.BuildDirectory ie. c:\agent_work\1. See below:

- bash: |
   cd "$(Agent.BuildDirectory)"
   set -e
   set -x
   ...

2, Or you can try changing the relative path in gradle file to maven { url '\''../flutter_aar/build/host/outputs/repo'\''}