LogoLogo
HomeDiscourseBlogDiscord
  • Introduction
  • Introduction
    • Quick start
    • Aurelia for new developers
    • Hello world
      • Creating your first app
      • Your first component - part 1: the view model
      • Your first component - part 2: the view
      • Running our app
      • Next steps
  • Templates
    • Template Syntax
      • Attribute binding
      • Event binding
      • Text interpolation
      • Template promises
      • Template references
      • Template variables
      • Globals
    • Custom attributes
    • Value converters (pipes)
    • Binding behaviors
    • Form Inputs
    • CSS classes and styling
    • Conditional Rendering
    • List Rendering
    • Lambda Expressions
    • Local templates (inline templates)
    • SVG
  • Components
    • Component basics
    • Component lifecycles
    • Bindable properties
    • Styling components
    • Slotted content
    • Scope and context
    • CustomElement API
    • Template compilation
      • processContent
      • Extending templating syntax
      • Modifying template parsing with AttributePattern
      • Extending binding language
      • Using the template compiler
      • Attribute mapping
  • Getting to know Aurelia
    • Routing
      • @aurelia/router
        • Getting Started
        • Creating Routes
        • Routing Lifecycle
        • Viewports
        • Navigating
        • Route hooks
        • Router animation
        • Route Events
        • Router Tutorial
        • Router Recipes
      • @aurelia/router-lite
        • Getting started
        • Router configuration
        • Configuring routes
        • Viewports
        • Navigating
        • Lifecycle hooks
        • Router hooks
        • Router events
        • Navigation model
        • Current route
        • Transition plan
    • App configuration and startup
    • Enhance
    • Template controllers
    • Understanding synchronous binding
    • Dynamic composition
    • Portalling elements
    • Observation
      • Observing property changes with @observable
      • Effect observation
      • HTML observation
      • Using observerLocator
    • Watching data
    • Dependency injection (DI)
    • App Tasks
    • Task Queue
    • Event Aggregator
  • Developer Guides
    • Animation
    • Testing
      • Overview
      • Testing attributes
      • Testing components
      • Testing value converters
      • Working with the fluent API
      • Stubs, mocks & spies
    • Logging
    • Building plugins
    • Web Components
    • UI virtualization
    • Errors
      • Kernel Errors
      • Template Compiler Errors
      • Dialog Errors
      • Runtime HTML Errors
    • Bundlers
    • Recipes
      • Apollo GraphQL integration
      • Auth0 integration
      • Containerizing Aurelia apps with Docker
      • Cordova/Phonegap integration
      • CSS-in-JS with Emotion
      • DOM style injection
      • Firebase integration
      • Markdown integration
      • Multi root
      • Progress Web Apps (PWA's)
      • Securing an app
      • SignalR integration
      • Strongly-typed templates
      • TailwindCSS integration
      • WebSockets Integration
      • Web Workers Integration
    • Playground
      • Binding & Templating
      • Custom Attributes
        • Binding to Element Size
      • Integration
        • Microsoft FAST
        • Ionic
    • Migrating to Aurelia 2
      • For plugin authors
      • Side-by-side comparison
    • Cheat Sheet
  • Aurelia Packages
    • Validation
      • Validation Tutorial
      • Plugin Configuration
      • Defining & Customizing Rules
      • Architecture
      • Tagging Rules
      • Model Based Validation
      • Validation Controller
      • Validate Binding Behavior
      • Displaying Errors
      • I18n Internationalization
      • Migration Guide & Breaking Changes
    • i18n Internationalization
    • Fetch Client
      • Overview
      • Setup and Configuration
      • Response types
      • Working with forms
      • Intercepting responses & requests
      • Advanced
    • Event Aggregator
    • State
    • Store
      • Configuration and Setup
      • Middleware
    • Dialog
  • Tutorials
    • Building a ChatGPT inspired app
    • Building a realtime cryptocurrency price tracker
    • Building a todo application
    • Building a weather application
    • Building a widget-based dashboard
    • React inside Aurelia
    • Svelte inside Aurelia
    • Synthetic view
    • Vue inside Aurelia
  • Community Contribution
    • Joining the community
    • Code of conduct
    • Contributor guide
    • Building and testing aurelia
    • Writing documentation
    • Translating documentation
Powered by GitBook
On this page
  • Prerequisites
  • Step 1: Create a Cordova Project
  • Step 2: Add Your Target Platform
  • Step 3: Create an Aurelia 2 Project
  • Step 4: Configure the Aurelia 2 Project
  • Step 5: Build the Aurelia 2 Application
  • Step 6: Build and Run the Cordova Application
  • Conclusion
  • Additional Tips and Best Practices
  • Using Cordova Plugins
  • Debugging and Live Reload

Was this helpful?

Export as PDF
  1. Developer Guides
  2. Recipes

Cordova/Phonegap integration

This guide will demonstrate how to integrate Aurelia 2 with Cordova/PhoneGap for mobile application development.

Prerequisites

Ensure you have the following installed:

  • Node.js and npm

  • Cordova CLI: npm install -g cordova

Step 1: Create a Cordova Project

Start by creating a new Cordova project:

cordova create aurelia-cordova com.example.aureliacordova AureliaCordova
cd aurelia-cordova

Step 2: Add Your Target Platform

Add the platforms you are targeting:

cordova platform add android
cordova platform add ios # Only for macOS

Step 3: Create an Aurelia 2 Project

Navigate to the www directory, which Cordova uses for the web application content. You'll want to clear its contents, as we will generate the Aurelia 2 app directly in this directory.

cd www
rm -rf *

Now, use npx makes aurelia with the --here flag to create a new Aurelia 2 project in the current directory without creating an additional folder:

npx makes aurelia --here

Step 4: Configure the Aurelia 2 Project

Configure your Aurelia 2 build process to output the files directly into the www directory. If you are using the default setup with Webpack, you may not need to change anything, as it already outputs to a dist folder inside the current directory. However, review your configuration to ensure it aligns with Cordova's structure.

Step 5: Build the Aurelia 2 Application

Build your Aurelia 2 application. The build process should place the output into the www directory.

# Follow the build steps for your specific Aurelia 2 setup
npm run build

Step 6: Build and Run the Cordova Application

After building your Aurelia application, navigate back to the root directory of your Cordova project. You can now build the Cordova app:

cd ..
cordova build

Run your application on an emulator or a connected device with the following command:

cordova emulate android
# or
cordova run android

Conclusion

You now have an Aurelia 2 application packaged within a Cordova application, ready for mobile deployment. Be sure to utilize Cordova plugins to access native device features and thoroughly test on different devices for performance and user experience.

Additional Tips and Best Practices

Using Cordova Plugins

To access native device functionalities (GPS, camera, file system, etc.), install the appropriate Cordova plugins. For example, to use the Cordova device plugin:

cordova plugin add cordova-plugin-device

Within your Aurelia application, you can create a service to interact with the plugin. For instance:

// src/services/device-service.js
export class DeviceService {
  getDeviceInfo() {
    if (window.device) {
      return {
        model: window.device.model,
        platform: window.device.platform,
        version: window.device.version,
      };
    }
    return null;
  }
}

Then inject and consume this service in your components as needed.

Debugging and Live Reload

While Cordova doesn't provide live reload by default, you can improve your development workflow by running Aurelia's development server (e.g., npm run start) and pointing your Cordova www folder to the build output or working with the local dev server. You can then:

  1. Make changes in your Aurelia application.

  2. Refresh the Cordova environment (or use a live reload plugin) to pick up changes quickly.

  3. Use your browser or remote debugging tools (like Chrome DevTools or Safari Web Inspector) to debug the Cordova application when running on an emulator or device.

PreviousContainerizing Aurelia apps with DockerNextCSS-in-JS with Emotion

Last updated 3 months ago

Was this helpful?