simple_eif_phone

Write an Android app in Eiffel, and get a signed APK from one command.

MIT License Android 8.0 or later Design by Contract

Commands

eifphone doctor                                       # are all the tools there?
eifphone new myapp --id io.github.me.myapp --label "My App"
eifphone build myapp                                  # signed APK in myapp/build/
eifphone run myapp                                    # install on the device, start, show the log
eifphone log myapp --crash                            # crash lines only
eifphone test examples/phone_tests                    # on-device tests (start drive.sh first)

Options:

eifphone new     <dir> --id <app.id> [--label <text>]
eifphone build   [<dir>] [--abi arm64-v8a|x86_64] [--clean]
eifphone install [<dir>] [--device <serial>]
eifphone run     [<dir>] [--device <serial>]
eifphone log     [<dir>] [--crash] [--device <serial>]
eifphone test    [<dir>] [--device <serial>]

Exit codes

CodeMeaning
0OK
1a tool is missing, or a test failed
2bad arguments or an invalid project
3a version pin doesn't match
4a build stage failed (the stage and its first error are printed)
5a device or install problem

A first app

class APP_MAIN
inherit PHONE_EVENT_KIND
create make
feature {NONE}
	make
		do
			create phone.make
			from until phone.lifecycle.is_destroyed loop
				phone.wait_for_event        -- Eiffel owns the loop; no callbacks
				inspect phone.last_event.kind
				when Kind_window_ready, Kind_window_resized, Kind_redraw_needed then draw
				when Kind_touch_down then phone.log.info (phone.last_event.out_line)
				else
				end
			end
		end

	draw
		do
			if phone.screen.has_window then
				phone.screen.begin_frame     -- Android may refuse: check in_frame
				if phone.screen.in_frame then
					phone.screen.fill_rect (0, 0, phone.screen.width, phone.screen.height, 0x14161C)
					phone.screen.end_frame
				end
			end
		end

	phone: SIMPLE_EIF_PHONE
end

What the phone object gives you

CallGives you
phone.wait_for_event, phone.poll_event (ms)The next event, in phone.last_event
phone.lifecycleStarted, resumed, has a window, has focus, destroyed
phone.touchesEvery finger now down, by pointer id
phone.screenFrames: begin_frame, fill_rect, present_argb, end_frame
phone.metricsSize, density, system-bar insets, dp
phone.storageThe app's private folder, and its external folder if there is one
phone.assetsFiles packed into the APK
phone.logLines to the Android log
phone.set_back_policy, set_keep_screen_on, finishBack key, screen timeout, leaving the app

Every feature and contract is in the API Reference.