Monday 27 November 2017

Where to place the 'assets' folder in Android Studio?

itemprop="text">

I am confused about the
assets folder. It doesn't come auto-created in Android Studio,
and almost all the forums in which this is discussed talk about
Eclipse.




How can the Assets directory
be configured in Android Studio?


class="post-text" itemprop="text">
class="normal">Answer



Since
Android Studio uses href="http://tools.android.com/tech-docs/new-build-system/user-guide">the new
Gradle-based build system, you should be href="http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Project-Structure">putting
assets/ inside of the source sets (e.g.,
src/main/assets/).



In a
typical Android Studio project, you will have an app/ module,
with a main/ sourceset (app/src/main/
off of the project root), and so your primary assets would go in
app/src/main/assets/.
However:




  • If you
    need assets specific to a build, such as debug versus
    release, you can create sourcesets for those roles (e.g,.
    app/src/release/assets/)


  • Your
    product flavors can also have sourcesets with assets (e.g.,
    app/src/googleplay/assets/)


  • Your
    instrumentation tests can have an androidTest sourceset with
    custom assets (e.g., app/src/androidTest/assets/), though be
    sure to ask the InstrumentationRegistry for
    getContext(), not getTargetContext(),
    to access those
    assets





Also,
a quick reminder: assets are read-only at runtime. Use href="https://commonsware.com/blog/2014/04/07/storage-situation-internal-storage.html">internal
storage, href="https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html">external
storage, or href="http://developer.android.com/guide/topics/providers/document-provider.html">the
Storage Access Framework for read/write content.



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...