Skip to content

Brand new app with mlkit-core fails to build for iOS #64

Open

Description

@andrewm-mitchells

Steps to reproduce:

  1. Generate new project with drawer template NG ns create ml-kit-test --template @nativescript/template-drawer-navigation-ng
  2. Run npm i @nativescript/mlkit-core
  3. Run ns build iOS

At this point you'd get the following error:
Command xcodebuild failed with exit code 65

ns info:

Component nativescript has 8.8.0 version and is up to date.
✔ Component @nativescript/core has 8.8.1 version and is up to date.
✔ Component @nativescript/ios has 8.8.1 version and is up to date.
✖ Component @nativescript/android is not installed.

package.json:

{
  "name": "ml-kit-test",
  "main": "src/main.ts",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "@angular/animations": "~18.0.0",
    "@angular/common": "~18.0.0",
    "@angular/compiler": "~18.0.0",
    "@angular/core": "~18.0.0",
    "@angular/forms": "~18.0.0",
    "@angular/platform-browser": "~18.0.0",
    "@angular/platform-browser-dynamic": "~18.0.0",
    "@angular/router": "~18.0.0",
    "@nativescript/angular": "^18.0.0",
    "@nativescript/core": "~8.8.0",
    "@nativescript/mlkit-core": "^2.1.0",
    "@nativescript/theme": "~3.0.2",
    "nativescript-ui-sidedrawer": "~15.2.0",
    "rxjs": "~7.8.0",
    "zone.js": "~0.14.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~18.0.0",
    "@angular/compiler-cli": "~18.0.0",
    "@nativescript/ios": "8.8.1",
    "@nativescript/types": "~8.8.0",
    "@nativescript/webpack": "~5.0.0",
    "@ngtools/webpack": "~18.0.0",
    "typescript": "~5.4.0"
  }
}

Activity

  1. andrewm-mitchells commented on Jul 22, 2024

    @andrewm-mitchells
    Author

    This bug makes it impossible to use a barcode scanner on nativescript currently as other solutions like https://market.nativescript.org/plugins/@nstudio/nativescript-barcodescanner/ are also out of date and won't function properly

  2. ShimonKh commented on Nov 3, 2024

    @ShimonKh

    same issue. Any updates?

  3. omarmfs98 commented on Jul 4, 2025

    @omarmfs98

    I tried using version 1.0.6 for iOS and 3.0.0 for Android, and it works perfectly. To test, you can add a script before compiling in the nativescript.config.ts file, for example:

    hooks: [
        {
          type: 'before-prepare',
          script: 'scripts-hook/mlkit-before-prepare.js',
        },
      ]
    

    script:

    module.exports = function ($logger, $platformsDataService, $projectData, hookArgs) {
      return new Promise(async (resolve, reject) => {
        const { execSync } = require('child_process')
    
        const platform = hookArgs.prepareData.platform
        const currentEnvironment = hookArgs.prepareData.env.prod || hookArgs.prepareData.env.production ? 'prod' : 'dev'
    
        $logger.info(`[MLKit Hook] before-prepare ${platform} - environment: ${currentEnvironment}`)
    
        try {
          const platformVersions = {
            android: {
              '@nativescript/mlkit-barcode-scanning': '3.0.0',
              '@nativescript/mlkit-core': '3.0.0',
            },
            ios: {
              '@nativescript/mlkit-barcode-scanning': '1.0.6',
              '@nativescript/mlkit-core': '1.0.6',
            },
          }
    
          const versions = platformVersions[platform]
          if (!versions) {
            $logger.info(`[MLKit Hook] No specific versions defined for platform: ${platform}`)
            resolve(true)
            return
          }
    
          $logger.info(`[MLKit Hook] Installing MLKit dependencies for ${platform}...`)
    
          Object.entries(versions).forEach(([packageName, version]) => {
            try {
              $logger.info(`[MLKit Hook] Installing ${packageName}@${version} for ${platform}...`)
              execSync(`npm install ${packageName}@${version} --legacy-peer-deps`, {
                cwd: $projectData.projectDir,
                stdio: 'inherit',
              })
              $logger.info(`[MLKit Hook] Successfully installed ${packageName}@${version}`)
            } catch (error) {
              $logger.error(`[MLKit Hook] Failed to install ${packageName}@${version}: ${error.message}`)
            }
          })
    
          $logger.info(`[MLKit Hook] MLKit setup completed for ${platform}`)
          resolve(true)
        } catch (error) {
          $logger.error(`[MLKit Hook] Error: ${error.message}`)
          reject(error)
        }
      })
    }
    
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions