Revision 522663 of Quickstart guide to Gaia development

  • 리비전 슬러그: Mozilla/Firefox_OS/Hacking_Firefox_OS/Quickstart_guide_to_Gaia_development
  • 리비전 제목: Quickstart guide to Gaia development
  • 리비전 아이디: 522663
  • 제작일시:
  • 만든이: jryans
  • 현재 리비전인가요? 아니오
  • 댓글 Edited section headers.
태그: 

리비전 내용

This guide provides a very quick easy guide to developing Gaia apps, including running Gaia inside desktop Firefox. This guide assumes that you know HTML5 technologies, have knowledge of MVC patterns and have keen interest in Firefox OS.

Note: It's important to note that this is not a particularly accurate representation of the experience of using Boot to Gecko on a real mobile device. Many hardware interface features don't work, for example, and Firefox nightly builds may be unstable. But it is still a valid way to get some high level testing done.

What do you need?

  • First of all you need to have Git installed. If you prefer working in a visual environment, you might also consider installing the Github client (Github for Mac / Github for Windows). Git is essential for updating the code, promoting your changes, and seeing what other developers are working on.
  • Next, you need to fork the Mozilla Gaia repository: https://github.com/mozilla-b2g/gaia. After this is done, you should use a terminal to enter the repository (cd gaia) and then run the DEBUG=1 make command to configure Gaia correctly for debugging.
  • After you are done with setting up your workspace, you need to install the Nightly build of Firefox.
  • In that Nightly build, you need to have the Firefox Simulator Extension and App Manager Extension. The App Manager extension should be pre-installed in the nightly build, but you'll need to install the Firefox OS simulator.
  • You will need to install the ADB helper for debugging on the remote device, AKA your phone.
  • You might want to get a Firefox OS phone. It will show you various use information related to the start time of apps, frame rates, etc. Also, once you have the actual OS running on a device, you will be able to easily test all the supported device APIs.

Now that you have the basic workspace setup, lets get to the apps!

Firefox OS's default apps

The default HTML5 apps provided in the Gaia source code are as follows:

  • Bluetooth
  • Browser
  • Calendar
  • Camera
  • Clock
  • Communications
  • Cost Control
  • Dialer
  • FL
  • FM
  • Gallery
  • Homescreen
  • Keyboard
  • Music
  • PDF.js
  • Ringtones
  • Search
  • Setringtone
  • Settings
  • SMS
  • System
  • Video
  • Wallpaper
  • WAPPush

The first app that gets called up when the phone starts is the System app. This app is responsible for opening and managing the Home Screen app. From the Home Screen app,  you can call the other apps to perform various functions.  For example, the Dialer app gets called up from the Home Screen app when a user clicks on the phone icon. This Dialer app can then call the Contacts app when the user wants to see the list of contacts to dial.

Explore the Apps

The default apps are all contained in folders inside the gaia/apps/ folder. Each app folder will contain the following components :

  • manifest.webapp file: To store metadata about the app.
  • style folder: To store CSS files.
  • js folder: To store JavaScript files.
  • locales folder:  To store translated strings for different languages.
  • An HTML file: usually (but not limited to) index.html.

Some apps may also have:

  • elements folder: To store other views in HTML files.
  • test folder: To run the tests related to the application.
  • resources folder: Contains other resources such as movies, sounds, etc.
  • build folder.

There might also be some additional files like LazyLoaders and Customized Templating Engines and other utilities at work in a Firefox OS app. Just find the path to those files from the main HTML file, and try to figure out how they work. You may notice different JavaScript patterns in different apps or .js files. Remember, it is an open source app/OS, so it is coded by many different people.

If you are experienced in web development, you will aready have all you need to make some modifications to these apps. Get improving.

Fire Up the Apps

After you have made modifications to those applications, you might want to see the changes. You can either see it in the Firefox OS simulator, or on the physical device. To run the modified Gaia apps on the Firefox Simulator, you will have to run the following command.

/path/to/firefoxnightly -profile /Volumes/Mozilla/b2g/B2G/gaia/profile-debug -no-remote

On Mac OS X, for example, you should do:

/Applications/FirefoxNightly.app/Contents/MacOS/firefox -profile /path/to/B2G/gaia/profile-debug -no-remote

Note: -no-remote is needed to prevent reusing a running Firefox instance instead of creating a new one running the custom Gaia profile.

Running modified Gaia on a device takes a little more work. You will have to build all the things starting from B2G, then Gecko, and then Gaia. If you want to do it, then follow the steps on Building Firefox OS. It is a little easier however to just run the modified app itself in the App Manager, as sene below.

Debug the Broken Apps

After you are done building your app, you might want to debug it.

To do so, first of all get the App Manager and your physical device talking to one another, as shown in Using the App Manager.

Select the Contacts app (for example), then click on that debug button in your app section in the App Manager.

A card showing details of the Gaia contacts app: a simple contacts application.

This will not only run the app on a device, but it opens up the debug window as well. Test it out by adding console or debug logs.

