Confirmed users
400
edits
| Line 1: | Line 1: | ||
<h1> Native Sync </h1> | |||
<h2> Setup </h2> | |||
<p><a href="Mobile/Fennec/Android OtherBuildEnvs#Mac_OSX"> Setting up an Android dev environment</a> | |||
</p> | |||
<ul><li> note: installing *all* the platform tools (all Android from 1 to 3.3) takes a while, if you only need a specific SDK version, just install from the GUI tool: | |||
</li></ul> | |||
<pre class="_fck_mw_lspace">$ANDROID_HOME/tools/android | |||
</pre> | |||
<h3> Emulators </h3> | |||
<ul><li> to create: | |||
Use the command line <tt>$ANDROID_HOME/tools/android</tt>, or use the graphical Android AVD Manager (from within Eclipse: <tt>Window | </li></ul> | ||
<p>Use the command line <tt>$ANDROID_HOME/tools/android</tt>, or use the graphical Android AVD Manager (from within Eclipse: <tt>Window > AVD Manager</tt>). | |||
</p> | |||
<pre class="_fck_mw_lspace">$ANDROID_HOME/tools/android create avd -t android-10 -n NAME -c 2047M | |||
produces the output | </pre> | ||
<p>produces the output | |||
</p> | |||
<pre class="_fck_mw_lspace">Auto-selecting single ABI armeabi | |||
Android 2.3.3 is a basic Android platform. | |||
Do you wish to create a custom hardware profile [no] | |||
Created AVD 'NAME' based on Android 2.3.3, ARM (armeabi) processor, | |||
with the following hardware config: | |||
hw.lcd.density=240 | |||
vm.heapSize=24 | |||
hw.ramSize=256 | |||
{{note|Target (in the example above, | </pre> | ||
<p><span class="fck_mw_template">{{note|Target (in the example above, <tt>android-10</tt>) probably needs to match build specified in .mozconfig (see Building Fennec Native below).}}</span> | |||
</p> | |||
<ul><li> to launch: | |||
</li></ul> | |||
<pre class="_fck_mw_lspace">$ANDROID_HOME/tools/emulator -wipe-data -avd NAME -partition-size 2047 | |||
</pre> | |||
<p><span class="fck_mw_template">{{note|The partition size is set large so that you don't run into an insufficient storage error.}}</span> | |||
</p> | |||
<ul><li> to delete: | |||
</li></ul> | |||
<pre class="_fck_mw_lspace">$ANDROID_HOME/tools/android delete avd -n NAME | |||
After installation, fennec would crash on installation (unable to locate mozutils library, although it's in the apk). Possibly related to emulator failing to run NDK applications? | </pre> | ||
<p>After installation, fennec would crash on installation (unable to locate mozutils library, although it's in the apk). Possibly related to emulator failing to run NDK applications? | |||
</p> | |||
<h2> Running everything </h2> | |||
The main <tt>android-sync</tt> source repository is hosted on github: | <p>The main <tt>android-sync</tt> source repository is hosted on github: | ||
</p> | |||
<pre class="_fck_mw_lspace">https://github.com/mozilla-services/android-sync | |||
</pre> | |||
Try | <p>Try | ||
</p> | |||
<pre class="_fck_mw_lspace">git clone git@github.com:mozilla-services/android-sync.git | |||
</pre> | |||
<h3> android-sync dependencies </h3> | |||
<p>android-sync has the following dependencies: | |||
android-sync has the following dependencies: | </p> | ||
<ul><li> sync-crypto, described below. | |||
</li><li> httpclientandroidlib, which provides a working modern version of the Apache HTTPClient under a different Java package. | |||
</li><li> json-simple 1.1 and commons-codec 1.2, which ship with Android. | |||
</li><li> Android 2.3.3. | |||
</li></ul> | |||
<p>For testing it requires: | |||
For testing it requires: | </p> | ||
<ul><li> JUnit 4.1. | |||
</li><li> org.simpleframework.simple, for HTTP testing. | |||
</li><li> Tiny “un-stub” packages for android.util.Log, android.util.Base64, and android.content.SharedPreferences. | |||
</li></ul> | |||
These live on github, and must be built and installed. | <p>These live on github, and must be built and installed. | ||
</p> | |||
<ul><li><ul><li> https://github.com/rnewman/base64-unstub | |||
</li><li> https://github.com/rnewman/log-unstub | |||
</li><li> https://github.com/rnewman/sharedpreferences-stub | |||
</li></ul> | |||
</li></ul> | |||
<h3> sync-crypto dependencies </h3> | |||
sync-crypto relies on Apache commons-codec 1.5, which includes Base32. The Android system libraries include the 8-year-old version 1.2. As a result, sync-crypto is packaged as an assembly jar (aka über jar). | <p>sync-crypto relies on Apache commons-codec 1.5, which includes Base32. The Android system libraries include the 8-year-old version 1.2. As a result, sync-crypto is packaged as an assembly jar (aka über jar). | ||
</p> | |||
<h3> What you need to do </h3> | |||
<pre class="_fck_mw_lspace">git clone https://github.com/rnewman/base64-unstub | |||
git clone https://github.com/rnewman/log-unstub | |||
git clone https://github.com/rnewman/sharedpreferences-stub | |||
git clone https://github.com/mozilla-services/android-sync | |||
pushd base64-unstub; mvn install; popd | |||
pushd log-unstub; mvn install; popd | |||
pushd sharedpreferences-stub; mvn install; popd | |||
pushd android-sync | |||
git checkout develop | |||
./preprocess.sh | |||
mvn test | |||
</pre> | |||
<p><span class="fck_mw_template">{{note|<tt>mvn assembly:assembly</tt> may fail, however, it is still ok to proceed.}}</span> | |||
{{note| | </p><p>To do real Android development and testing, you need to import android-sync as a project in Eclipse with the ADT installed. | ||
</p><p>Note that both android-sync and sync-crypto have JUnit 4 tests that run in both Eclipse and Maven. The subdirectory android-sync/test includes Android JUnit 3 tests for activity and store testing. This is to avoid the mammoth annoyance of testing in a VM without introducing robolectric. | |||
To do real Android development and testing, you need to import android-sync as a project in Eclipse with the ADT installed. | </p> | ||
<h3> Running Fennec </h3> | |||
Note that both android-sync and sync-crypto have JUnit 4 tests that run in both Eclipse and Maven. The subdirectory android-sync/test includes Android JUnit 3 tests for activity and store testing. This is to avoid the mammoth annoyance of testing in a VM without introducing robolectric. | <p>The directions at <a href="Fennec/NativeUI"> Building Native Fennec</a> should be correct, specifically <a href="Fennec/NativeUI#How_To_Build"> How To Build</a>. | ||
</p><p>After building Fennec, make the apk. | |||
</p> | |||
The directions at | <pre class="_fck_mw_lspace">make -sj8 -C objdir-droid/ package | ||
</pre> | |||
After building Fennec, make the apk. | <p>The apk will be something like <tt>objdir-droid/dist/fennec-12.0a1.en-US.android-arm.apk</tt>. | ||
</p> | |||
<h4> Running Fennec on an Android device </h4> | |||
The apk will be something like <tt>objdir-droid/dist/fennec-12.0a1.en-US.android-arm.apk</tt>. | <ul><li> Ensure USB debugging is enabled on your Android device: fom the home screen, select <tt>Settings > Applications > Development > USB debugging</tt>. | ||
</li><li> Ensure your Android device is connected to your computer's USB port. | |||
</li><li> Run | |||
</li></ul> | |||
<pre class="_fck_mw_lspace">$ANDROID_HOME/platform-tools/adb install -r objdir-droid/dist/fennec*apk | |||
</pre> | |||
<h4> Running Fennec on an emulator </h4> | |||
<ul><li> Ensure the emulator is running. | |||
</li><li> Run | |||
</li></ul> | |||
<pre class="_fck_mw_lspace">$ANDROID_HOME/platform-tools/adb install -r objdir-droid/dist/fennec*apk | |||
</pre> | |||
<p><span class="fck_mw_template">{{note|You may need to run <tt>adb kill-server; adb start-server</tt> if adb doesn't recognize the emulator.}}</span> | |||
{{note|You may need to run | </p> | ||
<h4> Accessing Fennec/Android Sync debug statements </h4> | |||
<pre class="_fck_mw_lspace">$ANDROID_HOME/platform-tools/adb logcat | |||
</pre> | |||
<h3> Setting up Eclipse </h3> | |||
<p>If you want to use Eclipse: | |||
If you want to use Eclipse: | </p> | ||
<ul><li> Install Eclipse and the SDK plugin, as described in the Android SDK page. | |||
</li><li> Correct formatting: <tt>Preferences > Java > Code style > Formatter > Edit...</tt>, set profile name to <tt>Mozilla</tt>, set <tt>Tab policy</tt> to <tt>Spaces only</tt> change both <tt>Indentation size</tt> and <tt>Tab size</tt> to 2, and check <tt>Align fields in columns</tt>. | |||
</li><li> Run these commands in your <tt>android-sync</tt> git repository directory (don't forget to checkout the <tt>develop</tt> branch): | |||
</li></ul> | |||
<pre class="_fck_mw_lspace">mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo | |||
mvn -DdownloadJavadocs=true -DdownloadSources=true eclipse:eclipse | |||
</pre> | |||
<ul><li> Install the project and classpath files (again in your git repository directory), making sure to update the paths where necessary in both files: | |||
</li></ul> | |||
<pre class="_fck_mw_lspace">cp example.project .project | |||
cp example.classpath .classpath | |||
</pre> | |||
<ul><li> Open Eclipse, choose <tt>File > Import... > General > Existing Projects into Workspace</tt>, and specify your git repository directory. | |||
</li></ul> | |||
<p><span class="fck_mw_template">{{note|You may need to set <tt>M2_REPO</tt> (for example, as described at [http://www.mkyong.com/maven/how-to-configure-m2_repo-variable-in-eclipse-ide/]) to something like <tt>$HOME/.m2/repository</tt>.}}</span> | |||
{ | </p> | ||
<h4> To run the unit test suite under Eclipse </h4> | |||
<ul><li> First configure the test suite launcher, under <tt>Preferences > Run/Debug > Launching > Default Launchers</tt>. Set the Debug and Run launchers to <tt>Android JUnit Test Launcher</tt>. | |||
</li><li> Select the <tt>android-sync</tt> project and execute <tt>Run > Run As ... > JUnit Test</tt>. | |||
</li></ul> | |||
<h4> To run the integration test suite under Eclipse </h4> | |||
<ul><li> Add the <tt>test</tt> subdirectory as a sub-project using <tt>File > Import > Existing project</tt>. | |||
</li></ul> | |||
<ul><li> Refresh and clean everything. | |||
</li></ul> | |||
<ul><li> Select the <tt>test</tt> project and execute <tt>Run > Run As ... > Android JUnit Test</tt>. | |||
</li></ul> | |||
<h2> Development </h2> | |||
<p>Let's stick to some fairly sane Java conventions: 2-space indenting (Java is wide enough as it is), Maven2 for dependencies and build, JUnit4 for unit tests. We can wire in Hudson later if we have time. "Simple" for HTTP test server. | |||
</p><p>Let's figure out bleeding edge stuff ("how do I get a SyncAdapter to work?") in throwaway projects. There will be a lot of these :) | |||
</p><p>We don't quite follow the <a _fcknotitle="true" href="Fennec/NativeUI/CodingStyle">Fennec/NativeUI/CodingStyle</a>. See also <a href="http://source.android.com/source/code-style.html">the Android coding style</a>. | |||
</p> | |||
Let's stick to some fairly sane Java conventions: 2-space indenting (Java is wide enough as it is), Maven2 for dependencies and build, JUnit4 for unit tests. We can wire in Hudson later if we have time. "Simple" for HTTP test server. | <h3> Running unit test code coverage </h3> | ||
<p>To see the current unit test code coverage (using the Maven plugin integrating Cobertura), from the <tt>android-sync</tt> directory run | |||
Let's figure out bleeding edge stuff ("how do I get a SyncAdapter to work?") in throwaway projects. There will be a lot of these :) | </p> | ||
<pre class="_fck_mw_lspace">mvn cobertura:cobertura | |||
We don't quite follow the | </pre> | ||
<p>browse | |||
</p> | |||
<pre class="_fck_mw_lspace">./target/site/cobertura/index.html | |||
To see the current unit test code coverage (using the Maven plugin integrating Cobertura), from the <tt>android-sync</tt> directory run | </pre> | ||
<p>and click on <tt>org.mozilla.gecko</tt>. | |||
</p><p><span class="fck_mw_template">{{note|At this time, you can't see the current integration test code coverage.}}</span> | |||
</p> | |||
browse | <h2> Security </h2> | ||
<p>Goals: no less secure than currently, at most Fennec, Service, UI have access to credentials. | |||
</p><p><a href="http://developer.android.com/guide/topics/security/security.html">Android Docs on security </a> | |||
</p><p>Sandboxing by using UIDs, specifically the section on "User IDs and File Access". | |||
and click on <tt>org.mozilla.gecko</tt>. | </p><p>See also <a href="http://developer.android.com/guide/topics/manifest/manifest-element.html">manifest entries</a>: | ||
</p> | |||
{{note|At this time, you can't see the current integration test code coverage.}} | |||
Goals: no less secure than currently, at most Fennec, Service, UI have access to credentials. | |||
Sandboxing by using UIDs, specifically the section on "User IDs and File Access". | |||
See also | |||
<blockquote><tt>android:sharedUserId</tt> | <blockquote><tt>android:sharedUserId</tt> | ||
The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID — provided that they are also signed by the same certificate. Application with the same user ID can access each other's data and, if desired, run in the same process</blockquote> | The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID — provided that they are also signed by the same certificate. Application with the same user ID can access each other's data and, if desired, run in the same process</blockquote> | ||
<h2> Permissions </h2> | |||
<pre class="_fck_mw_lspace"> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> | |||
<uses-permission android:name="android.permission.MANAGE_CREDENTIALS" /> | |||
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> | |||
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" /> | |||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" /> | |||
<uses-permission android:name="android.permission.WRITE_SETTINGS" /> | |||
<uses-permission android:name="android.permission.READ_SYNC_STATS" /> | |||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /> | |||
<uses-permission android:name="android.permission.INTERNET"/> | |||
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/> | |||
<uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/> | |||
</pre> | |||
<h2> Adjusting sync frequency </h2> | |||
<p>If API > 8, use ContentResolver.addPeriodicSync() | |||
</p><p>If API = 7, create a service with a periodic timer callback, and call ContentResolver.requestSync(). | |||
</p><p>API < 6 does not support syncAdapter, so no worries. | |||
If API | </p><p>Triggering a sync: | ||
</p> | |||
If API = 7, create a service with a periodic timer callback, and call ContentResolver.requestSync(). | <pre class="_fck_mw_lspace"> android:supportsUploading defaults to true and if true an upload-only sync will be requested for all syncadapters associated with an | ||
authority whenever that authority's content provider does a notifyChange(android.net.Uri, android.database.ContentObserver, boolean) with | |||
API | syncToNetwork set to true. | ||
</pre> | |||
Triggering a sync: | <h2> Altering Sync settings </h2> | ||
<pre class="_fck_mw_lspace"> android:syncAdapterSettingsAction defaults to null and if supplied it specifies an Intent action of an activity that can be used to adjust the sync adapter's sync settings. The activity must live in the same package as the sync adapter. | |||
</pre> | |||
<h2> Localization </h2> | <h2> Localization </h2> | ||
<p>http://developer.android.com/guide/topics/resources/localization.html | <p>http://developer.android.com/guide/topics/resources/localization.html | ||
</p> | </p> | ||
< | <h2> Schemas </h2> | ||
< | <p>TODO | ||
< | </p> | ||
< | <h2> Gotchas </h2> | ||
<p>Android's sqlite cursors are limited. Oh, and the heap is limited. We have to be very careful about how much data we store and process at one time. | |||
</p> | |||
<blockquote cite="http://stackoverflow.com/questions/1407442/android-sqlite-and-huge-data-sets"><p>“You are out of heap space. With a 16MB non-compacting heap, and the fact that a Cursor holds the entire result set in the heap, that is not out of the question. CursorWindow only supports 1MB of data, which is what the error message suggests more directly.</p><p>If there is a logical way to divide your queries into discrete chunks, you could do incremental queries and use CursorJoiner to stitch them together, and see if that helps.”</p></blockquote> | |||
<h2> jvoll's notes </h2> | |||
<p>Having trouble with the emulator when loading Fennec and Sync onto it? Use: emulator -avd android-14 -partition-size 2047 | |||
</p><p>Lines to remove from mobile/android/base/AndroidManifest.xml.in if you don't feel like working around the permissions stuff: | |||
-android:permission="org.mozilla.gecko.permissions.BROWSER_PROVIDER"/> from both providers | |||
Android's sqlite cursors are limited. Oh, and the heap is limited. We have to be very careful about how much data we store and process at one time. | -<permission android:name="org.mozilla.gecko.permissions.BROWSER_PROVIDER" android:protectionLevel="signature"/> | ||
</p><p>Tests failing and seeing a ProfileDatabaseException logged in logcat? This usually happens when you did a fresh install of fennec and haven't opened it yet. So, just open Fennec. If that fails (and this works for other weird stuff too), go to apps and stop Fennec, clear app data and/or in extreme cases uninstall and reinstall it. This stuff *should* all be fixed shortly, but for now these are good work arounds. | |||
<blockquote cite="http | </p><p>Accessing android db on emulator: | ||
Having trouble with the emulator when loading Fennec and Sync onto it? Use: emulator -avd android-14 -partition-size 2047 | |||
Lines to remove from mobile/android/base/AndroidManifest.xml.in if you don't feel like working around the permissions stuff: | |||
-android:permission="org.mozilla.gecko.permissions.BROWSER_PROVIDER"/ | |||
- | |||
Tests failing and seeing a ProfileDatabaseException logged in logcat? This usually happens when you did a fresh install of fennec and haven't opened it yet. So, just open Fennec. If that fails (and this works for other weird stuff too), go to apps and stop Fennec, clear app data and/or in extreme cases uninstall and reinstall it. This stuff *should* all be fixed shortly, but for now these are good work arounds. | |||
Accessing android db on emulator: | |||
adb shell | adb shell | ||
cd /data/data/org.mozilla.fennec_jason/files/mozilla/yvzvl036.default | cd /data/data/org.mozilla.fennec_jason/files/mozilla/yvzvl036.default | ||
sqlite3 browser.db (or w/e database is wanted) | sqlite3 browser.db (or w/e database is wanted) | ||
</p> | |||
<h2> Troubleshooting </h2> | |||
<h3> "R cannot be resolved" </h3> | |||
Something is wrong with xml resolution. Check your Eclipse console errors in xml files, which will prevent Eclipse from building resource (R) files - resolve them first. | <p>Something is wrong with xml resolution. Check your Eclipse console errors in xml files, which will prevent Eclipse from building resource (R) files - resolve them first. | ||
</p><p>Things to try: | |||
Things to try: | </p> | ||
<ul><li>Update string resources: ./preprocess | |||
</li><li>Project > Clean, then rebuild the project. Alternatively, you can delete the gen/ directory, and Eclipse will rebuild automatically (Project > Build Automatically checked) | |||
</li></ul> | |||
<h3> Loading apk: "Insufficient space" error on emulator </h3> | |||
Start an emulator with "-partition-size 2047" as a flag, to set emulator size. | <p>Start an emulator with "-partition-size 2047" as a flag, to set emulator size. | ||
</p> | |||