0

I have written many E2E tests for an Android app which is developed with the Jetpack Compose way. I want to add those tests to my CI/CD pipeline on Microsoft Azure pipelines. After building and signing the app, I try to install AVD files, create and start the emulator in the background as it is posted on Microsoft azure documentations. I keep getting the following error about the XMLSchema.

Generating script.
========================== Starting Command Output ===========================
/bin/bash /Users/runner/work/_temp/be1cec62-f6f6-4aef-8d5c-4850153086aa.sh
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 5 more
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:213)
    at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:200)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
# Automatically trigger build when `main` or a `release/*` branch is updated.
# This ensures that we always have an up to date representation of `main` on
# App Center, and that `release` branches automatically build for convenience.
trigger:

  - release/*
  - main


pr:
  - '*'

variables:
  # Depending of the execution context the source branch location changes
  GIT_FULL_BRANCH_NAME: $[coalesce(variables['System.PullRequest.SourceBranch'], variables['Build.SourceBranch'])]

  # With trunk based development, release/* signifies the release branch
  IS_RELEASE_BRANCH: $[startsWith(variables['GIT_FULL_BRANCH_NAME'], 'refs/heads/release/')]

pool:
  vmImage: "macos-latest"

stages:
 - stage: buildAndDeploy
   displayName: "Build & Deploy to App Center"
   jobs:
    - job: "buildAndDeploy"
      steps:
        - task: UpdateAndroidVersionGradle@1
          inputs:
            buildGradlePath: "$(Build.SourcesDirectory)/app/build.gradle"
            versionName: "0.0.0"
            versionCode: $(Build.BuildId)
          displayName: "Set Version & Build Number"
          condition: eq(variables.IS_RELEASE_BRANCH, false)

        - task: PowerShell@2
          inputs:
            targetType: 'inline'
            script: |
              # Ensure that Java version 11 is used
              echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)"
              echo "##vso[task.setvariable variable=PATH]$(JAVA_HOME_11_X64)\bin;$(PATH)"
          displayName: "Set Java v11"

        - task: Gradle@2
          displayName: "Build APK"
          inputs:
            workingDirectory: ''
            gradleWrapperFile: 'gradlew'
            gradleOptions: '-Xmx3072m'
            publishJUnitResults: false
            tasks: 'clean build'

        - task: AndroidSigning@3
          displayName: "Sign APK"
          inputs:
            apkFiles: "$(Build.SourcesDirectory)/app/build/outputs/apk/release/app-release-unsigned.apk"
            apksign: true
            apksignerKeystoreFile: 'AppName-keystore.jks'
            apksignerKeystorePassword: '$(apksignerKeyPassword)'
            apksignerKeystoreAlias: 'AppName'
            apksignerKeyPassword: '$(apksignerKeyPassword)'
            apksignerArguments: "--out $(Build.SourcesDirectory)/app/build/outputs/apk/release/app-release-signed.apk"
            zipalign: false
          
        - bash: | 
            echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-28;google_apis;x86' 
            echo "AVD system-image successfully downloaded and installed." 
            displayName: 'Download and install emulator image' 
            condition: ne(variables.AVD_IMAGES_RESTORED, 'true')
              
        - bash: | 
            echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n android_emulator -k 'system-images;android-28;google_apis;x86' -d 17 --force 
            echo "Emulator created successfully $(ANDROID_HOME/emulator/emulator -list-avds), launching it" 
            nohup $ANDROID_HOME/emulator/emulator -avd android_emulator -skin 1080x1920 -no-snapshot -no-audio -no-boot-anim -accel auto -gpu auto -qemu -lcd-density 420 > /dev/null 2>&1 & 
            $ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done' 
            $ANDROID_HOME/platform-tools/adb devices echo "Emulator started" 
            displayName: 'Create and start emulator'
          
        - bash: | 
            ./gradlew connectedDebugAndroidTest --stacktrace 
            ./gradlew --stop 
          displayName: 'Run Instrumented Tests' 
          continueOnError: true
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
Karboon
  • 1
  • 1
  • i haven't used Jetpack Compose. but avove error message means you are missing schema information or you are missing class information in your xml. i can help more if you provide xml structure of your CI/CD with the question – Jake Jan 28 '22 at 07:26
  • Hi there, I am providing the following code on the post description. – Karboon Jan 28 '22 at 07:34
  • it also might be problem of mismatching Java Version. try upgrading your Java version. this link might help https://stackoverflow.com/questions/46402772/failed-to-install-android-sdk-java-lang-noclassdeffounderror-javax-xml-bind-a/51644855 – Jake Jan 28 '22 at 07:50
  • I tried the command tasks: 'assembleDebug' but I am getting error "##[error]Error: No matching files were found with search pattern: /Users/runner/work/1/s/app/build/outputs/apk/release/app-release-unsigned.apk " if i try to replace "tasks: 'clean build'" with tasks: 'assembleDebug' . – Karboon Jan 28 '22 at 08:08
  • of coarse azure didnot find that local path. you need to provide azure relative path for apkFiles. can you try replacing apkFiles with below line i.e. apkFiles: '$(Build.SourcesDirectory)/*/outputs/apk*.apk' – Jake Jan 28 '22 at 11:00
  • @Jake This is not the case. – Karboon Jan 31 '22 at 07:21

0 Answers0