A screenshot of the Mozilla App Manager

FAQ

The following subsections answer some common questions about debugging apps using Gaia on the desktop.

Note: Refer to Hacking gaia for more make options that can be set that are useful for Gaia debugging.

Can I emulate high resolution devices inside the Firefox desktop browser?

Yes.

  1. First of all, you can use the command
    GAIA_DEV_PIXELS_PER_PX=1.5 DEBUG=1 make
    to make sure the images look sharp on qHD and WVGA devices.
  2. Next, you can change browser density by opening the about:config page in Firefox and setting the layout.css.devPixelsPerPx flag to 1.5 .
  3. Last, you can use the Responsive Design View to 320 x 533 px (which is the equivalent CSS pixel dimensions to 480 x 800 device pixels.)

리비전 소스

<div class="summary">
 <p><span class="seoSummary">This guide provides a very quick easy guide to developing Gaia apps, including running Gaia inside desktop Firefox.</span> This guide assumes that you know HTML5 technologies, have knowledge of MVC patterns and have keen interest in Firefox OS.</p>
</div>
<div class="note">
 <p><strong>Note</strong>: It's important to note that this is not a particularly accurate representation of the experience of using Boot to Gecko on a real mobile device. Many hardware interface features don't work, for example, and Firefox nightly builds may be unstable. But it is still a valid way to get some high level testing done.</p>
</div>
<h2 id="What_do_you_need.3F">What do you need?</h2>
<ul>
 <li>First of all you need to have <a href="http://git-scm.com/book/en/Getting-Started-Installing-Git">Git installed</a>. If you prefer working in a visual environment, you might also consider installing the Github client (<a href="http://mac.github.com/">Github for Mac</a> / <a href="http://windows.github.com/">Github for Windows</a>). Git is essential for updating the code, promoting your changes, and seeing what other developers are working on.</li>
 <li>Next, you need to fork the Mozilla Gaia repository: <a href="https://github.com/mozilla-b2g/gaia">https://github.com/mozilla-b2g/gaia</a>. After this is done, you should use a terminal to enter the repository (<code>cd gaia</code>) and then run the <code>DEBUG=1 make</code> command to configure Gaia correctly for debugging.</li>
 <li>After you are done with setting up your workspace, you need to install the <a href="http://nightly.mozilla.org/">Nightly build of Firefox</a>.</li>
 <li>In that Nightly build, you need to have the Firefox Simulator Extension and App Manager Extension. The App Manager extension should be pre-installed in the nightly build, but you'll need to install the <a href="https://ftp.mozilla.org/pub/mozilla.org/labs/fxos-simulator/">Firefox OS simulator</a>.</li>
 <li>You will need to install the <a href="https://ftp.mozilla.org/pub/mozilla.org/labs/fxos-simulator/">ADB helper</a> for debugging on the remote device, AKA your phone.</li>
 <li>You might want to get a Firefox OS phone. It will show you various use information related to the start time of apps, frame rates, etc. Also, once you have the actual OS running on a device, you will be able to easily test all the supported device APIs.</li>
</ul>
<p>Now that you have the basic workspace setup, lets get to the apps!</p>
<h3 id="Firefox_OS's_default_apps">Firefox OS's default apps</h3>
<p>The default HTML5 apps provided in the Gaia source code are as follows:</p>
<ul>
 <li>Bluetooth</li>
 <li>Browser</li>
 <li>Calendar</li>
 <li>Camera</li>
 <li>Clock</li>
 <li>Communications</li>
 <li>Cost Control</li>
 <li>Dialer</li>
 <li>FL</li>
 <li>FM</li>
 <li>Gallery</li>
 <li>Homescreen</li>
 <li>Keyboard</li>
 <li>Music</li>
 <li>PDF.js</li>
 <li>Ringtones</li>
 <li>Search</li>
 <li>Setringtone</li>
 <li>Settings</li>
 <li>SMS</li>
 <li>System</li>
 <li>Video</li>
 <li>Wallpaper</li>
 <li>WAPPush</li>
</ul>
<p>The first app that gets called up when the phone starts is the System app. This app is responsible for opening and managing the Home Screen app. From the Home Screen app,&nbsp; you can call the other apps to perform various functions.&nbsp; For example, the Dialer app gets called up from the Home Screen app when a user clicks on the phone icon. This Dialer app can then call the Contacts app when the user wants to see the list of contacts to dial.</p>
<h2 id="Let.E2.80.99s_explore_some_apps">Explore the Apps</h2>
<p>The default apps are all contained in folders inside the <code>gaia/apps/</code> folder. Each app folder will contain the following components :</p>
<ul>
 <li><code>manifest.webapp</code> file: To store metadata about the app.</li>
 <li><code>style</code> folder: To store CSS files.</li>
 <li><code>js</code> folder: To store JavaScript files.</li>
 <li><code>locales</code> folder:&nbsp; To store translated strings for different languages.</li>
 <li>An HTML file: usually (but not limited to) <code>index.html</code>.</li>
