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.
我对assets文件夹感到困惑。它不是在Android Studio中自动创建的,几乎所有讨论这个的论坛都在讨论Eclipse。
How can the Assets directory be configured in Android Studio?
如何在Android Studio中配置资产目录?
19 个解决方案
#1
1445
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/
).
由于Android Studio使用新的基于等级的构建系统,您应该将资产/放在源集中(例如,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:
在一个典型的Android Studio项目中,您将拥有一个应用程序/模块,其中包含一个主/源集(app/src/main/ off of the project root),因此您的主要资产将进入app/src/main/assets/ assets/。然而:
-
If you need assets specific to a build, such as
debug
versusrelease
, you can create sourcesets for those roles (e.g,.app/src/release/assets/
)如果您需要特定于构建的资产,例如debug和release,您可以为这些角色创建源代码集(例如,应用程序/ src /释放/资产/)
-
Your product flavors can also have sourcesets with assets (e.g.,
app/src/googleplay/assets/
)您的产品风味也可以有具有资产的源文件(例如,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 theInstrumentationRegistry
forgetContext()
, notgetTargetContext()
, to access those assets您的仪表测试可以使用自定义资产(例如,app/src/androidTest/assets/)的androidTest sourceset,但是一定要询问getContext()的工具注册表(),而不是getTargetContext()来访问这些资产。
Also, a quick reminder: assets are read-only at runtime. Use internal storage, external storage, or the Storage Access Framework for read/write content.
另外,一个简短的提醒:资产在运行时是只读的。为读/写内容使用内部存储、外部存储或存储访问框架。
#2
1286
Let Android Studio do it for you.
让Android Studio为你做吧。
- In Android Studio (1.0 & above), right-click on the folder and navigate to the
Assets Folder
. - 在Android Studio(1.0及以上版本)中,右键单击文件夹并导航到Assets文件夹。
- On the next screen just click
Finish
. - 在下一个屏幕上单击Finish。
And voila! It will create the assets
folder in the main
target source set.
瞧!它将在主目标源集中创建assets文件夹。
#3
114
Looking inside the .iml file of your project you will see the following line:
查看项目的.iml文件,您将看到以下一行:
<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).
这意味着“assets”文件夹已经声明为Gradle。您需要在src/main/下创建它(我使用的是Android Studio 0.4.2)。
#4
#5
30
Simple follow this
简单遵循这个
File > New > folder > assets Folder
>新>文件夹>资产文件夹。
Note : App must be selected before creating folder.
注意:创建文件夹前必须选择App。
#6
22
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 studio中,您可以指定源文件夹、资源文件夹、资源文件夹的位置。对于构建中的每个模块/应用程序。你可以添加如下文件:
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
sourceSets {
main {
java.srcDirs = ['src']
assets.srcDirs = ['assets']
res.srcDirs = ['res']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
#7
9
If you tried all your bullets in this thread in vain try cleaning your project . In my case it only worked after Projet
-> clean
如果你在这条线上试了所有的子弹都没用,试着清理你的项目。在我的例子中,它只在Projet ->清洗后才起作用
#8
9
right click on app folder->new->folder->Assets folder->set Target Source set->click on finish button
右键点击app文件夹->新建->文件夹->资产文件夹->设置目标源集->点击finish按钮
#10
6
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.
当升级到Android Studio的发布版本时,你可能会自动切换到新的Android项目视图(更多信息请看这里)。如果您切换回Project或Packages视图,您应该会看到基于级别的项目的标准文件夹层次结构。然后参照CommonsWare的答案找到合适的位置。
#11
6
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.
如果应用程序被选中,它可能不会显示在你的侧边栏上。单击顶部的下拉菜单,选择包。到时候你会看到的。
#12
6
Put the assets folder in the main/src/assets
path.
将assets文件夹放在main/src/assets路径中。
#13
5
need configure parameter for gradle
i hope is will work
需要配置参数的等级,我希望是将工作
// file: build.gradle
sourceSets {
main {
assets.srcDirs = ['src/main/res/icon/', 'src/main/assets/']
}
}
#14
3
Click over main → new directory → directory name "assets"
点击在主→新目录→目录名称“资产”
#15
2
Step 1 : Go to Files. Step 2 : Go to Folders. Step 3 : Create Assets Folder.
第一步:进入文件。步骤2:进入文件夹。步骤3:创建Assets文件夹。
In Assets folder just put fonts and use it if needed.
在“资产”文件夹中,只需要放置字体并在需要时使用。
#16
1
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.
在Android Studio中,单击app文件夹,然后单击src文件夹,然后单击主文件夹。在主文件夹中可以添加assets文件夹。
#17
1
Either create a directory under /app/src/main or use studio File-> New -> Folder - > Assets Folder.
要么在/app/src/main下创建一个目录,要么使用studio File-> New ->文件夹-> Assets文件夹。
#18
1
Two ways 1. select app/main folder, Right click and select New => Folder => Asset Folder It will create 'assets' directory in main
两种方法1。选择app/main文件夹,右键单击,选择New =>文件夹=> Asset文件夹,它将在主文件夹中创建“assets”目录
- Select main folder, Right click and select New => Directory Enter name as 'assets' = > ok
- 选择主文件夹,右键单击并选择New =>目录输入名称为'assets' => ok
#19
0
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
资产文件夹的位置为:- App->src->资产
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.
注意:对于craeting assets文件夹点击项目右键点击选择NEW then assets文件夹,它会创建assets文件夹。
#1
1445
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/
).
由于Android Studio使用新的基于等级的构建系统,您应该将资产/放在源集中(例如,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:
在一个典型的Android Studio项目中,您将拥有一个应用程序/模块,其中包含一个主/源集(app/src/main/ off of the project root),因此您的主要资产将进入app/src/main/assets/ assets/。然而:
-
If you need assets specific to a build, such as
debug
versusrelease
, you can create sourcesets for those roles (e.g,.app/src/release/assets/
)如果您需要特定于构建的资产,例如debug和release,您可以为这些角色创建源代码集(例如,应用程序/ src /释放/资产/)
-
Your product flavors can also have sourcesets with assets (e.g.,
app/src/googleplay/assets/
)您的产品风味也可以有具有资产的源文件(例如,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 theInstrumentationRegistry
forgetContext()
, notgetTargetContext()
, to access those assets您的仪表测试可以使用自定义资产(例如,app/src/androidTest/assets/)的androidTest sourceset,但是一定要询问getContext()的工具注册表(),而不是getTargetContext()来访问这些资产。
Also, a quick reminder: assets are read-only at runtime. Use internal storage, external storage, or the Storage Access Framework for read/write content.
另外,一个简短的提醒:资产在运行时是只读的。为读/写内容使用内部存储、外部存储或存储访问框架。
#2
1286
Let Android Studio do it for you.
让Android Studio为你做吧。
- In Android Studio (1.0 & above), right-click on the folder and navigate to the
Assets Folder
. - 在Android Studio(1.0及以上版本)中,右键单击文件夹并导航到Assets文件夹。
- On the next screen just click
Finish
. - 在下一个屏幕上单击Finish。
And voila! It will create the assets
folder in the main
target source set.
瞧!它将在主目标源集中创建assets文件夹。
#3
114
Looking inside the .iml file of your project you will see the following line:
查看项目的.iml文件,您将看到以下一行:
<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).
这意味着“assets”文件夹已经声明为Gradle。您需要在src/main/下创建它(我使用的是Android Studio 0.4.2)。
#4
72
Select the app
folder and then:
选择app文件夹,然后:
File
> New
> folder
> assets Folder
,
文件>新的>文件夹>资产文件夹,
the default location is inside /main
folder
默认位置在/main文件夹内
#5
30
Simple follow this
简单遵循这个
File > New > folder > assets Folder
>新>文件夹>资产文件夹。
Note : App must be selected before creating folder.
注意:创建文件夹前必须选择App。
#6
22
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 studio中,您可以指定源文件夹、资源文件夹、资源文件夹的位置。对于构建中的每个模块/应用程序。你可以添加如下文件:
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
sourceSets {
main {
java.srcDirs = ['src']
assets.srcDirs = ['assets']
res.srcDirs = ['res']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
#7
9
If you tried all your bullets in this thread in vain try cleaning your project . In my case it only worked after Projet
-> clean
如果你在这条线上试了所有的子弹都没用,试着清理你的项目。在我的例子中,它只在Projet ->清洗后才起作用
#8
9
right click on app folder->new->folder->Assets folder->set Target Source set->click on finish button
右键点击app文件夹->新建->文件夹->资产文件夹->设置目标源集->点击finish按钮
#9
#10
6
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.
当升级到Android Studio的发布版本时,你可能会自动切换到新的Android项目视图(更多信息请看这里)。如果您切换回Project或Packages视图,您应该会看到基于级别的项目的标准文件夹层次结构。然后参照CommonsWare的答案找到合适的位置。
#11
6
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.
如果应用程序被选中,它可能不会显示在你的侧边栏上。单击顶部的下拉菜单,选择包。到时候你会看到的。
#12
6
Put the assets folder in the main/src/assets
path.
将assets文件夹放在main/src/assets路径中。
#13
5
need configure parameter for gradle
i hope is will work
需要配置参数的等级,我希望是将工作
// file: build.gradle
sourceSets {
main {
assets.srcDirs = ['src/main/res/icon/', 'src/main/assets/']
}
}
#14
3
Click over main → new directory → directory name "assets"
点击在主→新目录→目录名称“资产”
#15
2
Step 1 : Go to Files. Step 2 : Go to Folders. Step 3 : Create Assets Folder.
第一步:进入文件。步骤2:进入文件夹。步骤3:创建Assets文件夹。
In Assets folder just put fonts and use it if needed.
在“资产”文件夹中,只需要放置字体并在需要时使用。
#16
1
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.
在Android Studio中,单击app文件夹,然后单击src文件夹,然后单击主文件夹。在主文件夹中可以添加assets文件夹。
#17
1
Either create a directory under /app/src/main or use studio File-> New -> Folder - > Assets Folder.
要么在/app/src/main下创建一个目录,要么使用studio File-> New ->文件夹-> Assets文件夹。
#18
1
Two ways 1. select app/main folder, Right click and select New => Folder => Asset Folder It will create 'assets' directory in main
两种方法1。选择app/main文件夹,右键单击,选择New =>文件夹=> Asset文件夹,它将在主文件夹中创建“assets”目录
- Select main folder, Right click and select New => Directory Enter name as 'assets' = > ok
- 选择主文件夹,右键单击并选择New =>目录输入名称为'assets' => ok
#19
0
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
资产文件夹的位置为:- App->src->资产
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.
注意:对于craeting assets文件夹点击项目右键点击选择NEW then assets文件夹,它会创建assets文件夹。