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?
转载于:https://stackoverflow.com/questions/18302603/where-do-i-place-the-assets-folder-in-android-studio
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, 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.
Looking inside the .iml file of your project you will see the following line:
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
This means the "assets" folder is already declared for Gradle. You will need to create it under src/main/
(I'm using Android Studio 0.4.2).
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'
}
}
}
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.
Let Android Studio do it for you.
Assets Folder
.Finish
.And voila! It will create the assets
folder in the main
target source set.
If you tried all your bullets in this thread in vain try cleaning your project . In my case it only worked after Projet
-> clean
Simple follow this
File > New > folder > assets Folder
Note : App must be selected before creating folder.
Select the app
folder and then:
File
> New
> folder
> assets Folder
,
the default location is inside /main
folder
need configure parameter for gradle
i hope is will work
// file: build.gradle
sourceSets {
main {
assets.srcDirs = ['src/main/res/icon/', 'src/main/assets/']
}
}
In Android Studio, click on the app
folder, then the src
folder, and then the main
folder. Inside the main folder you can add the assets folder.
Click over main → new directory → directory name "assets"
right click on app folder->new->folder->Assets folder->set Target Source set->click on finish button
Put the assets folder in the main/src/assets
path.
Src/main/Assets
It might not show on your side bar if the app is selected. Click the drop-down at the top that says android and select packages. you will see it then.
Either create a directory under /app/src/main or use studio File-> New -> Folder - > Assets Folder.
Step 1 : Go to Files. Step 2 : Go to Folders. Step 3 : Create Assets Folder.
In Assets folder just put fonts and use it if needed.
Two ways 1. select app/main folder, Right click and select New => Folder => Asset Folder It will create 'assets' directory in main
Hi it very simple, first of all, assets folder will not create automatic with the project. we need to create it.
The location of Assets folder is:- App->src->assets
please have a look of two simple images:enter image description here
Note: for craeting assets folder just click on project right click select NEW then folder then Assets, it will create assets folder.