Leanpub Header

Skip to main content

Native Mobile Apps With Elixir

From Your First Screen to Production Withou Leaving the Beam

Native Mobile Apps With Elixir

Build a real, offline-first Android app in Elixir with Mob, from mix mob.new to an APK in your testers' hands, without leaving the BEAM.

Minimum price

$49.99

$59.99

You pay

Author earns

$

Also available for 2 book credits with a Reader Membership

PDF
EPUB
WEB
APP
About

About

About the Book

You know Elixir. You've built things with Phoenix and LiveView. Then your users ask for an app on their phone, and the usual answer is to step out of the BEAM: Kotlin, Swift, or React Native and a JavaScript toolchain, plus a second codebase to keep in step.

This book takes the other road. Mob puts the BEAM itself on the phone and draws a real native UI from your Elixir code: no server round trip for a tap, no JavaScript bridge.

We use it to build one app from an empty screen to production: Risiti, an expense app for teams in Kenya. Risiti photographs receipts, reads them on the phone, checks them against the Kenya Revenue Authority, works offline, and syncs with a Phoenix and Ash server where managers approve expenses, refunds and payment requests.

Along the way you will learn to:

  • set up an Android workbench and run Elixir on your own phone;
  • build screens, navigation, layouts, themes and lists with Mob, tied at every step to what you already know from LiveView;
  • keep data on the phone with SQLite and Ecto, and test screens without a phone attached;
  • use the camera, a fingerprint lock, on-device OCR and QR scanning;
  • write your own native plugin in Zig and Kotlin when Mob doesn't have what you need;
  • build the server with Phoenix and Ash: accounts, multi-tenant teams, approvals, background jobs and a web dashboard;
  • sync both ways over a bad connection, and send push notifications;
  • ship a signed release APK, and deploy the server to your own domain.

Every chapter ends with something you can run on your phone, and the code for each one is in the book's repository, with tests. Where something broke on a real phone, the chapter says so and shows the fix.

It's written for Elixir developers who have never shipped a mobile app. Words like APK, ADB or "back stack" are explained the first time they appear. If you have written a LiveView, you are closer to writing a mobile screen than you think.

Author

About the Author

Kamaro Lambert

A tech lead and full-stack Elixir engineer with more than 18 years of shipping production software. He worked in telecom, health care, logistics, retail(e-commerce), finance institutions including fin-tech, and core banking systems. He is the author of Ash Framework for Phoenix Developers and Native Mobile Apps with Elixir, has written more than 196 articles on Medium, and published ash_parental on Hex.

Contents

Table of Contents

Preface

  1. Who this book is for
  2. What we will build
  3. What “by hand” means
  4. Why a book, when you can ask an AI?
  5. How to read this book
  6. What you need

Chapter 1: Elixir on the Phone

  1. Native, web and everything in between
  2. The price we used to pay
  3. What Mob does differently
  4. What runs on the phone
  5. Why this is good news for us
  6. An honest word about maturity
  7. What we will build

Chapter 2: Your Android Workbench

  1. What we are installing, and why
  2. Step 1: Prepare the phone
  3. Step 2: Elixir, Hex and the Mob generator
  4. Step 3: Create the app
  5. Step 4: Install Java
  6. Step 5: Install the Android SDK
  7. Step 6: Install Zig
  8. Step 7: First-run Mob install, then check the toolchain
  9. Step 8: Connect the phone and deploy
  10. The daily loop
  11. When it doesn’t start
  12. What we have so far

Chapter 3: Your First Screen

  1. A screen is a process
  2. Writing the screen
  3. The ~MOB sigil
  4. The starting screen
  5. Run it
  6. A test, without a phone
  7. What we have so far

Chapter 4: Moving Between Screens

  1. The navigation stack
  2. From a tap to your code
  3. Adding the buttons
  4. Push and pop
  5. Adding the form and settings screens
  6. Run it
  7. The back gesture is free
  8. Testing navigation
  9. Other ways to move
  10. What we have so far

Chapter 5: Passing Parameters Between Screens

  1. Putting the ID in the tap
  2. Three receipts to tap
  3. Sending the params
  4. Receiving the params
  5. Run it
  6. Testing it
  7. Don’t pass the whole receipt
  8. What we have so far

Chapter 6: Columns, Rows and Boxes

  1. What we’re building
  2. The containers
  3. A word about sizes
  4. The new receipts screen
  5. Run it
  6. When a layout looks wrong
  7. Updating the test
  8. What we have so far

Chapter 7: Colours, Type and Themes

  1. Tokens, not colours
  2. Risiti’s theme
  3. Making it the app’s theme
  4. The dark green spend card
  5. Typography
  6. Letting the user choose
  7. Run it
  8. Testing it
  9. What we have so far

Chapter 8: Lists That Scroll

  1. Why lists are special
  2. The expense book
  3. The list screen
  4. Filtering with pills
  5. Run it
  6. Testing lists
  7. A tip: mix format knows ~MOB
  8. What we have so far

Chapter 9: Components of Your Own

  1. Way one: a function that returns UI
  2. Way two: a composite
  3. The header
  4. The receipt card
  5. The action button
  6. Registering the composites
  7. Using them
  8. Run it
  9. Testing components
  10. What about stateful components?
  11. What we have so far

Chapter 10: Testing Without a Phone

  1. Three tiers
  2. The ScreenCase toolbox
  3. What to test on a screen
  4. One test for every screen
  5. async: true or async: false?
  6. The tier on the phone
  7. What we have so far

