Thursday, October 20, 2016

New video tips to help news publishers find success on Google Play

Posted by Tamzin Taylor - Strategic Partner Lead, Google Play





Today we have released a three-part video series ‘Tips for
your news app on Google Play’
, where you can find actionable tips
and learn best practices for developing, launching and monetising a high quality
news app. The video series accompanies the recently published href="https://play.google.com/store/books/details/Google_Inc_The_News_Publisher_Playbook_for_Android?id=O7T3CwAAQBAJ">News
Publisher Playbook
.

href="https://www.youtube.com/playlist?list=PLWz5rJ2EKKc_ElGrEtiEXc83m1SeYu3-Q">Watch
the video series
to learn:

  • 10 tips on how to design and develop your News app
  • 10 tips to help you launch your News app and start gaining readers
  • 10 tips to engage your readers and monetize your News app




You can also href="https://play.google.com/store/books/details/Google_Inc_The_News_Publisher_Playbook_for_Android?id=O7T3CwAAQBAJ&hl=en_GB">get
the News Publisher Playbook on the Play Store
to help you develop a
successful news mobile strategy on Android. It includes tips on mobile website
optimization, how to create a Google Play Newsstand edition, how to improve your
native app, and more.

Give us your feedback

Once you’ve checked out the video series, we’d love to hear your feedback so we
can continue to help you find success with and achieve your business objectives.
Leave a comment or a thumbs up, and href="https://www.youtube.com/channel/UCVHFbqXqoYvEWM1Ddxl0QDg?sub_confirmation=1">subscribe
to the Android Developers YouTube channel
!

Also, href="https://www.youtube.com/playlist?list=PLWz5rJ2EKKc_ElGrEtiEXc83m1SeYu3-Q">check
out our other videos in in the Tips for Success on Google Play series
,
including the recent video on href="https://www.youtube.com/watch?v=PfwHq8w9GBc&list=PLWz5rJ2EKKc_ElGrEtiEXc83m1SeYu3-Q&index=11">10
tips to build an app for billions of users
.

For more best practices to find success on Google Play, href="http://g.co/play/playbook-androiddevblogposts-evergreen">get the new
Playbook for Developers app
.








Wednesday, October 19, 2016

Improving Stability with Private C/C++ Symbol Restrictions in Android N


Posted by Dimitry Ivanov & Elliott Hughes, Software Engineers



As documented in the href="https://developer.android.com/preview/behavior-changes.html#ndk">Android N
behavioral changes
, to protect Android users and apps from unforeseen
crashes, Android N will restrict which libraries your C/C++ code can link
against at runtime
. As a result, if your app uses any private symbols from
platform libraries, you will need to update it to either use the public NDK APIs
or to include its own copy of those libraries. Some libraries are public: the
NDK exposes libandroid, libc, libcamera2ndk, libdl,
libGLES, libjnigraphics, liblog, libm, libmediandk, libOpenMAXAL, libOpenSLES,
libstdc++, libvulkan, and libz as part of the NDK API. Other libraries are
private, and Android N only allows access to them for platform HALs, system
daemons, and the like. If you aren’t sure whether your app uses private
libraries, you can immediately check it for warnings on the N Developer Preview.


We’re making this change because it’s painful for users when their apps stop
working after a platform update. Whether they blame the app developer or the
platform, everybody loses. Users should have a consistent app experience across
updates, and developers shouldn’t have to make emergency app updates to handle
platform changes. For that reason, we recommend against using private C/C++
symbols. Private symbols aren’t tested as part of the Compatibility Test Suite
(CTS) that all Android devices must pass. They may not exist, or they may behave
differently. This makes apps that use them more likely to fail on specific
devices, or on future releases — as many developers found when Android 6.0
Marshmallow switched from OpenSSL to BoringSSL.


You may be surprised that there’s no STL in the list of NDK libraries. The three
STL implementations included in the NDK — the LLVM libc++, the GNU STL, and
libstlport — are intended to be bundled with your app, either by statically
linking into your library, or by inclusion as a separate shared library. In the
past, some developers have assumed that they didn’t need to package the library
because the OS itself had a copy. This assumption is incorrect: a particular STL
implementation may disappear (as was the case with stlport, which was removed in
Marshmallow), may never have been available (as is the case with the GNU STL),
or it may change in ABI incompatible ways (as is the case with the LLVM libc++).


In order to reduce the user impact of this transition, we’ve identified a set of
libraries that see significant use from Google Play’s most-installed apps, and
that are feasible for us to support in the short term (including
libandroid_runtime.so, libcutils.so, libcrypto.so, and libssl.so). For legacy
code in N, we will temporarily support these libraries in order to give you more
time to transition. Note that we don't intend to continue this support in any
future Android platform release, so if you see a warning that means your code
will not work in a future release — please fix it now!



Table 1. What to expect if your app is linking against private native libraries.

LibrariesApp's targetSdkVersionRuntime access via dynamic linkerImpact, N Developer PreviewImpact, Final N ReleaseImpact, future platform version
NDK PublicAnyAccessible
Private (graylist)<=23Temporarily accessibleWarning / ToastWarningError
>=24RestrictedErrorErrorError
Private (all other)>AnyRestrictedErrorErrorError



What behavior will I see?



Please test your app during the N Previews.


N Preview behavior



  • All public NDK libraries (libandroid, libc, libcamera2ndk, libdl, libGLES,
    libjnigraphics, liblog, libm, libmediandk, libOpenMAXAL, libOpenSLES, libstdc++,
    libvulkan, and libz), plus libraries that are part of your app are accessible.
  • For all other libraries you’ll see a warning in logcat and a toast on the
    display. This will happen only if your app’s targetSdkVersion is less than N. If
    you change your manifest to target N, loading will fail: Java’s
    System.loadLibrary will throw, and C/C++’s dlopen(3) will return NULL.




Test your apps on the Developer Preview — if you see a toast like this one, your app is accessing private native APIs. Please fix your code soon!



N Final Release behavior



  • All NDK libraries (libandroid, libc, libcamera2ndk, libdl, libGLES,
    libjnigraphics, liblog, libm, libmediandk, libOpenMAXAL, libOpenSLES, libstdc++,
    libvulkan, and libz), plus libraries that are part of your app are accessible.
  • For the temporarily accessible libraries (such as libandroid_runtime.so,
    libcutils.so, libcrypto.so, and libssl.so), you’ll see a warning in logcat for
    all API levels before N, but loading will fail if you update your app so that
    its targetSdkVersion is N or later.
  • Attempts to load any other libraries will fail in the final release of
    Android N, even if your app is targeting a pre-N platform version.



Future platform behavior



  • In O, all access to the temporarily accessible libraries will be removed.
    As a result, you should plan to update your app regardless of your
    targetSdkVersion prior to O. If you believe there is missing functionality from
    the NDK API that will make it impossible for you to transition off a temporarily
    accessible library, please file a bug here.



What do the errors look like?



Here’s some example logcat output from an app that hasn’t bumped its target SDK
version (and so the restriction isn’t fully enforced because this is only the
developer preview):




03-21 17:07:51.502 31234 31234 W linker  : library "libandroid_runtime.so"
("/system/lib/libandroid_runtime.so") needed or dlopened by
"/data/app/com.popular-app.android-2/lib/arm/libapplib.so" is not accessible
for the namespace "classloader-namespace" - the access is temporarily granted
as a workaround for http://b/26394120


This is telling you that your library “libapplib.so” refers to the library
“libandroid_runtime.so”, which is a private library.


When Android N ships, or if you set your target SDK version to N now, you’ll see
something like this if you try to use System.loadLibrary from Java:

java.lang.UnsatisfiedLinkError: dlopen failed: library "libcutils.so"
("/system/lib/libcutils.so") needed or dlopened by "/system/lib/libnativeloader.so"
is not accessible for the namespace "classloader-namespace"
  at java.lang.Runtime.loadLibrary0(Runtime.java:977)
  at java.lang.System.loadLibrary(System.java:1602)


