<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <id>https://docs.memfault.com/embed/android</id>
    <title>Memfault Docs Blog</title>
    <updated>2021-06-02T13:26:45.000Z</updated>
    <generator>https://github.com/jpmonette/feed</generator>
    <link rel="alternate" href="https://docs.memfault.com/embed/android"/>
    <subtitle>Memfault Docs Blog</subtitle>
    <icon>https://docs.memfault.com/img/memfault-favicon.png</icon>
    <entry>
        <title type="html"><![CDATA[Getting Started]]></title>
        <id>https://docs.memfault.com/embed/android/android-getting-started-guide</id>
        <link href="https://docs.memfault.com/embed/android/android-getting-started-guide"/>
        <updated>2021-06-02T13:26:45.000Z</updated>
        <content type="html"><![CDATA[<p>The following guide will walk you through step-by-step how to integrate and
validate Memfault's <a class="" href="https://docs.memfault.com/docs/android/android-bort">Android SDK</a> in your custom AOSP project.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="integration-steps">1. Create a Project<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#integration-steps" class="hash-link" aria-label="Direct link to 1. Create a Project" title="Direct link to 1. Create a Project" translate="no">​</a></h2>
<!-- -->
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="build-your-aosp-project-with-the-bort-sdk-integrated">2. Build your AOSP project with the Android SDK integrated<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#build-your-aosp-project-with-the-bort-sdk-integrated" class="hash-link" aria-label="Direct link to 2. Build your AOSP project with the Android SDK integrated" title="Direct link to 2. Build your AOSP project with the Android SDK integrated" translate="no">​</a></h2>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="clone-the-bort-sdk-into-your-project">i. Clone the Android SDK into your project<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#clone-the-bort-sdk-into-your-project" class="hash-link" aria-label="Direct link to i. Clone the Android SDK into your project" title="Direct link to i. Clone the Android SDK into your project" translate="no">​</a></h3>
<p>Using a <a href="https://git-scm.com/" target="_blank" rel="noopener noreferrer" class="">Git</a> client, clone the <code>bort</code> repository from:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">git clone https://github.com/memfault/bort.git</span><br></span></code></pre></div></div>
<p>Add this repo to your tree at <code>vendor/memfault/bort</code> (i.e. add it to your repo
manifest).</p>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="add-the-sdk-components-to-your-build">ii. Include the Memfault Android SDK into your project Makefiles<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#add-the-sdk-components-to-your-build" class="hash-link" aria-label="Direct link to ii. Include the Memfault Android SDK into your project Makefiles" title="Direct link to ii. Include the Memfault Android SDK into your project Makefiles" translate="no">​</a></h3>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>We recommend placing the <code>include</code>s below at the <em>end</em> of the respective
<code>Makefile</code>s. This is because <code>include</code> directives are used to <em>append</em> to
variables in the build script; placing them at the end of the file reduces the
chances that subsequent lines in the <code>Makefile</code> do not redefine those variables
and discard the effect of the <code>include</code>. If it is not possible to place the
<code>include</code> at the end of the file, ensure that the respective variables are not
redefined (look for the <code>:=</code> syntax).</p></div></div>
<p>Add this line to your <code>device.mk</code> file to get the components included in your
build; this appends to the <code>PRODUCT_PACKAGES</code> variable:</p>
<div class="language-makefile codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-makefile codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token keyword" style="color:#c5a5c5">include</span><span class="token plain"> vendor/memfault/bort/product.mk</span><br></span></code></pre></div></div>
<p>Add this line to your <code>BoardConfig.mk</code> file to get the sepolicy files picked up
by the build system; this appends to the <code>BOARD_SEPOLICY_DIRS</code> and
<code>BOARD_PLAT_PRIVATE_SEPOLICY_DIR</code> variables:</p>
<div class="language-makefile codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-makefile codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token keyword" style="color:#c5a5c5">include</span><span class="token plain"> vendor/memfault/bort/BoardConfig.mk</span><br></span></code></pre></div></div>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="patch-the-sdk">iii. Patch AOSP<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#patch-the-sdk" class="hash-link" aria-label="Direct link to iii. Patch AOSP" title="Direct link to iii. Patch AOSP" translate="no">​</a></h3>
<p>Before Memfault Android SDK version 5.0, it is required to apply patches to the
AOSP source code in order to integrate the Android SDK. After 5.0, patches are
only required for the SDK to function on Android 7.1 and 8. Not all patches are
required - some enhance enable/enhanced specific SDK features:</p>
<table><thead><tr><th>AOSP Version</th><th>Memfault Android SDK Version</th><th>Required AOSP Patches</th></tr></thead><tbody><tr><td>7.1, 8</td><td>All</td><td><a href="https://github.com/memfault/bort/blob/c1af86857463676ad4bd6896186509188978dcf0/patches/android-8/build/git.diff" target="_blank" rel="noopener noreferrer" class="">build/core/tasks</a> / <a href="https://github.com/memfault/bort/blob/c1af86857463676ad4bd6896186509188978dcf0/patches/android-8/system/sepolicy/git.diff" target="_blank" rel="noopener noreferrer" class="">system/sepolicy</a></td></tr><tr><td>11+</td><td>&lt; 5.0</td><td><a href="https://github.com/memfault/bort/blob/c1af86857463676ad4bd6896186509188978dcf0/patches/android-12/build/make/git.diff" target="_blank" rel="noopener noreferrer" class="">build/make/target/product/mainline</a></td></tr></tbody></table>
<p>For full details, see <a class="" href="https://docs.memfault.com/docs/android/android-patches">AOSP Patches</a>.</p>
<p>Apply using the <code>bort_cli.py</code> tool (requires Python 3.6+). Be sure to call this
using the correct Android OS version (<code>--android-release</code>) for your build.</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">vendor/memfault/bort/bort_cli.py patch-aosp \</span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain">  --android-release 16 \</span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain">  &lt;AOSP_ROOT&gt;</span><br></span></code></pre></div></div>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="patch-bort">iv. Patch Bort's application ID<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#patch-bort" class="hash-link" aria-label="Direct link to iv. Patch Bort's application ID" title="Direct link to iv. Patch Bort's application ID" translate="no">​</a></h3>
<p>Decide on an application ID for the Bort application. We recommend placing the
application under your domain, and appending <code>bort</code> to your
<a href="https://en.wikipedia.org/wiki/Reverse_domain_name_notation" target="_blank" rel="noopener noreferrer" class="">reverse domain name</a>
in some fashion. For example, <code>com.mycorp.bort</code>.</p>
<p>If you're using the <a class="" href="https://docs.memfault.com/docs/android/android-ota-update-client">OTA Update Client</a>, the OTA
application ID must also be set. For example, <code>com.mycorp.bort.ota</code>.</p>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>OTA must be explicitly enabled -
<a class="" href="https://docs.memfault.com/docs/android/android-ota-update-client#enable-ota-update-client">instructions here</a>.</p></div></div>
<p>Patch Bort with your own application IDs:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">vendor/memfault/bort/bort_cli.py patch-bort \</span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain">  --bort-app-id &lt;YOUR_BORT_APPLICATION_ID&gt; \</span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain">  --bort-ota-app-id &lt;YOUR_BORT_OTA_APPLICATION_ID&gt; \</span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain">  &lt;AOSP_ROOT&gt;/vendor/memfault/bort/MemfaultPackages</span><br></span></code></pre></div></div>
<p>This command will patch <code>bort.properties</code>, setting the <code>BORT_APPLICATION_ID</code>
(and <code>BORT_OTA_APPLICATION_ID</code>) properties to <code>&lt;YOUR_BORT_APPLICATION_ID&gt;</code> and
<code>YOUR_BORT_OTA_APPLICATION_ID</code>.</p>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="configure-the-bort--usagereporter-apps">v. Configure bort.properties<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#configure-the-bort--usagereporter-apps" class="hash-link" aria-label="Direct link to v. Configure bort.properties" title="Direct link to v. Configure bort.properties" translate="no">​</a></h3>
<p><strong>You must set your Project Key in the Bort app</strong>. This is set in
<code>MemfaultPackages/bort.properties</code>; the app will not compile without this
property.</p>
<p>If your devices will have
<a href="https://www.android.com/intl/en_ca/gms/" target="_blank" rel="noopener noreferrer" class="">Google Mobile Services (GMS)</a> and must
run the
<a href="https://source.android.com/compatibility/cts" target="_blank" rel="noopener noreferrer" class="">Compatibility Test Suite (CTS)</a>,
you may need to <strong>update the target SDK version</strong> to match the API level of your
OS. This can be done by updating the <code>TARGET_SDK_VERSION</code> property in
<code>MemfaultPackages/bort.properties</code>.</p>
<p>Additional settings can be configured via the Android SDK over-the-air
<a class="" href="https://docs.memfault.com/docs/android/android-bort#features-and-configuration">SDK settings</a> system.</p>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="create-a-keystore-for-the-bort-sdk">vi. Create a keystore for the Android SDK<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#create-a-keystore-for-the-bort-sdk" class="hash-link" aria-label="Direct link to vi. Create a keystore for the Android SDK" title="Direct link to vi. Create a keystore for the Android SDK" translate="no">​</a></h3>
<h4 class="anchor anchorTargetStickyNavbar_Vzrq" id="create-a-keystore-for-the-bort-app">Bort app<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#create-a-keystore-for-the-bort-app" class="hash-link" aria-label="Direct link to Bort app" title="Direct link to Bort app" translate="no">​</a></h4>
<p><strong>The Bort app requires a Java keystore file so that the app can be signed</strong>.</p>
<p>To generate a keystore, run the following command in the
<code>&lt;AOSP_ROOT&gt;/vendor/memfault/bort/MemfaultPackages</code> directory:</p>
<div class="language-sh codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-sh codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">$JAVA_HOME/bin/keytool -genkeypair -alias release_key -keypass secretPassword -keystore bort_keystore.jks -storepass secretPassword -validity 10000 -keyalg rsa</span><br></span></code></pre></div></div>
<p>Make sure to change the <code>secretPassword</code> to a uniquely generated password and
store that password securely. Please note that the <code>-keypass</code> and <code>-storepass</code>
must be the same.</p>
<p>Alternatively, instructions on how to create a keystore in Android Studio can be
found
<a href="https://developer.android.com/studio/publish/app-signing#generate-key" target="_blank" rel="noopener noreferrer" class="">in the Android documentation</a>.
If you plan to update the app via the Play Store, you may wish to follow the
additional instructions on that page.</p>
<div class="theme-admonition theme-admonition-important admonition_xJq3 alert alert--info"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg></span>important</div><div class="admonitionContent_BuS1"><ul>
<li class="">The key that is used to sign the Bort app must NOT be the platform signing
key, otherwise the SDK will not function correctly.</li>
<li class="">The key must ONLY be used to sign the Bort app and no other apps. Special
permissions are assigned to Bort app based on the signing certificate.</li>
</ul></div></div>
<p>Once you have a keystore, set up a <code>keystore.properties</code> file and provide the
path to it via the <code>bort.properties</code> file:</p>
<div class="language-properties codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-properties codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token key attr-name" style="color:#c5a5c5">BORT_KEYSTORE_PROPERTIES_PATH</span><span class="token punctuation" style="color:#8dc891">=</span><span class="token value attr-value" style="color:#8dc891">keystore.properties</span><br></span></code></pre></div></div>
<p>The <code>keystore.properties</code> file must contain these properties with the
appropriate values:</p>
<div class="language-properties codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-properties codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token key attr-name" style="color:#c5a5c5">keyAlias</span><span class="token punctuation" style="color:#8dc891">=</span><span class="token value attr-value" style="color:#8dc891">release_key # e.g. key0</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"></span><span class="token key attr-name" style="color:#c5a5c5">keyPassword</span><span class="token punctuation" style="color:#8dc891">=</span><span class="token value attr-value" style="color:#8dc891">secretPassword</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"></span><span class="token key attr-name" style="color:#c5a5c5">storeFile</span><span class="token punctuation" style="color:#8dc891">=</span><span class="token value attr-value" style="color:#8dc891">bort_keystore.jks</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"></span><span class="token key attr-name" style="color:#c5a5c5">storePassword</span><span class="token punctuation" style="color:#8dc891">=</span><span class="token value attr-value" style="color:#8dc891">secretPassword</span><br></span></code></pre></div></div>
<h4 class="anchor anchorTargetStickyNavbar_Vzrq" id="create-a-keystore-for-the-ota-update-client-app">OTA Update Client app<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#create-a-keystore-for-the-ota-update-client-app" class="hash-link" aria-label="Direct link to OTA Update Client app" title="Direct link to OTA Update Client app" translate="no">​</a></h4>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>This step is only required if you are using the
<a class="" href="https://docs.memfault.com/docs/android/android-ota-update-client">OTA Update Client</a>.</p></div></div>
<p>If using the OTA Update Client, a separate keystore should be created, following
the same steps as for the Bort app.</p>
<p>Once you have a keystore, set up a <code>ota_keystore.properties</code> file and provide
the path to it via the <code>bort.properties</code> file:</p>
<div class="language-properties codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-properties codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token key attr-name" style="color:#c5a5c5">BORT_OTA_KEYSTORE_PROPERTIES_PATH</span><span class="token punctuation" style="color:#8dc891">=</span><span class="token value attr-value" style="color:#8dc891">ota_keystore.properties</span><br></span></code></pre></div></div>
<p>If using OTA, then this must be explicitly enabled -
<a class="" href="https://docs.memfault.com/docs/android/android-ota-update-client#enable-ota-update-client">instructions here</a>.</p>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="build-the-bort-sdk-apks">vii. Build the Android SDK APKs<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#build-the-bort-sdk-apks" class="hash-link" aria-label="Direct link to vii. Build the Android SDK APKs" title="Direct link to vii. Build the Android SDK APKs" translate="no">​</a></h3>
<h4 class="anchor anchorTargetStickyNavbar_Vzrq" id="build-the-bort-apk">Build the Bort APK<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#build-the-bort-apk" class="hash-link" aria-label="Direct link to Build the Bort APK" title="Direct link to Build the Bort APK" translate="no">​</a></h4>
<p>The <code>MemfaultBort</code> app is built using gradle. Building the release APK will
automatically invoke a task to copy the resulting APK and place it in the root
directory where it will be picked up by the AOSP build system.</p>
<p>Building the Bort app with gradle requires the Android SDK location to be
configured. This can either be set with the <code>ANDROID_HOME</code> environment variable,
or by opening the project with Android Studio (e.g. opening the root
<code>build.gradle</code>) which will auto-generate a <code>local.properties</code> file with the
<code>sdk.dir</code> property. We recommend installing
<a href="https://developer.android.com/studio" target="_blank" rel="noopener noreferrer" class="">Android Studio</a>, which will automatically
install many Android SDK tools.</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">cd MemfaultPackages &amp;&amp; ./gradlew :bort:assembleRelease</span><br></span></code></pre></div></div>
<p>This will create a signed <code>MemfaultBort.apk</code> and <code>MemfaultBort.x509.pem</code> file.
The <code>pem</code> file is a public certificate used by the system when enforcing the SE
policy.</p>
<h4 class="anchor anchorTargetStickyNavbar_Vzrq" id="build-the-ota-update-client-apk">Build the OTA Update Client APK<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#build-the-ota-update-client-apk" class="hash-link" aria-label="Direct link to Build the OTA Update Client APK" title="Direct link to Build the OTA Update Client APK" translate="no">​</a></h4>
<p>The <code>MemfaultBortOta</code> app is built using gradle. Building the release APK will
automatically invoke a task to copy the resulting APK and place it in the root
directory where it will be picked up by the AOSP build system.</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">cd MemfaultPackages &amp;&amp; ./gradlew :bort-ota:assembleRelease</span><br></span></code></pre></div></div>
<p>This will create a signed <code>MemfaultBortOta.apk</code> and <code>MemfaultBortOta.x509.pem</code>
file. The <code>pem</code> file is a public certificate used by the system when enforcing
the SE policy.</p>
<h4 class="anchor anchorTargetStickyNavbar_Vzrq" id="build-the-usagereporter-apk">Build the UsageReporter APK<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#build-the-usagereporter-apk" class="hash-link" aria-label="Direct link to Build the UsageReporter APK" title="Direct link to Build the UsageReporter APK" translate="no">​</a></h4>
<p>The <code>MemfaultUsageReporter</code> app is built using gradle. Building the release APK
will automatically invoke a task to copy the resulting APK and place it in the
root directory where it will be picked up by the AOSP build system.</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">cd MemfaultPackages &amp;&amp; ./gradlew :reporter:assembleRelease</span><br></span></code></pre></div></div>
<h4 class="anchor anchorTargetStickyNavbar_Vzrq" id="build-all-apks-at-once-recommended">Build all APKs at once (Recommended)<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#build-all-apks-at-once-recommended" class="hash-link" aria-label="Direct link to Build all APKs at once (Recommended)" title="Direct link to Build all APKs at once (Recommended)" translate="no">​</a></h4>
<p>All of the above APKs can be built using a single command! We recommend using
the full command and letting gradle automatically optimize the recompilation.</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">cd MemfaultPackages &amp;&amp; ./gradlew assembleRelease</span><br></span></code></pre></div></div>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="compile-and-run-the-aosp-image-on-your-device">viii. Compile and run the AOSP image on your device<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#compile-and-run-the-aosp-image-on-your-device" class="hash-link" aria-label="Direct link to viii. Compile and run the AOSP image on your device" title="Direct link to viii. Compile and run the AOSP image on your device" translate="no">​</a></h3>
<p>After the APKs are built and the Makefiles are included in your AOSP project,
compile your AOSP image, and flash it to your device.</p>
<p>By default, Memfault expects the <code>MemfaultBort.apk</code>,
<code>MemfaultUsageReporter.apk</code>, and <code>MemfaultBort.x509.pem</code> files to exist in the
<code>vendor/memfault/bort/MemfaultPackages</code> folder, so the Bort and UsageReporter
apps can be installed in the AOSP image.</p>
<p>If using OTA, the <code>MemfaultBortOta.apk</code> and <code>MemfaultBortOta.x509.pem</code> must also
exist in that folder.</p>
<p>Building these APKs using gradle will automatically copy the apk and
certificates to the correct location, but you can define your own process as
long as those files are written to that location before the image AOSP is built.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="validating-the-sdk-integration">3. Validate the AOSP integration<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#validating-the-sdk-integration" class="hash-link" aria-label="Direct link to 3. Validate the AOSP integration" title="Direct link to 3. Validate the AOSP integration" translate="no">​</a></h2>
<p>The <code>bort_cli.py</code> tool can also be used to check for issues with the SDK
installation. To use it, install a build containing the Android SDK on a device
that you wish to validate. Connect that device via ADB (verify via
<code>adb devices</code>) and run the script:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">./bort_cli.py validate-sdk-integration --bort-app-id your.app.id</span><br></span></code></pre></div></div>
<p>If using the Bort OTA client, then run the validation tool with an additional
argument for the OTA app ID. This is supported from Android SDK 4.12.0 onwards:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">./bort_cli.py validate-sdk-integration --bort-app-id your.app.id --bort-ota-app-id your.ota.app.id</span><br></span></code></pre></div></div>
<div class="theme-admonition theme-admonition-info admonition_xJq3 alert alert--info"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg></span>info</div><div class="admonitionContent_BuS1"><p>We recommend running the validation tool with a <code>userdebug</code> system image. A
<code>user</code> image does not allow all checks to be run, which may result in Bort
configuration issues being missed.</p></div></div>
<p>If you have multiple devices connected, use the <code>--device</code> flag to specify the
target device. For more information on the different options, run the command
with the <code>-h</code> flag:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">./bort_cli.py validate-sdk-integration -h</span><br></span></code></pre></div></div>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="collect-your-first-device-metrics">4. Collect your first device metrics<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#collect-your-first-device-metrics" class="hash-link" aria-label="Direct link to 4. Collect your first device metrics" title="Direct link to 4. Collect your first device metrics" translate="no">​</a></h2>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="enable-the-sdk">i. Enable the Android SDK<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#enable-the-sdk" class="hash-link" aria-label="Direct link to i. Enable the Android SDK" title="Direct link to i. Enable the Android SDK" translate="no">​</a></h3>
<p>By default, the Android SDK will only run after being explicitly enabled at
runtime (<code>RUNTIME_ENABLE_REQUIRED=true</code>) - this is to ensure no data is
collected without user consent.</p>
<p>Additional information on enabling the SDK can be found in the
<a class="" href="https://docs.memfault.com/docs/android/android-bort#enabling-the-sdk-at-runtime">Enabling the SDK at Runtime</a>
section of the Android SDK documentation.</p>
<p>For the purposes of testing the SDK on a development device, the SDK can be
enabled via ADB using the CLI tool:</p>
<div class="language-sh codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-sh codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">./bort_cli.py enable-bort --bort-app-id your.app.id</span><br></span></code></pre></div></div>
<p>The <code>enable-bort</code> command runs this ADB command under the hood:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">adb shell am broadcast --receiver-include-background \</span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain">  -a com.memfault.intent.action.BORT_ENABLE \</span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain">  -n your.app.id/com.memfault.bort.receivers.ShellControlReceiver \</span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain">  --ez com.memfault.intent.extra.BORT_ENABLED true</span><br></span></code></pre></div></div>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="trigger-metrics-collection-from-bort-manually">ii. Trigger metrics collection from the Android SDK manually<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#trigger-metrics-collection-from-bort-manually" class="hash-link" aria-label="Direct link to ii. Trigger metrics collection from the Android SDK manually" title="Direct link to ii. Trigger metrics collection from the Android SDK manually" translate="no">​</a></h3>
<p>You can request a Metrics collection using the <code>bort_cli.py</code> tool as well. To
enable these debugging utilities, we must first enable Developer Mode.</p>
<h4 class="anchor anchorTargetStickyNavbar_Vzrq" id="developer-mode">Developer Mode<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#developer-mode" class="hash-link" aria-label="Direct link to Developer Mode" title="Direct link to Developer Mode" translate="no">​</a></h4>
<p>On local development/test devices, the Android SDK can be placed into developer
mode. This can be useful for testing the AOSP integration or testing newly added
Custom Metrics.</p>
<p>Once in developer mode:</p>
<ul>
<li class="">Random upload jitter is removed (this is helpful to see diagnostic information
in the Memfault dashboard immediately).</li>
<li class=""><code>mar</code> files are uploaded immediately (instead of waiting to be bundled in a
single upload, as it normally would).</li>
<li class="">Metrics collection can be triggered on-demand. This will trigger Bort to
collect <code>batterystats</code> and Metrics - useful for validating new calls to the
<a class="" href="https://docs.memfault.com/docs/android/android-custom-metrics">Reporting APIs</a>.</li>
<li class="">Device configuration update can also be requested on-demand. This will trigger
the Android SDK to update settings from the Memfault server, including the
fleet-sampling configuration.</li>
<li class="">All client-side rate limits are bypassed. Server-side rate-limits may still be
in effect.</li>
</ul>
<p>To enable developer mode (change <code>true</code> to <code>false</code> to disable):</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">./bort_cli.py dev-mode --bort-app-id your.app.id --enabled true</span><br></span></code></pre></div></div>
<p>Then, request a metrics collection using:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">./bort_cli.py request-metrics --bort-app-id your.app.id</span><br></span></code></pre></div></div>
<!-- -->Server-side rate limiting will apply to the device you're using to work on the integration process. Once you can see the device on the Memfault Web App, consider enabling<!-- --> <a href="https://docs.memfault.com/docs/platform/rate-limiting#server-side-developer-mode">Server-Side Developer Mode</a> <!-- -->for it on the Memfault Web App to temporarily bypass these limits.<!-- -->
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="next-steps">Next Steps<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#next-steps" class="hash-link" aria-label="Direct link to Next Steps" title="Direct link to Next Steps" translate="no">​</a></h2>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="activate-your-first-ota-update"><a class="" href="https://docs.memfault.com/docs/android/android-releases-integration-guide">Activate your first OTA update</a><a href="https://docs.memfault.com/embed/android/android-getting-started-guide#activate-your-first-ota-update" class="hash-link" aria-label="Direct link to activate-your-first-ota-update" title="Direct link to activate-your-first-ota-update" translate="no">​</a></h3>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="collect-your-first-custom-metrics"><a class="" href="https://docs.memfault.com/docs/android/android-custom-metrics">Collect your first Metrics</a><a href="https://docs.memfault.com/embed/android/android-getting-started-guide#collect-your-first-custom-metrics" class="hash-link" aria-label="Direct link to collect-your-first-custom-metrics" title="Direct link to collect-your-first-custom-metrics" translate="no">​</a></h3>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="upload-a-bug-report">Request a test bug report<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#upload-a-bug-report" class="hash-link" aria-label="Direct link to Request a test bug report" title="Direct link to Request a test bug report" translate="no">​</a></h3>
<p>Once the SDK has been enabled, you can manually trigger a bug report to be
generated. Once generated, it will be automatically uploaded to Memfault:</p>
<div class="language-sh codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-sh codeBlock_bY9V thin-scrollbar" style="background-color:#282c34;color:#ffffff"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">./bort_cli.py request-bug-report --bort-app-id your.app.id</span><br></span></code></pre></div></div>
<p>More information on triggering a bug report can be found in
<a class="" href="https://docs.memfault.com/docs/android/android-bug-reports#triggering-a-bug-report-programmatically">Triggering A Bug Report Programmatically</a>;
more information on when bug reports are automatically captured can be found in
<a class="" href="https://docs.memfault.com/docs/android/android-bug-reports#bug-report-capture-period">Bug Report Capture Period</a>.</p>
<p>Once the bug report has been generated, uploaded and processed successfully, you
will be able to find it in Memfault by navigating to the <code>Fleet → Devices</code> view
and finding the device that uploaded the bug report.</p>
<p>If you do not see the bug report, you can check your project's
<a href="https://app.memfault.com/organizations/-/projects/-/integration-hub/processing-log" target="_blank" rel="noopener noreferrer" class="">Processing Log</a>
under the "Integration Hub" sub-menu. The Processing Log contains details on
what data has been received and processed by Memfault, as well as any error that
may have occurred.</p>
<p>A bug report's status will remain as <code>Stored</code> if the maximum number of bug
reports that will be analyzed from a device per day is reached.
<a class="" href="https://docs.memfault.com/docs/platform/metrics#quotas">Quotas</a> can be accessed from
<a href="https://app.memfault.com/organizations/-/projects/-/settings/quotas" target="_blank" rel="noopener noreferrer" class="">Settings → Quotas</a>.
When a bug report is <code>Processed</code>, the results of analysis can be viewed from the
respective Issue page.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="troubleshooting">Troubleshooting<a href="https://docs.memfault.com/embed/android/android-getting-started-guide#troubleshooting" class="hash-link" aria-label="Direct link to Troubleshooting" title="Direct link to Troubleshooting" translate="no">​</a></h2>
<p>See <a class="" href="https://docs.memfault.com/docs/android/android-troubleshooting">Troubleshooting</a>.</p>]]></content>
    </entry>
</feed>