</ul>
<p>Some apps may also have:</p>
<ul>
 <li><code>elements</code> folder: To store other views in HTML files.</li>
 <li><code>test</code> folder: To run the tests related to the application.</li>
 <li><code>resources</code> folder: Contains other resources such as movies, sounds, etc.</li>
 <li><code>build</code> folder.</li>
</ul>
<p>There might also be some additional files like LazyLoaders and Customized Templating Engines and other utilities at work in a Firefox OS app. Just find the path to those files from the main HTML file, and try to figure out how they work. You may notice different JavaScript patterns in different apps or .js files. Remember, it is an open source app/OS, so it is coded by many different people.</p>
<p>If you are experienced in web development, you will aready have all you need to make some modifications to these apps. Get improving.</p>
<h2 id="Lets_Fire_Up_These_Apps!">Fire Up the Apps</h2>
<p>After you have made modifications to those applications, you might want to see the changes. You can either see it in the Firefox OS simulator, or on the physical device. To run the modified Gaia apps on the Firefox Simulator, you will have to run the following command.</p>
<pre class="language-html" style="margin-top: 0.5em; margin-bottom: 0.5em; padding: 1em; border-width: 0px 0px 0px 6px; border-left-style: solid; border-left-color: rgba(0, 83, 159, 0.65098); background-image: url(https://developer.cdn.mozilla.net/media/redesign/img/blueprint-dark.png); background-color: rgba(234, 239, 242, 0.247059); font-size: 12px; font-family: Consolas, Monaco, 'Andale Mono', monospace; text-shadow: none; direction: ltr; tab-size: 4; background-position: 50% 0%; background-repeat: repeat repeat;">
/path/to/firefoxnightly -profile /Volumes/Mozilla/b2g/B2G/gaia/profile-debug -no-remote
</pre>
<p>On Mac OS X, for example, you should do:</p>
<pre class="brush: bash">
/Applications/FirefoxNightly.app/Contents/MacOS/firefox -profile /path/to/B2G/gaia/profile-debug -no-remote</pre>
<div class="note">
 <p><strong>Note:</strong> <code><em>-no-remote</em></code> is needed to prevent reusing a running Firefox instance instead of creating a new one running the custom Gaia profile.</p>
</div>
<p>Running modified Gaia on a device takes a little more work. You will have to build all the things starting from B2G, then Gecko, and then Gaia. If you want to do it, then follow the steps on <a href="/en-US/Firefox_OS/Building">Building Firefox OS</a>. It is a little easier however to just run the modified app itself in the App Manager, as sene below.</p>
<h2 id="Let.E2.80.99s_Debug_Those_Broken_Apps!">Debug the Broken Apps</h2>
<p>After you are done building your app, you might want to debug it.</p>
<p>To do so, first of all get the App Manager and your physical device talking to one another, as shown in <a href="/en-US/Firefox_OS/Using_the_App_Manager">Using the App Manager</a>.</p>
<p>Select the Contacts app (for example), then click on that debug button in your app section in the App Manager.</p>
<p><img alt="A card showing details of the Gaia contacts app: a simple contacts application." src="https://mdn.mozillademos.org/files/7135/contacts-app-screenshot.png" style="width: 868px; height: 358px; display: block; margin: 0px auto;" /></p>
<p>This will not only run the app on a device, but it opens up the debug window as well. Test it out by adding console or debug logs.</p>
<p><img alt="A screenshot of the Mozilla App Manager" src="https://mdn.mozillademos.org/files/7137/debugger.png" style="width: 700px; height: 357px; display: block; margin: 0px auto;" /></p>
<h2 id="FAQ">FAQ</h2>
<p>The following subsections answer some common questions about debugging apps using Gaia on the desktop.</p>
<div class="note">
 <p><strong>Note</strong>: Refer to <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS/Platform/Gaia/Hacking#High_resolution_image_assets" title="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS/Platform/Gaia/Hacking#High_resolution_image_assets">Hacking gaia</a> for more make options that can be set that are useful for Gaia debugging.</p>
</div>
<h3 id="Can_I_emulate_high_resolution_devices_inside_the_Firefox_desktop_browser.3F">Can I emulate high resolution devices inside the Firefox desktop browser?</h3>
<p>Yes.</p>
<ol>
 <li>First of all, you can use the command
  <pre class="language-html">
GAIA_DEV_PIXELS_PER_PX=1.5 DEBUG=1 make</pre>
  to make sure the images look sharp on qHD and WVGA devices.</li>
 <li>Next, you can change browser density by opening the <a href="https://developer.mozilla.org/about:config" title="/about:config">about:config</a> page in Firefox and setting the <code>layout.css.devPixelsPerPx</code> flag to <code>1.5</code> .</li>
 <li>Last, you can use the <a href="/en-US/docs/Tools/Responsive_Design_View">Responsive Design View</a> to 320 x 533 px (which is the equivalent CSS pixel dimensions to 480 x 800 device pixels.)</li>
</ol>
현재 리비전 복원