How to create an apk in a pipeline on dev.azure.com

0
Hi, I'm trying to build an apk in an azure devops pipeline for the first time. Together with chatgpt I tried to make one, but failed. Does anyone hase a working yml file to create an apk?   What I made with chatgpt is shown here (but it gives an error):   trigger: branches: include: - master # Ensure this matches your actual branch name pool: vmImage: 'ubuntu-latest' # Use Ubuntu as the build environment variables: androidHome: '/opt/android-sdk-linux' # Define any necessary variables explicitly jdkVersion: '21' # Define Java version if necessary androidSdkVersion: '34.0.1' # Example Android SDK version steps: # Step 1: Checkout the repository - task: Checkout@1 # Use version 1 of the Checkout task displayName: 'Checkout repository' # Step 2: Install JDK - script: | sudo apt-get update sudo apt-get install -y openjdk-21-jdk # Install JDK 21 java -version # Verify Java installation displayName: 'Install JDK 21' # Step 3: Install Android SDK - script: | mkdir -p $(androidHome) wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip -P $(androidHome) unzip $(androidHome)/commandlinetools-linux-7583922_latest.zip -d $(androidHome) rm $(androidHome)/commandlinetools-linux-7583922_latest.zip yes | $(androidHome)/cmdline-tools/bin/sdkmanager --sdk_root=$(androidHome) "platform-tools" "build-tools;30.0.3" "platforms;android-30" # Modify versions if necessary displayName: 'Install Android SDK' # Step 4: Add Android SDK tools to PATH - script: | echo "export ANDROID_HOME=$(androidHome)" >> $BASH_ENV echo "export PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/bin:$PATH" >> $BASH_ENV displayName: 'Set up Android SDK Path' # Step 5: Build APK (unsigned) - script: | ./gradlew assembleDebug # Builds the unsigned APK (debug version) displayName: 'Build unsigned APK' # Step 6: Publish the artifact (optional) - task: PublishBuildArtifacts@1 inputs: pathToPublish: '$(Build.SourcesDirectory)/app/build/outputs/apk/debug' # Adjust path if necessary artifactName: 'apk-artifacts' displayName: 'Publish APK artifact'      
asked
2 answers
0

My colleague Bas Jonker wrote a blog post about getting this to work, hopefully that'll help you get started!

 

https://medium.com/@bas.jonker/mendix-native-builds-with-azure-pipelines-d421c0c67ff7

answered
0

Thanks Eline,

I still got some gradle errors, but I am very glad that your info helped me in this process. Tjis is the yaml so far, not working but almost there I think:

 

trigger:

- master

pool:

  vmImage: macos-latest

steps:

- task: CmdLine@2

  inputs:

    script: |

      echo Write your commands here

      

      /usr/libexec/java_home -V

- task: UseNode@1

  inputs:

    version: '18.x'

- task: Npm@1

  inputs:

    command: 'install'

- task: Npm@1

  inputs:

    command: 'custom'

    customCommand: 'run configure'

- task: Gradle@4

  inputs:

    gradleWrapperFile: 'android/gradlew'

    options: 'clean build'

    workingDirectory: 'android'

    tasks: 'devDebug'

    publishJUnitResults: false

    javaHomeOption: '1.21'

    jdkVersionOption: '1.21' # Specify the JDK version you need

    jdkUserInputPath: '/Users/runner/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.6-7.0/x64/Contents/Home' # Specify the path to your JDK installation

- task: CopyFiles@2

  inputs:

    SourceFolder: '**/*.apk'

    Contents: '**'

    TargetFolder: '$(Build.ArtifactStagingDirectory)'

    sonarQubeRunAnalysis: false

    spotBugsAnalysis: false

- task: PublishBuildArtifacts@1

  inputs:

    PathtoPublish: '$(Build.ArtifactStagingDirectory)'

    ArtifactName: 'drop'

    publishLocation: 'Container'

answered