<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Peak Tech: Behind the Scenes - Medium]]></title>
        <description><![CDATA[An insight into the technological innovation and design behind Peak. - Medium]]></description>
        <link>https://medium.com/peak-tech-behind-the-scenes?source=rss----d0858023c25---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Peak Tech: Behind the Scenes - Medium</title>
            <link>https://medium.com/peak-tech-behind-the-scenes?source=rss----d0858023c25---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 20:57:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/peak-tech-behind-the-scenes" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deploying an Android App]]></title>
            <link>https://medium.com/peak-tech-behind-the-scenes/deploying-an-android-app-a81fd1d9da78?source=rss----d0858023c25---4</link>
            <guid isPermaLink="false">https://medium.com/p/a81fd1d9da78</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[peak]]></category>
            <dc:creator><![CDATA[Peak]]></dc:creator>
            <pubDate>Mon, 11 May 2015 09:55:08 GMT</pubDate>
            <atom:updated>2015-05-28T15:34:07.812Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*olz-uffyr3aaEF6cngz4jw.jpeg" /></figure><p><em>CLÉMENT HÉLY</em></p><p>The current version of Peak for Android has 18 different brain training games, and we are committed to adding a new game for our users every month. This means that with every new version of the app, it grows in size by about 1.5 MiB (that’s the average increase, but some of our most complex games can weigh more than 5 MiB). Consequently, at the end of March 2015, our Android Application Package (APK) had almost reached 49.5 MiB, where the maximum size of an APK that can be uploaded to the Google Play Store is 50 MiB. So we needed to find a solution to either make the app lighter or go over the limit.</p><p>As games assets and resources represent the biggest part of our APK’s size (more than 50%), our only solution was to use APK expansion files. Offered by Google, this provides up to two files with a maximum size of 2 GiB each. These files are downloaded directly from the Play Store alongside the app’s APK. Thanks to these expansion files, we managed to reduce the size of our APK to less than half its original size. By doing this, we also made Peak highly scalable in terms of the number of games that we can package.</p><p>We decided to write this blog post to explain how we implemented the APK expansion files in Peak. Our case is particularly interesting since our games are developed using <a href="http://libgdx.badlogicgames.com/">libGDX</a>, which requires some specific development to be interfaced with APK expansion files.</p><h4>Building APK expansion files</h4><p><strong>Multi-flavour builds</strong></p><p>APK expansion files can only be downloaded to a device that has the Play Store app installed and is connected to a Google account (the 50 MiB limit only exists on the Play Store). With the size restriction in mind we wanted to build APKs that included every resource and asset, and be able to upload them to other marketplaces or sideload directly onto devices. Fortunately, thanks to <a href="http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Product-flavors">Gradle’s product flavours</a>, building several variants of the same application is a very simple process in the Android world.</p><p><em>Product flavours</em> are different versions of the same application, which either have different features or target different devices. They are different from <em>build types</em>, which are used to package or build a given app in different ways (e.g. development environment vs. production environment). Gradle will always build a combination of a product flavour and a build type.</p><p>The best way to implement APK expansion files and to continue being able to build the full application is to create two distinct product flavours: one targeting the Google Play Store (we’ll call it <strong>googlePlay</strong>) and the other including all the assets (we’ll call it <strong>full</strong>). Once these two flavours have been created, we only include all the assets in the full version not in the Google Play version. To be able to achieve this we create different asset folders and move all the game assets to the full flavour’s asset folder. However Gradle will not automatically know which folder to look for, so we have to declare different source sets for each flavour.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be8ac503ae7c77fb9c3e532f9e85d673/href">https://medium.com/media/be8ac503ae7c77fb9c3e532f9e85d673/href</a></iframe><p>Each flavour needs to have its own manifest as it is possible for each flavour to have different package names, application names and activities etc. There is still a main source set that is shared by all flavours to avoid duplication of code or assets. In Peak’s case the resources folder is common to all flavours; we only put the game assets in the expansion files.</p><p>Product flavours not only make it easy to have different assets but also offer the possibility to have variations in an application’s code or dependencies. This is important for Peak, as there is no need to import libraries related to expansion files or to check if these files have been downloaded in a full flavour build. The process for creating flavour-specific code is the same as for assets: create several source folders and declare their paths in each flavour’s source set.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c03327cd489d10063e5e208fbc740229/href">https://medium.com/media/c03327cd489d10063e5e208fbc740229/href</a></iframe><p>With Peak, every game is a different Android Library Project, and each project has its own assets (the app project only contains shared assets, like word dictionaries or HUD components). We have to create these flavours and apply the same architecture to all of our games. As all game projects are in the same folder, we can easily import them all by adding a dependency to the application project, for all subprojects of <strong>:games</strong>. When adding these flavours we have to change this dependency to import each game into the correct flavour. Gradle makes this really easy as compile dependencies can be made flavour-specific just by adding the name of the flavour.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fc7892822418a8fc1993b065f4d7b76/href">https://medium.com/media/0fc7892822418a8fc1993b065f4d7b76/href</a></iframe><p><strong>Gradle tasks to build expansion files</strong></p><p>With this structure in place, we needed a way to automatically build both expansion files, so that we can upload new files whenever we add a game. Expansion files can be provided in many different formats, and the Google Play Store will always treat them as binary files. We chose to provide ZIP archives as they are easy to package and use. Gradle comes with a Zip Task, which can be used to package any file type into a ZIP archive. Therefore we created two Zip Tasks: one to build the main expansion file and the other to create the patch file. Each task uses its own list of projects to know which games should be included in which expansion file. Whenever we add a new game, we only need to add the name of the project to the list of games to include in the patch file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09d08450a16c9f7f3c589c594916441a/href">https://medium.com/media/09d08450a16c9f7f3c589c594916441a/href</a></iframe><p>We can execute these tasks manually, whenever needed, but they are automatically run when building Peak in the <strong>googlePlay</strong> flavour. To do this we simply added this snippet of code to our build script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3dbf3f4cda65e43441044e8c075f5465/href">https://medium.com/media/3dbf3f4cda65e43441044e8c075f5465/href</a></iframe><p>The reason for applying these dependencies to the debug build type and not the release type build is that currently we do not have an automatic way to retrieve the size of the archives being generated. Knowing the size of both archives is necessary to check if they have been downloaded correctly. At the moment we need to build expansion files first, declare their sizes in the <strong>BuildConfig</strong> so they are accessible in several places in the code, and then build the APK again using the Release build type.</p><p>We do not update the main expansion file, only the patch file. Every time a user updates their version of Peak and the main expansion file attached to this version has not changed, they will only have to download the patch expansion file. Since the main archive is about 25 MiB and the patch one is only a few hundred kilobytes, we can continue to put new content only in the patch file. When the patch file starts to get too heavy, we can transfer all or part of its content to a new main file. This limits the amount of data downloaded for every update.</p><h4>Integrating expansion files into Peak</h4><p>Now we’ll explain how to check if APK expansion files have been correctly downloaded. It’s important to do this check before trying to access their content; in some (rare) cases expansion files will not have been properly downloaded with the APK. You can refer to the <a href="http://developer.android.com/google/play/expansion-files.html#Downloading">Android documentation</a> to learn more.</p><p><strong>Loading game assets from zip files</strong></p><p>As mentioned earlier, all our games are developed using <a href="http://libgdx.badlogicgames.com/">libGDX</a>. This game engine provides asset managers which are responsible for loading assets and handling their lifecycle. By default, the libGDX asset managers look for assets in the “assets” folder inside the APK, using the default <a href="https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/assets/loaders/resolvers/InternalFileHandleResolver.java">InternalFileHandleResolver</a>. While it is possible to provide other <strong>FileHandleResolver</strong> classes to look for assets elsewhere on the device, none of those provided can load files directly from a zip archive. We had to create a custom <strong>FileHandleResolver</strong> and <strong>FileHandle</strong> to be able to load assets directly from expansion files, without having to unzip everything. This can be a resource-expensive process that can cause conflicts after an update.</p><p>The inspiration for the <strong>FileHandleResolver</strong> and <strong>FileHandle</strong> implementation came from a <a href="https://gist.github.com/MobiDevelop/5514357">post shared by MobiDevelop on GitHub</a>.</p><p>We added support for the patch expansion file by declaring two ZipFile objects in the <strong>FileHandleResolver</strong> and passing both of them as parameters when creating the <strong>FileHandle</strong>. Inside the <strong>FileHandle</strong>, we check which of the expansion file contains the asset we are looking for and we store this in a boolean.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1abc2c4f5e183187b34670b6fe35e03/href">https://medium.com/media/b1abc2c4f5e183187b34670b6fe35e03/href</a></iframe><p>When actually loading the asset (in the <strong>read()</strong> method of our <strong>FileHandle</strong>), we can create an <strong>InputStream</strong> object from the right expansion file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aea0a2d02473299d43b693bf546c45e6/href">https://medium.com/media/aea0a2d02473299d43b693bf546c45e6/href</a></iframe><p><strong>In the case of sounds…</strong></p><p>Most assets can be loaded by libGDX regardless of their location, however sounds are an exception. Sounds cannot be loaded with a custom <strong>FileHandle</strong>, their <strong>FileHandle</strong> is cast to an A<strong>ndroidFileHandle</strong> when creating the Sound object. <strong>AndroidFileHandle</strong>’s constructors are both package-private, and it is therefore impossible to extend this class. Even after solving this cast issue it would be impossible to load sounds from ZIP files, as the sounds pool cannot read files from memory (see: <a href="https://github.com/libgdx/libgdx/pull/2565">https://github.com/libgdx/libgdx/pull/2565</a>).</p><p>The only workaround to this problem is to extract sounds somewhere else on the device’s storage before trying to load them. libGDX makes it possible to load different types of assets in different ways. It is easy to load all assets from expansion files except sounds and to create another <strong>FileHandleResolver</strong> for sounds so they are loaded from the folder they are extracted to. We extended <strong>AbsoluteFileHandleResolver</strong> and made it so that its resolve(<strong>String</strong>) method will look for sounds using the correct path.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84add41bf7e7b5b6516f75d9a83abef0/href">https://medium.com/media/84add41bf7e7b5b6516f75d9a83abef0/href</a></iframe><p>Initially we were extracting sounds to Android external storage, where they can be retrieved using the following path <strong>Environment.getExternalStorageDirectory()</strong>. We realised however that making the files world-readable meant users could delete them and not have sounds when playing the games. To solve this, we now extract sounds to the internal storage, using the <strong>getFilesDir()</strong> method of the <strong>Context</strong> object. This path doesn’t require any permission to be written to and will not be accessible to users who have not rooted their device.</p><p>A good example of how to extract files from a zip archive programmatically can be found on this <a href="http://stackoverflow.com/a/23895411">Stack Overflow post</a>.</p><h4>Useful links</h4><p><a href="http://developer.android.com/google/play/expansion-files.html">http://developer.android.com/google/play/expansion-files.html</a></p><p><a href="http://stackoverflow.com/questions/11715855/steps-to-create-apk-expansion-file">http://stackoverflow.com/questions/11715855/steps-to-create-apk-expansion-file</a></p><p><a href="http://stackoverflow.com/questions/22368251/how-to-make-android-extension-file-using-android-studio">http://stackoverflow.com/questions/22368251/how-to-make-android-extension-file-using-android-studio</a></p><p><a href="http://badlogicgames.com/forum/viewtopic.php?f=11&amp;t=5752">http://badlogicgames.com/forum/viewtopic.php?f=11&amp;t=5752</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a81fd1d9da78" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peak-tech-behind-the-scenes/deploying-an-android-app-a81fd1d9da78">Deploying an Android App</a> was originally published in <a href="https://medium.com/peak-tech-behind-the-scenes">Peak Tech: Behind the Scenes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Behind the Scenes: 
Street Nav — A 3D Game with SceneKit]]></title>
            <link>https://medium.com/peak-tech-behind-the-scenes/behind-the-scenes-street-nav-a-3d-game-with-scenekit-c81b23b864d3?source=rss----d0858023c25---4</link>
            <guid isPermaLink="false">https://medium.com/p/c81b23b864d3</guid>
            <dc:creator><![CDATA[Peak]]></dc:creator>
            <pubDate>Fri, 07 Nov 2014 14:28:43 GMT</pubDate>
            <atom:updated>2014-11-07T12:53:55.633Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XcgZ_64KM_0KfG8RbHDfMQ.jpeg" /></figure><h3>Behind the Scenes:<br>Street Nav — A 3D Game with SceneKit</h3><p><em>LOURENÇO BOTELHO</em></p><h4>Game Layers</h4><p>Here at Peak, we have a library of more than 20 brain games that are designed to tackle specific cognitive challenges. In the early days of their design, it became clear to us that all these games share common elements such as score, timer, pause panel, feedback animations, as well as the cognitive data collection process. In order to avoid code duplication, we opted for the architecture represented in this diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*JVde359m6SOi3hR5NPaWBg.png" /></figure><p>Here we can see two layers — one for the individual game (GAME view), and one for the common elements (HUD view). They both communicate with a Game Controller. The GAME view is responsible for rendering the game play. It has to conform to a [GameProtocol] to be able to receive instructions from the game controller, such as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33926d6c956012ddc7611fb4ab8dd22c/href">https://medium.com/media/33926d6c956012ddc7611fb4ab8dd22c/href</a></iframe><p>and to communicate back through a set of methods, for example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e407c07fec221fce7d3f72de7d0ed1f/href">https://medium.com/media/0e407c07fec221fce7d3f72de7d0ed1f/href</a></iframe><p>Our first collection of games was developed using Sprite Kit, where both the GAME view and the HUD view are subclasses of [SKView].</p><p>The cornerstone of the Peak ethos is innovation, and that means we always try to push the boundaries of conventionality by using the latest technologies to improve user experience, providing better training every day. So when Apple announced their new SceneKit framework, the team sat down to figure out how this could benefit our users. There we were, moving between 3D blocks, rotating, trying to figure out where we were, when we saw what was right in front of us the whole time: Spatial Working Memory! It was clear that we had the ingredients to create an immersive game that could challenge this important cognitive skill.</p><p>The beauty of our architectural approach is that it was quite simple to extend, and to allow Game View to be a subclass of [SCNView] (SceneKit) or [UIWebView] (HTML5), since it conforms to our [GameProtocol].</p><h4>Working with SceneKit</h4><p>First, we created the world in which the game would take place.</p><p>Our design team went to work to build an interface that would look both beautiful and simple, in tune with the rest of the app. We used the standard COLLADA file because of its wide compatibility in both software applications that manipulate it and platforms that can read it. Loading a SCNNode from a file is as simple as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be5ed10e672623994e5245d05420c934/href">https://medium.com/media/be5ed10e672623994e5245d05420c934/href</a></iframe><p>Now it was just a matter of generating as many blocks, or buildings, as we needed, and organising them appropriately to create a mini city.</p><p>Second, the task of navigating this world.</p><p>In SceneKit you see the world through a camera you control. For that you just need to create a normal SCNNode and attach a SCNCamera to it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cae4aaf792f77a1058c3a327e3b5905/href">https://medium.com/media/3cae4aaf792f77a1058c3a327e3b5905/href</a></iframe><p>Now you can just use the normal properties of the SCNNode to move the camera around and control your point of view. In our game this gives you the ability to run around the mini city and try to find your designated destination.</p><p>And thus <em>Street Nav </em>was born — now playable in Peak 1.4, available in the <a href="https://itunes.apple.com/app/peak-brain-training/id806223188">App Store</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N4wsctWo9u9VMvternRghQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c81b23b864d3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peak-tech-behind-the-scenes/behind-the-scenes-street-nav-a-3d-game-with-scenekit-c81b23b864d3">Behind the Scenes: 
Street Nav — A 3D Game with SceneKit</a> was originally published in <a href="https://medium.com/peak-tech-behind-the-scenes">Peak Tech: Behind the Scenes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>