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?
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.
Let Android Studio do it for you.
In Android Studio (1.0 & above), right-click on the folder and navigate to the Assets Folder.
On the next screen just click Finish.
And voila! It will create the assets folder in the main target source set.
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).
Select the app folder and then:
File > New > folder > assets Folder ,
the default location is inside /main folder
First of all the "Assets" folder will not be created automatically with the project. We have to create it.
The location of Assets folder is: App > src > Assets
Please have a look of the simple image below.
Note: For creating assets folder just click on Project => Right click => Select New => Folder => Assets. It will create Assets folder.
It's simple, follow these steps
File > New > Folder > Assets Folder
Note : App must be selected before creating folder.
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'
}
}
}
Simply, double shift then type Assets Folder
choose it to be created in the correct place
Click over main → new -> directory → and type as name "assets"
or... main -> new -> folder -> assets folder (see image)
In Android Studio 4.1.1
Right Click on your module (app for example) -> New -> Folder -> Assets Folder
File > New > folder > assets Folder
Project -> app -> src -> main -> RMB(right mouse button) -> New -> Directory:
Two ways:
Select app/main folder, Right click and select New => Folder => Asset Folder.
It will create 'assets' directory in main.
Select main folder, Right click and select New => Directory
Enter name as 'assets' = > Ok.
If you tried all your bullets in this thread in vain try cleaning your project . In my case it only worked after Projet -> clean
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.
need configure parameter for gradle
i hope is will work
// file: build.gradle
sourceSets {
main {
assets.srcDirs = ['src/main/res/icon/', 'src/main/assets/']
}
}
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.
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.
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.
follow these steps
1)file->New->Folder
there are multiple options like
aidl folder
assets folder
jni folder
2) choose options assets folder
3) then there is option to change path of assets folder if you
want to change then check otherwise left that checkbox of cahnge folder location
4) click on finish
Either create a directory under /app/src/main or use studio File-> New -> Folder - > Assets Folder.
In Android Studio right-click Folder in app->src->main then create new DIRECTORY name that assets.
It seems that nobody mentioned this:
You can define it in Project Structure > Project Settings:
I'm new to Android development, and I'm trying to manage projects from the command line using the SDK since I cannot get Android Studio 1.2 to work properly in my system (it's unresponsive).
The problem: I created a new project but the asset folder is missing.
Other SO answers (enter link description here) solve this by creating the folder from the IDE, or by pointing to the asset folder in the .iml file, with doesn't work in my case (I trying to mange the projects from the command line entirely)
There's also a solution editing build.gradle, but the project created from command line (using the SDK) doesn't seem to be a gradle project.
Any help would be appreciated.
Just create a directory called "assets" at the root of your project, i.e. in the same directory your AndroidManifest.xml lives. There's no need to "link that folder from the project". At least that's the case on my system, where I'm using Android SDK 24.4.1 (and I'm not using Gradle -- just emacs and ant).
Once I had assets/fonts/aisauc.ttf in there, the following code...
import android.graphics.Typeface;
...
Typeface greek =
Typeface.createFromAsset(getAssets(), "fonts/aisauc.ttf");
mytextfield.setTypeface(greek);
gave me a TextField with characters from the font I wanted.
How do I create the assets folder manually?
You make it the same you make any directory on your filesystem. Whether you use mkdir or a command-line equivalent, or whether you use your desktop OS's file manager, is up to you.
The default location for an assets/ directory is in a sourceset (e.g., src/main/assets/, to go along with src/main/AndroidManifest.xml and src/main/res/ and src/main/java/, where src/main/ is a sourceset). You can have an assets/ directory located elsewhere, if you choose, but then you will need to configure your build.gradle file to teach Gradle the alternative assets/ location for whatever sourceset you are trying to apply it to.
In your left most sidebar or the sidebar that shows the app, manifests, java... etc, right click app > New > Folder (has the green android symbol next to it) > Assets Folder.
On the next screen leave the path as 'main' and click 'Finish'. Then you can drop whatever asset you want into the folder.
Android Studio has changed its project structure yet again... now it is
project
└── app-module
├── manifests
├── res
└── java
I've been looking everywhere online, but I can't find where to put the assets folder. When I try to create the folder via the directory viewer in Android Studio (right-click, New... directory) the "directory" option is not available. The only available options are:
Java Class
File
Module
Package
Image Asset
None of which will do what I want here.
Has anyone figured this out?
An image of how to in Android Studio 1.5.1.
Within the "Android" project (see the drop-down in the topleft of my image), Right-click on the app...
You can click on the Project window, press Alt-Insert, and select Folder->Assets Folder. Android Studio will add it automatically to the correct location.
You are most likely looking at your Project with the new(ish) "Android View". Note that this is a view and not the actual folder structure on disk (which hasn't changed since the introduction of Gradle as the new build tool). You can switch to the old "Project View" by clicking on the word "Android" at the top of the Project window and selecting "Project".
According to new Gradle based build system. We have to put assets under main folder.
Or simply right click on your project and create it like
File > New > folder > assets Folder
To specify any additional asset folder I've used this with my Gradle. This adds moreAssets, a folder in the project root, to the assets.
android {
sourceSets {
main.assets.srcDirs += '../moreAssets'
}
}
right click on app-->select
New-->Select Folder-->then click on Assets Folder
Is there a script or something that creates a new Android project in Terminal IDE on Android? How does the R file get updated with new resources?
This might help : http://developer.android.com/tools/projects/projects-cmdline.html
It will create a project that can be used...with ant.
Maven has an archetype system that can create a new Android project : https://github.com/akquinet/android-archetypes
There doesn't seem to be any gradle equivalent (yet).
You need to create your project's home folder and then create the
./src
./dist
./res
./build
./build/classes
directories and add an "AndroidManifest.xml" file manually.
It works. Copy the "builder.sh" script in the project's home folder and make the proper changes like cd into your project's home folder, set your project's package name and select the main activity class.
As per your question about the R.java file, the aapt tool from Android SDK detects the changes in resources and writes R.java file and packs resources accordingly.
I'm working on an Android project and i need to import an XML library called XOM. The only way i found was to right click on the project name -> Properties -> Libraries tab -> click on "Add external Jar". But that only references it from it's original path, what happens when i compile the app and move it to my phone? Will the Jar be in there?
Might be a stupid question, sorry if that's the case.
It's fine to do that but what I normally do is create a folder called liband then add Jars from there. I find that makes it easier to see what Jars I have in my application.
The main disadvantage of your original approach is that what if the path to that library externally accidentally changes? then your program will not compile. It's better to have everything in the one place to make things easier.
.apk is nothing but a collection or zipped version of a file. it contains all the resources and compiled java files.
So you need not have to worry about the inclusion of your library files. if you have set proper path to your libraries in eclipse then these will be included in your apk file.
Create a directory called "libs" in your under your root directory. You can do it by,
Right click on the project which is in the Package Explorer window in
Eclipse.
New -> Folder -> give "libs" as the Folder name
Copy your jar file and paste it to in the "libs" folder
Expand the "libs" folder
Right click on your copied jar file -> Build Path -> Add to build
path
That's it