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

后端 未结 22 3267
醉酒成梦
醉酒成梦 2020-11-22 01:59

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.

相关标签:
22条回答
  • 2020-11-22 02:19

    When upgrading to the release version of Android Studio, you may be automatically switched to the new Android project View (see here for more info). If you swap back to either the Project or Packages view, you should see the standard folder hierarchy of a Gradle-based project. Then refer to CommonsWare's answer for the appropriate location.

    0 讨论(0)
  • 2020-11-22 02:20

    If you tried all your bullets in this thread in vain try cleaning your project . In my case it only worked after Projet -> clean

    0 讨论(0)
  • 2020-11-22 02:21

    Since Android Studio uses the new Gradle-based build system, you should be 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 type, 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 internal storage, external storage, or the Storage Access Framework for read/write content.

    0 讨论(0)
  • 2020-11-22 02:21

    Click over main → new -> directory → and type as name "assets"

    or... main -> new -> folder -> assets folder (see image)

    0 讨论(0)
  • 2020-11-22 02:22

    Either create a directory under /app/src/main or use studio File-> New -> Folder - > Assets Folder.

    0 讨论(0)
  • 2020-11-22 02:24

    In android studio you can specify where the source, res, assets folders are located. for each module/app in the build.gradle file you can add something like:

    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.1"
    
        sourceSets {
            main {
                java.srcDirs = ['src']
                assets.srcDirs = ['assets']
                res.srcDirs = ['res']
                manifest.srcFile 'AndroidManifest.xml'
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题