If you’re using href="http://man7.org/linux/man-pages/man3/dlopen.3.html">dlopen(3) from
C/C++ you’ll get a NULL return and href="http://man7.org/linux/man-pages/man3/dlerror.3.html">dlerror(3) will
return the same “dlopen failed...” string as shown above.


For more information about how to check if your app is using private symbols,
see the FAQ on developer.android.com.

Tuesday, October 18, 2016

Announcing the Google Play Indie Games Festival in San Francisco, Sept. 24

Posted by Jamil Moledina, Google Play, Games Strategic Lead


If you’re an indie game developer, you know that games are a powerful medium of
expression of art, whimsy, and delight. Being on Google Play can help you reach
over a billion users and build a successful, global business. That’s why we
recently introduced programs, like the href="https://play.google.com/store/info/topic?id=topic_b000054_games_indie_corner_tp&e=-EnableAppDetailsPageRedesign">Indie
Corner
, to help more gamers discover your works of art.


To further celebrate and showcase the passion and innovation of indie game
developers, we’re hosting the Google Play Indie Games Festival at the href="https://www.google.com/maps/place/Terra+Gallery+%26+Event+Venue/@37.785531,-122.3929643,15z/data=!4m5!3m4!1s0x0:0xf5fb5bcb9c7795ab!8m2!3d37.785531!4d-122.3929643">Terra
Gallery
in San Francisco, on September 24.





This is a great opportunity for you to showcase your indie title to the public,
increase your network, and compete to win great prizes, such as Tango devices,
free tickets for Google I/O 2017, and Google ad campaign support. Admission will
be free and players will get the chance to play and vote on their favorites.


If you’re interested in showcasing your game, we’re href="https://docs.google.com/a/google.com/forms/d/e/1FAIpQLSduaM998L0WXm_4znsZjHX5-unZLBChNXHuCHbTlWuAcmMNmQ/viewform">accepting
submissions
now through August 14. We’ll then select high-quality games that
are both innovative and fun for the festival. Submissions are open to US and
Canadian developers with 15 or less full time staff. Only games published on or
after January 1, 2016 or those to be published by December 31, 2016 are
eligible. See href="https://docs.google.com/a/google.com/forms/d/e/1FAIpQLSduaM998L0WXm_4znsZjHX5-unZLBChNXHuCHbTlWuAcmMNmQ/viewform">complete
rules
.


We encourage virtual reality and augmented reality game submissions that use the
Google VR SDK and the href="https://store.google.com/product/tango_tablet_development_kit?srp=/product/project_tango_tablet_development_kit">Tango
Tablet Development Kit
.


At the end of August, we’ll announce the group of indies to be featured at the
festival.


You can learn more about the event href="https://events.withgoogle.com/google-play-indie-game-festival/">here.
We can’t wait to see what innovative and fun experiences you share with us!


Android Wear 2.0 Developer Preview 2

Android Wear 2.0 Developer Preview 2


Posted by Hoi Lam, Android Wear
Developer Advocate


At Google I/O 2016, we launched the Android
Wear 2.0 Developer Preview, which gives developers early access to the next
major release of Android Wear. Since I/O, feedback from the developer community
has helped us identify bugs and shape our product direction. Thank you!


Today, we are releasing the second developer preview with new functionalities
and bug fixes. Prior to the consumer release, we plan to release additional
updates, so please send us your
feedback early and often. Please keep in mind that this preview is a work in
progress, and is not yet intended for daily use.

What’s new?



 public class MainActivity extends Activity {  
   ...    
   @Override /* KeyEvent.Callback */  
   public boolean onKeyDown(int keyCode, KeyEvent event) {  
     switch (keyCode) {  
       case KeyEvent.KEYCODE_NAVIGATE_NEXT:  
         Log.d(TAG, "Next");  
         break;  
       case KeyEvent.KEYCODE_NAVIGATE_PREVIOUS:  
         Log.d(TAG, "Previous");  
         break;  
     }  
     // If you did not handle, then let it be handled by the next possible element as deemed by  
     // Activity.  
     return super.onKeyDown(keyCode, event);  
   }  
 }  


Get started and give us feedback!



The Android Wear 2.0 Developer Preview includes an updated SDK with tools and
system images for testing on the official Android emulator, the href="https://store.google.com/product/lg_watch_urbane_2nd_edition_lte">LG Watch
Urbane 2nd Edition LTE
, and the href="https://store.google.com/product/huawei_watch">Huawei Watch.


To get started, follow these steps:

  1. Take a video tour
    of the Android Wear 2.0 developer preview
  2. Update to Android Studio v2.1.1 or later
  3. Visit the Android Wear 2.0 Developer
    Preview site for downloads and documentation
  4. Get the emulator system images through the SDK Manager or href="https://developer.android.com/wear/preview/downloads.html?utm_campaign=android wear_launch_preview2_071216&utm_source=anddev&utm_medium=blog">download the
    device system images from the developer preview downloads page
  5. Test your app with your supported device or emulator
  6. Give us feedback


We will update this developer preview over the next few months based on your
feedback. The sooner we hear from you, the more we can include in the final
release, so don't be shy!

Final Developer Preview before Android 7.0 Nougat begins rolling out


Posted by Dave Burke, VP of Engineering





As we close in on the public rollout of href="https://developer.android.com/preview/index.html?utm_campaign=android_launch_developerpreview5_071816&utm_source=anddev&utm_medium=blog">Android 7.0 Nougat
to devices later this summer, today we’re releasing Developer Preview
5
, the last milestone of this preview series. href="http://android-developers.blogspot.com/2016/06/android-n-apis-are-now-final.html">Last
month’s
Developer Preview included the final APIs for Nougat; this preview
gives developers the near-final system updates for all of the supported preview
devices, helping you get your app ready for consumers.


Here’s a quick rundown of what’s included in the final Developer Preview of
Nougat:

  • System images for Nexus and other preview devices
  • An emulator that you can use for doing the final testing of your apps to
    make sure they’re ready
  • The final N APIs (API level 24) and latest system behaviors and UI
  • The latest bug fixes and optimizations across the system and in preinstalled
    apps


Working with this latest Developer Preview, you should make sure your app
handles all of the href="https://developer.android.com/preview/behavior-changes.html?utm_campaign=android_launch_developerpreview5_071816&utm_source=anddev&utm_medium=blog">system
behavior changes in Android N
, like Doze on the Go, background
optimizations, screen zoom, permissions changes, and more. Plus, you can take
advantage of href="https://developer.android.com/preview/api-overview.html?utm_campaign=android_launch_developerpreview5_071816&utm_source=anddev&utm_medium=blog">new developer
features in Android N
such as href="https://developer.android.com/preview/api-overview.html?utm_campaign=android_launch_developerpreview5_071816&utm_source=anddev&utm_medium=blog#multi-window_support">Multi-window
support
, Direct Reply and other href="https://developer.android.com/preview/api-overview.html?utm_campaign=android_launch_developerpreview5_071816&utm_source=anddev&utm_medium=blog#notification_enhancements">notifications
enhancements
, href="https://developer.android.com/preview/api-overview.html?utm_campaign=android_launch_developerpreview5_071816&utm_source=anddev&utm_medium=blog#direct_boot">Direct
boot
, href="https://developer.android.com/preview/api-overview.html?utm_campaign=android_launch_developerpreview5_071816&utm_source=anddev&utm_medium=blog#emoji">new
emojis
and more.


Publish your apps to alpha, beta or production channels in Google
Play



After testing your apps with Developer Preview 5 you should publish the updates
to Google Play soon. We recommend compiling against, and optionally targeting,
API 24 and then publishing to your alpha, beta, or production channels in the
Google Play Developer Console. A great strategy to do this is using href="https://developer.android.com/distribute/engage/beta.html?utm_campaign=android_launch_npreview_061516&utm_source=anddev&utm_medium=blog">Google
Play’s beta testing feature
to get early feedback from a small group of
users -- including Developer Preview users — and then doing a staged rollout as
you release the updated app to all users.


How to get Developer Preview 5


If you are already enrolled in the Android
Beta program, your devices will get the Developer Preview 5 update right
away, no action is needed on your part. If you aren’t yet enrolled in Android
Beta, the easiest way to get started is by visiting href="https://android.com/beta">android.com/beta and opt-in your eligible
Android phone or tablet -- you’ll soon receive this preview update over-the-air.
As always, you can also download and href="https://developer.android.com/preview/download.html?utm_campaign=android_launch_npreview_061516&utm_source=anddev&utm_medium=blog#flash">flash
this update manually
. The Nougat Developer Preview is available for Nexus 6,
Nexus 5X, Nexus 6P, Nexus 9, and Pixel C devices, as well as General Mobile 4G
[Android One] devices.


Thanks so much for all of your feedback so far. Please continue to share
feedback or requests either in the href="https://code.google.com/p/android/issues/list?can=2&q=label%3ADevPreview-N">N
Developer Preview issue tracker
, href="https://plus.google.com/communities/103655397235276743411">N Preview
Developer community
, or href="https://plus.google.com/communities/106765800802768335079">Android Beta
community
as we work towards the consumer release later this summer. Android
Nougat is almost here!


Also, the Android engineering team will host a Reddit AMA on r/androiddev to
answer all your technical questions about the platform tomorrow, July 19
from 12-2 PM (Pacific Time)
. We look forward to addressing your
questions!

Android Developer Story: StoryToys finds success in the ‘Family’ section on Google Play


Posted by Lily Sheringham, Google Play team


Based in Dublin, Ireland, href="https://play.google.com/store/apps/dev?id=8762313232916265908">StoryToys
is a leading publisher of interactive books and games for children. Like most
kids’ app developers, they faced the challenges of engaging with the right
audiences to get their content discovered. Since the launch of the Family
section on Google Play, StoryToys has experienced an uplift of 270% in revenue
and an increase of 1300% in downloads.


Hear Emmet O’Neill, Chief Product Officer, and Gavin Barrett, Commercial
Director, discuss how the Family section creates a trusted and creative space
for families to find new content. Also hear how beta testing, localized pricing
and more, has allowed StoryToy’s flagship app, href="https://play.google.com/store/apps/details?id=com.storytoys.myveryhungrycaterpillar.free.android.googleplay">My
Very Hungry Caterpillar
, to significantly increase engagement and revenue.



href="https://developer.android.com/distribute/googleplay/families/about.html">Learn
more about Google Play for Families
and href="http://g.co/play/playbook-androiddevblogposts-evergreen">get the Playbook
for Developers app
to stay up-to-date with more features and best practices
that will help you grow a successful business on Google Play.
Connecting your App to a Wi-Fi Device

Connecting your App to a Wi-Fi Device


Posted by Rich Hyndman, Android Developer Advocate



With the growth of the Internet of Things, connecting Android applications to
Wi-Fi enabled devices is becoming more and more common. Whether you’re building
an app for a remote viewfinder, to set up a connected light bulb, or to control
a quadcopter, if it’s Wi-Fi based you will need to connect to a hotspot that may
not have Internet connectivity.


From Lollipop onwards the OS became a little more intelligent, allowing multiple
network connections and not routing data to networks that don’t have Internet
connectivity. That’s very useful for users as they don’t lose connectivity when
they’re near Wi-Fis with captive portals. Data routing APIs were added for
developers, so you can ensure that only the appropriate app traffic is routed
over the Wi-Fi connection to the external device.


To make the APIs easier to understand, it is good to know that there are 3 sets
of networks available to developers:


In all versions of Android you start by scanning for available Wi-Fi networks
with href="https://developer.android.com/reference/android/net/wifi/WifiManager.html#startScan()">WiFiManager#startScan,
iterate through the href="https://developer.android.com/reference/android/net/wifi/ScanResult.html">ScanResults
looking for the SSID of your external Wi-Fi device. Once you’ve found it you can
check if it is already a configured network using href="https://developer.android.com/reference/android/net/wifi/WifiManager.html#getConfiguredNetworks()">WifiManager#getConfiguredNetworks
and iterating through the href="https://developer.android.com/reference/android/net/wifi/WifiConfiguration.html">WifiConfigurations
returned, matching on SSID. It’s worth noting that the SSIDs of the configured
networks are enclosed in double quotes, whilst the SSIDs returned in href="https://developer.android.com/reference/android/net/wifi/ScanResult.html">ScanResults
are not.


If your network is configured you can obtain the network ID from the
WifiConfiguration object. Otherwise you can configure it using href="https://developer.android.com/reference/android/net/wifi/WifiManager.html#addNetwork(android.net.wifi.WifiConfiguration)">WifiManager#addNetwork
and keep track of the network id that is returned.


To connect to the Wi-Fi network, register a BroadcastReceiver that listens for
href="https://developer.android.com/reference/android/net/wifi/WifiManager.html#NETWORK_STATE_CHANGED_ACTION">WifiManager.NETWORK_STATE_CHANGED_ACTION
and then call href="https://developer.android.com/reference/android/net/wifi/WifiManager.html#enableNetwork(int,%20boolean)">WifiManager.enableNetwork
(int netId, boolean disableOthers)
, passing in your network ID. The
enableNetwork call disables all the other Wi-Fi access points for the next scan,
locates the one you’ve requested and connects to it. When you receive the
network broadcasts you can check with href="https://developer.android.com/reference/android/net/wifi/WifiManager.html#getConnectionInfo()">WifiManager#getConnectionInfo
that you’re successfully connected to the correct network. But, on Lollipop and
above, if that network doesn’t have internet connectivity network, requests will
not be routed to it.


Routing network requests


To direct all the network requests from your app to an external Wi-Fi device,
call href="https://developer.android.com/reference/android/net/ConnectivityManager.html#setProcessDefaultNetwork(android.net.Network)">ConnectivityManager#setProcessDefaultNetwork
on Lollipop devices, and on Marshmallow call href="https://developer.android.com/reference/android/net/ConnectivityManager.html#bindProcessToNetwork(android.net.Network)">ConnectivityManager#bindProcessToNetwork
instead, which is a direct API replacement. Note that these calls require
android.permission.INTERNET; otherwise they will just return false.


Alternatively, if you’d like to route some of your app traffic to the Wi-Fi
device and some to the Internet over the mobile network:


Now you can keep your users connected whilst they benefit from your innovative
Wi-Fi enabled products.

Tuesday, August 23, 2016

Improvements for smaller app downloads on Google Play

Posted by Anthony Morris, SWE Google Play


Google Play continues to grow rapidly, as Android users installed over 65
billion apps in the last year from the Google Play Store. We’re also seeing
developers move to update their apps more frequently to push great new content,
patch security vulnerabilities, and iterate quickly on user feedback.


However, many users are sensitive to the amount of data they use, especially if
they are not on Wi-Fi. Google Play is investing in improvements to reduce the
data that needs to be transferred for app installs and updates, while making
data cost more transparent to users.


Read on to understand the updates and learn some tips for ways to optimize the
size of your APK.

New Delta algorithm to reduce the size of app updates



For approximately 98% of app updates from the Play Store, only changes(deltas) to APK files are downloaded and merged with the existing
files, reducing the size of updates. Google Play has used delta algorithms since 2012, and we recently rolled out an additional delta algorithm, href="http://www.daemonology.net/bsdiff/">bsdiff href="http://www.daemonology.net/bsdiff/">(created by Colin Percivalid="fnref1">1href="http://www.daemonology.net/bsdiff/">), that our experimentation shows
can reduce delta size by up to 50% or more compared to the previous algorithm
for some APKs. Bsdiff is
specifically targeted to produce more efficient deltas of native libraries by
taking advantage of the specific ways in which compiled native code changes
between versions. To be most effective, native libraries should be stored
uncompressed (compression interferes with delta algorithms).


An example from Chrome:


Patch Description



Previous patch size

Bsdiff Size





M46 to M47 major update

22.8 MB

12.9 MB




M47 minor update

15.3 MB

3.6 MB





Apps that don’t have uncompressed native libraries can see a 5% decrease in size
on average, compared to the previous delta algorithm.

Applying the delta algorithm to APK Expansion Files to further
reduce update size



APK Expansion Files allow you to include additional large files up to 2GB in
size (e.g. high resolution graphics or media files) with your app, which is
especially popular with games. We have recently expanded our delta and
compression algorithms to apply to these APK Expansion Files in addition to
APKs, reducing the download size of initial installs by 12%, and updates by 65%
on average. APK Expansion file patches use the href="http://xdelta.org/">xdelta algorithm.

Clearer size information in the Play Store



Alongside the improvements to reduce download size, we also made information
displayed about data used and download sizes in the Play Store clearer. You can
now see actual download sizes, not the APK file size, in the Play Store. If you
already have an app, you will only see the update size. These changes are
rolling out now.






  1. Colin Percival, Naive differences of executable code,
    http://www.daemonology.net/bsdiff/, 2003. 




Example 1: Showing new “Download size” of APK




Example 2: Showing new “Update size” of APK



Tips to reduce your download sizes


1. Optimize for the right size measurements: Users care about download size (i.e. how many bytes are transferred when installing/updating an app), and they care about disk size (i.e. how much space the app takes up on disk). It’s important to note that neither of these are the same as the original APK file size nor necessarily correlated.



Chrome example:


























Compressed Native Library Uncompressed Native Library
APK Size 39MB 52MB (+25%)
Download size (install) 29MB 29MB (no change)
Download size (update) 29MB 21MB (-29%)
Disk size 71MB 52MB (-26%)



Chrome found that initial download size remained the same by not compressing the native library in their APK, while the APK size increased, because Google Play already performs compression for downloads. They also found that the update size decreased, as deltas are more effective with uncompressed files, and disk size decreased as you no longer need an compressed copy of the native library. However, please note, native libraries should only be uncompressed when the minimum SDK version for an APK is 23 (Marshmallow) or later.

2. Reduce your APK size: Remove unnecessary data from the APK like unused resources and code.

3. Optimize parts of your APK to make them smaller: Using more efficient file formats, for example by using WebP instead of JPEG, or by using Proguard to remove unused code.

href="https://medium.com/google-developers/smallerapk-part-1-anatomy-of-an-apk-da83c25e7003#.jgy8wuni9">Read
more about reducing APK sizes
and watch the I/O 2016 session href="https://www.youtube.com/watch?v=xctGIB81D2w">‘Putting Your App on a
Diet’
to learn from
Wojtek KaliciƄski, about how to reduce the size of your APK
.

Wednesday, August 17, 2016

Protecting Android with more Linux kernel defenses

Protecting Android with more Linux kernel defenses



Posted by Jeff Vander Stoep, Android Security team



Android relies heavily on the Linux kernel for enforcement of its security
model. To better protect the kernel, we’ve enabled a number of mechanisms within
Android. At a high level these protections are grouped into two
categories—memory protections and attack surface reduction.

Memory protections



One of the major security features provided by the kernel is memory protection
for userspace processes in the form of address space separation. Unlike
userspace processes, the kernel’s various tasks live within one address space
and a vulnerability anywhere in the kernel can potentially impact unrelated
portions of the system’s memory. Kernel memory protections are designed to
maintain the integrity of the kernel in spite of vulnerabilities.

Mark memory as read-only/no-execute



This feature segments kernel memory into logical sections and sets restrictive
page access permissions on each section. Code is marked as read only + execute.
Data sections are marked as no-execute and further segmented into read-only and
read-write sections. This feature is enabled with config option
CONFIG_DEBUG_RODATA. It was put together by Kees Cook and is based on a subset
of Grsecurity’s KERNEXEC feature by Brad
Spengler and Qualcomm’s CONFIG_STRICT_MEMORY_RWX feature by Larry Bassel and
Laura Abbott. CONFIG_DEBUG_RODATA landed in the upstream kernel for arm/arm64
and has been backported to Android’s 3.18+ arm/href="https://android-review.googlesource.com/#/c/174947/">arm64 common
kernel.

Restrict kernel access to userspace



This feature improves protection of the kernel by preventing it from directly
accessing userspace memory. This can make a number of attacks more difficult
because attackers have significantly less control over kernel memory
that is executable, particularly with CONFIG_DEBUG_RODATA enabled. Similar
features were already in existence, the earliest being Grsecurity’s UDEREF. This
feature is enabled with config option CONFIG_CPU_SW_DOMAIN_PAN and was
implemented by Russell King for ARMv7 and backported to href="https://android-review.googlesource.com/#/q/topic:sw_PAN">Android’s
4.1
kernel by Kees Cook.

Improve protection against stack buffer overflows



Much like its predecessor, stack-protector, stack-protector-strong protects
against stack
buffer overflows
, but additionally provides coverage for href="https://outflux.net/blog/archives/2014/01/27/fstack-protector-strong/">more
array types
, as the original only protected character arrays.
Stack-protector-strong was implemented by Han Shen and href="https://gcc.gnu.org/ml/gcc-patches/2012-06/msg00974.html">added to the gcc
4.9 compiler
.


Attack surface reduction



Attack surface reduction attempts to expose fewer entry points to the kernel
without breaking legitimate functionality. Reducing attack surface can include
removing code, removing access to entry points, or selectively exposing
features.

Remove default access to debug features



The kernel’s perf system provides infrastructure for performance measurement and
can be used for analyzing both the kernel and userspace applications. Perf is a
valuable tool for developers, but adds unnecessary attack surface for the vast
majority of Android users. In Android Nougat, access to perf will be blocked by
default. Developers may still access perf by enabling developer settings and
using adb to set a property: “adb shell setprop security.perf_harden 0”.


The patchset for blocking access to perf may be broken down into kernel and
userspace sections. The href="https://android-review.googlesource.com/#/c/234573/">kernel patch is
by Ben Hutchings and is
derived from Grsecurity’s CONFIG_GRKERNSEC_PERF_HARDEN by Brad Spengler. The
userspace changes were href="https://android-review.googlesource.com/#/q/topic:perf_harden">contributed
by Daniel Micay
. Thanks to href="https://conference.hitb.org/hitbsecconf2016ams/sessions/perf-from-profiling-to-kernel-exploiting/">Wish
Wu
and others for responsibly disclosing security vulnerabilities in perf.

Restrict app access to ioctl commands



Much of Android security model is described and enforced by SELinux. The ioctl()
syscall represented a major gap in the granularity of enforcement via SELinux.
Ioctl command
whitelisting with SELinux
was added as a means to provide per-command
control over the ioctl syscall by SELinux.


Most of the kernel vulnerabilities reported on Android occur in drivers and are
reached using the ioctl syscall, for example href="https://source.android.com/security/bulletin/2016-03-01.html#elevation_of_privilege_vulnerability_in_mediatek_wi-fi_kernel_driver">CVE-2016-0820.
Some ioctl commands are needed by third-party applications, however most are not
and access can be restricted without breaking legitimate functionality. In
Android Nougat, only a small whitelist of socket ioctl commands are available to
applications. For select devices, applications’ access to GPU ioctls has been
similarly restricted.

Require seccomp-bpf



Seccomp provides an additional sandboxing mechanism allowing a process to
restrict the syscalls and syscall arguments available using a configurable
filter. Restricting the availability of syscalls can dramatically cut down on
the exposed attack surface of the kernel. Since seccomp was first introduced on
Nexus devices in Lollipop, its availability across the Android ecosystem has
steadily improved. With Android Nougat, seccomp support is a requirement for all
devices. On Android Nougat we are using seccomp on the mediaextractor and
mediacodec processes as part of the href="http://android-developers.blogspot.com/2016/05/hardening-media-stack.html">media
hardening effort
.

Ongoing efforts



There are other projects underway aimed at protecting the kernel:


Due to these efforts and others, we expect the security of the kernel to
continue improving. As always, we appreciate feedback on our work and welcome
suggestions for how we can improve Android. Contact us at href="mailto:security@android.com">security@android.com.