'Azure DevOps iOS and Android React Native Build Failing on Pod Install and Gradle Build Steps

I am trying to create CI/CD pipeline, for iOS and android, in Azure Devops for a React-Native app.

With the android pipeline, whether I choose to create a yaml or use the classic editor and use pre-configured android tasks, the pipeline always fails on the build task (bundleRelease). The error I receive is:

FAILURE: Build failed with an exception.
  • Where: Settings file '/home/vsts/work/1/s/app-rn/android/settings.gradle' line: 12

  • What went wrong: A problem occurred evaluating settings 'iEquos'.

Could not read script '/home/vsts/work/1/s/app-rn/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' as it does not exist.

  • 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

BUILD FAILED in 12s Error: The process '/home/vsts/work/1/s/app-rn/android/gradlew' failed with exit code 1 at ExecState._setResult (/home/vsts/work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/2.200.2/node_modules/azure-pipelines-task-lib/toolrunner.js:944:25) at ExecState.CheckComplete (/home/vsts/work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/2.200.2/node_modules/azure-pipelines-task-lib/toolrunner.js:927:18) at ChildProcess. (/home/vsts/work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/2.200.2/node_modules/azure-pipelines-task-lib/toolrunner.js:840:19) at ChildProcess.emit (events.js:198:13) at maybeClose (internal/child_process.js:982:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5) ##[error]Error: The process '/home/vsts/work/1/s/app-rn/android/gradlew' failed with exit code 1 Finishing: Gradle

This is line being referred to in android/settings.gradle:

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings, "../")

The node modules folder is in the 'app-rn' directory, at the same level as the "android" folder, so only using one "../" is correct?

I can build the android solution locally through a termianl or using Android studio so I am completely clueless to why this is occurring in DevOps.

A similar issue is occurring with my pipeline for iOS. The issue is occurring when istalling Cocoa Pods:

DevOps Install Cocoa Pods Error

Here is an image of my PodFile, located in the 'iOS' folder. The 'iOS' folder is located at the same level as 'node-modules', both inside a folder 'app-rn':

Podfile

Here is the yaml for android:

# 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
variables:
  - group: DriverApp

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

name: $(date:yyyy).$(Month)$(rev:.r)

steps:

- script: yarn install

- task: Gradle@2
  inputs:
    gradleWrapperFile: 'app-rn/android/gradlew'
    workingDirectory: 'app-rn/android/'
    options: '-PversionName=$(Build.BuildNumber) -PversionCode=$(Build.BuildId)'
    tasks: 'bundleRelease'
    publishJUnitResults: false
    javaHomeOption: 'JDKVersion'
    gradleOptions: '-Xmx3072m'
    sonarQubeRunAnalysis: false

- task: AndroidSigning@3
  inputs:
    apkFiles: '**/*.aab'
    apksignerKeystoreFile: 'keystore.jks'
    apksignerKeystorePassword: '$(AndroidKeyStorePassword)'
    apksignerKeystoreAlias: '$(AndroidKeyAlias)'
    apksignerKeyPassword: '$(AndroidKeyAliasPassword)'
    zipalign: false

- task: PublishBuildArtifacts@1
  inputs:
    # PathtoPublish: 'android/app/build/outputs/apk/release'
    PathtoPublish: 'android/app/build/outputs/'
    ArtifactName: 'drop'
    publishLocation: 'Container'

The yaml for iOS:

# trigger:
#   branches:
#     include:
#       - master
variables:
  - group: DriverApp
pool:
  vmImage: 'macos-latest'
steps:
  - checkout: self
    persistCredentials: true
    clean: true
  - task: NodeTool@0
    displayName: 'Install Node'
    inputs:
      versionSpec: '12.19.0' # you can use your desired version here
      # workingDirectory: 'app-rn/'
  - script: yarn install
    displayName: Install Dependencies
  - task: InstallAppleCertificate@2
    displayName: Install Apple Certificate
    inputs:
      certSecureFile: 'AppleDistributionCertificate.p12'
      certPwd: '$(AppleCertificatePassword)'
      keychain: 'temp'
      deleteCert: true
  - task: InstallAppleProvisioningProfile@1
    displayName: 'Install Apple Provisioning Profile'
    inputs:
      provisioningProfileLocation: 'secureFiles'
      provProfileSecureFile: 'iEquos_App_Store.mobileprovision'
      removeProfile: true
  - task: CocoaPods@0
    displayName: 'Install CocoaPods'
    inputs:
      workingDirectory: 'app-rn/ios'
  - task: Xcode@5
    displayName: 'Build IPA'
    inputs:
      actions: 'build'
      configuration: 'Release'
      sdk: 'iphoneos'
      xcWorkspacePath: 'app-rn/ios/iEquos.xcworkspace'
      scheme: 'iEquos'
      packageApp: true
      exportPath: 'output'
      signingOption: 'manual'
      signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
      provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)'
  - task: CopyFiles@2
    displayName: 'Copy IPA'
    inputs:
      contents: '**/*.ipa'
      targetFolder: '$(build.artifactStagingDirectory)'
      overWrite: true
      flattenFolders: true
  - task: PublishBuildArtifacts@1
    displayName: 'Publish IPA to artifacts'
    inputs:
      PathtoPublish: '$(build.artifactStagingDirectory)'
      ArtifactName: 'ios'
      publishLocation: 'Container'

I have searched stackoverflow for similar issues, but only seem to find people running into these issues locally, nto within DevOps. As I mentioned before, I can build the android and iOS app locally.

I am fairly new to posting on stack overflow so please let me know if I should provide anymore information.

Any help would be greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source