Chapter 11: Remembering Things

  1. Three kinds of state
  2. Meet Mob.State
  3. An Appearance module
  4. Using it in Settings
  5. Applying it at startup
  6. Run it
  7. Testing it
  8. A note on screen state
  9. What we have so far

Chapter 12: A Database on the Phone

  1. Why SQLite
  2. What the generator gave us
  3. Migrations on a phone
  4. The transactions table
  5. The schema
  6. The context
  7. Pointing the screens at the database
  8. Run it
  9. Testing against SQLite
  10. What we have so far

Chapter 13: The Receipt Form

  1. How a text field talks to you
  2. A field component
  3. The right keyboard
  4. The form screen
  5. Choosing a category with a sheet
  6. Saving
  7. Deleting
  8. Wiring it up
  9. Run it
  10. Testing it
  11. What we have so far

Chapter 14: Taking the Photo

  1. Plugins
  2. Permissions
  3. One module for every device call
  4. Asking for the camera
  5. Where photos live
  6. A column for the photo
  7. The form, with a photo
  8. The photo in the list
  9. Run it
  10. Testing hardware without hardware
  11. What we have so far

Chapter 15: The Photo and the Lock

  1. A full-screen photo, without a new screen
  2. Saving to the gallery
  3. A fingerprint lock
  4. Run it
  5. Testing it
  6. What we have so far
  7. The end of Part I

Chapter 16: The Whole Picture

  1. Three types, one transaction
  2. The rule: the phone owns the figures, the server owns the decisions
  3. The stack
  4. The map of the code
  5. Where we go from here
  6. What we have so far

Chapter 17: The Whole Transaction

  1. One more migration
  2. The schema
  3. client_id
  4. The context
  5. Run it
  6. Testing it
  7. What we have so far

Chapter 18: The Home Screen, Finished

  1. Asking the phone, through Native
  2. The month picker
  3. Search
  4. Date periods
  5. Refunds and payments
  6. Status on the card
  7. The details sheet
  8. Wiring it up
  9. Run it
  10. Testing it
  11. What we have so far

Chapter 19: Reading a Receipt

  1. Why on the phone
  2. The mob_ocr plugin
  3. What OCR gives back
  4. Finding the total
  5. Finding the date and vendor
  6. Testing a parser
  7. Filling only what the person hasn’t touched
  8. Retake, remove, add later
  9. Run it
  10. Testing it
  11. What we have so far

Chapter 20: KRA Receipts

  1. What’s in a KRA QR code
  2. Scanning
  3. Fetching KRA’s record
  4. Verifying in the background
  5. KRA wins
  6. Run it
  7. Testing it
  8. What we have so far

Chapter 21: Refunds, Payment Requests and Attachments

  1. Turning an expense into a refund
  2. Payment requests
  3. Attachments
  4. Editing after sending
  5. Personal books
  6. Run it
  7. Testing it
  8. What we have so far

Chapter 22: Writing a Native Plugin

  1. Anatomy of a Mob plugin
  2. The Elixir side
  3. The Zig NIF
  4. The Kotlin bridge
  5. Back to Elixir
  6. Wiring it into the build
  7. Run it
  8. Testing it
  9. What we have so far

Chapter 23: A PDF on the Phone

  1. What the report holds
  2. Writing a PDF in Elixir
  3. The report
  4. Doing it off the screen
  5. Opening it
  6. Run it
  7. Testing it
  8. What we have so far
  9. The end of Part II

Chapter 24: Starting the Server

  1. Why Ash
  2. A new project
  3. Teams as tenants
  4. The domains
  5. Migrations, twice
  6. Run it
  7. Testing tenants
  8. What we have so far

Chapter 25: Accounts

  1. Who signs in, and how
  2. Signing in with a phone
  3. Signing in with Google
  4. Signing up
  5. Personal books and business teams
  6. User roles
  7. The API for signing in
  8. Run it
  9. Tests
  10. What we have so far

Chapter 26: Transactions and Approvals

  1. The resource
  2. Actions
  3. Changes
  4. Validations
  5. Policies
  6. An audit trail
  7. Moving old data
  8. Run it
  9. Tests
  10. What we have so far

Chapter 27: The Mobile API

  1. The shape of the API
  2. Errors the phone can act on
  3. Transactions
  4. Approvals and /api/me
  5. Run it
  6. Tests
  7. What we have so far

Chapter 28: Work in the Background

  1. Why a job queue
  2. Installing Oban
  3. The SMS worker
  4. Email
  5. Push notifications
  6. Every night
  7. Run it
  8. Tests
  9. What we have so far

Chapter 29: The Web Side

  1. Signing in on the web
  2. Approvals
  3. Transactions
  4. Reading uploads on the server
  5. Exports for accountants
  6. Run it
  7. Tests
  8. What we have so far

Chapter 30: Signing In from the Phone

  1. The profile
  2. Talking to the server
  3. Running network calls off the screen
  4. The sign-in screen
  5. Tests
  6. Run it
  7. What we have so far

Chapter 31: Two-Way Sync

  1. One run, four steps
  2. What the phone remembers
  3. The API calls
  4. RisitiApp.Sync
  5. Idempotency
  6. Photos and attachments
  7. One run at a time
  8. When to sync
  9. Tests
  10. Run it
  11. What we have so far

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub