Related
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 trying to add an Assets folder to my Android Project in Android Studio 2.1.2. I right click on the project and choose New -> Folder -> Assets Folder. In the project pane on the left, it doesn't show up when Android is selected. If I switch to Project Files, it does appear, however it looks like a normal directory, rather than looking like a resource directory. I then tried adding files to it (jpgs), both through Android Studio and through the file explorer (all file names are lowercase with no special characters). If you unzip the apk that gets created though, it doesn't contain an Assets directory or the added files. Also sometimes the assets directory will disappear from the project files pane, although it's still in explorer.
What step am I missing to get to the Assets directory properly added to my project?
Note: this is for a LibGdx project that expects image files to be there.
Finally got it. Appears to be a bug in Android Studio, but to make it work, in the Project pane, go to Android view and (this next part is critical) right click on the res folder and go to New->Folder->Assets folder. You might want to click change folder location to be sure it's going into the main folder (mine was) just to be on the safe side.
You must right click on the res folder. That was my issue. If you right click on the module or anywhere else, even though the folder will get created in the proper spot, Android Studio and gradle won't treat it as a resource directory and just ignores it.
Be sure to create folder in app/src/main/ and call it assets.
For me in Android Studio 3.6.2, the assets folder wasn't showing up in the "Android" view, no matter where I tried to create it, after trying the other suggestions here. In the "Project" view it showed up in app/assets as a plain folder. I then drag-and-dropped it to src/main/assets and it automatically changed its icon to the same icon as the res folder, and after this it is now also showing up in the "Android" view, so I guess Android Studio is picking it up correctly now, and it appears to be a bug in Android Studio.
If you created a folder in your res directory and named it "assets" and now as "Nullqwerty" mentioned you could not able to solve your problem and you face to the duplication error, just go to the project tab (or press Alt + 1) and in the view mode, change it from "Android" to "Project", then expand all folders in your project to find assets folder in your src\main\res directory (or in src\main path) and right-click on your "assets" folder (if you created it before by adding a "Directory" and named it assets), then change your view mode from "Project" to "Android", again, and right-click on "res" directory->New->Folder->Assets Folder. Then click on "Finish" button to see the assets folder on your main directory as you want. That's it ;)
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.
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:
New version of ADT r17 plugin for Eclipse added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration now. Unfortunately Android Dependencies classpath container is non modifiable.
How can i attach javadoc and sources to the automatically inserted .jar (from /libs folder)?
The best way to answer your question is to summarize the answers from Xavier, plastiv, VinceFR and Christopher.
Step by step guide
In order to link the sources and javadoc to a .jar library that is automatically linked by Eclipse you have to do the following:
Place the library .jar file in the libs folder, and the associated source .jar and doc .jar files in separate subfolders such as libs/src and libs/docs. You can use a name other than src and docs if you want, but it's important that the .jar files aren't directly in the libs folder.
Create a .properties file in the libs folder with the exact name of the actual library .jar (see example). Make sure you keep the .jar part.
Specify the relative paths to the sources and javadoc .jar in the .properties file.
Close and re-open the Eclipse project! Optionally, refresh the project by pressing F5.
Select an object of the linked library in the source code.
Open the Javadoc view in Eclipse to check the documentation (see screenshot).
Open the source code declaration (default shortcut: F3) of the selected object.
Example
The example uses the Gson library.
Directory structure of the libs folder:
libs
├── docs
│ └── gson-2.2.2-javadoc.jar
├── gson-2.2.2.jar
├── gson-2.2.2.jar.properties
└── src
└── gson-2.2.2-sources.jar
Contents of gson-2.2.2.jar.properties
src=src/gson-2.2.2-sources.jar
doc=docs/gson-2.2.2-javadoc.jar
Additional information
You can of course move the javadoc and sources .jar into other folders and specify relative paths. That's up to you. Placing the source and javadoc jars directly into the lib folder is possible but not recommended, as that causes documentation and source code to be included in your application.
Screenshot of the Eclipse JavaDoc panel:
Screenshot of an Eclipse project using Gson with Android 4.2.2.:
Referencing unpacked javadocs
In case you want to reference javadocs which are not provided as a packed .jar but simply as files and folders as asked by android developer in the comments do the following:
Place the library .jar in the libs/ folder
Create a yourlibraryname.jar.properties file (don't forget the .jar) with the following content:
doc=docs
Add the javadocs folders to the libs/ folder.
You should come up with the following folder structure:
├── docs
│ ├── allclasses-frame.html
│ ├── allclasses-noframe.html
│ ├── com
│ │ └── google
│ │ └── ads
│ │ ├── Ad.html
│ │ │ ....
│ │ └── package-tree.html
│ │ ...
│ └── stylesheet.css
├── GoogleAdMobAdsSdk-6.4.1.jar
└── GoogleAdMobAdsSdk-6.4.1.jar.properties
Do not forget to close and re-open the Eclipse project as mentioned above!
Here is a screenshot of a working example project referencing the GoogleAdMobAds Android library.
On windows you have to escape the backslash for references to doc and src paths in the properties file. Example, for
android-support-v4.jar the properties file content is something like:
doc=C:\\Program Files (x86)\\Android\\android-sdk\\extras\\android\\support\\v4\\docs
src=C:\\Program Files (x86)\\Android\\android-sdk\\extras\\android\\support\\v4\\src
An answer come from http://code.google.com/p/android/issues/detail?id=27490#c21
In your libs folder, you must have:
doc(folder)
foo_doc(folder)
index.html
...
...
foo.jar
foo.jar.properties
And in your foo.jar.properties, just put doc=./doc/foo_doc
Maybe you will have to refresh your project, to clean it, to close it and to reopen it.
It works for me!
I tried all of the above and none of them worked for me. I figured out a method that will always work. Basically, the culprit is the way that the ADT treats the "libs" folder so I quit using the "libs" folder. Instead I created a "libraries" folder and used it.
You can do the following and it will always work - even if the ADT should change how it changes how it deals with the "libs" folder in the future:
Create a "libraries" folder.
Create a sub-folder under it for each library.
Put all of the files for each library in the appropriate folder (java jar file, source jar file, javadoc jar file, etc).
Add the java jar file for each project in the "Libraries" tab for the Java Build Path by clicking on the Add Jars... button to add the jar from the library sub-folder in the "libraries" folder.
Attach the source/javadocs to each project by opening the project in the "Libraries" tab, selecting the desired item, and clicking on the Edit... button to add the source/javadocs from the library sub-folder in the "libraries" folder.
Check the checkbox for each project in the "Order and Export" tab for the Java Build Path.
After verifying that all libraries have been moved delete the "libs" folder.
By following the above procedure your project will have folders that look like this:
Your Java Build Path will look something like this:
In Order and Export the libraries are ticked:
For now, move the library you want Javadoc to lib. Them add that library to the Build Path and add the Javadoc.
Check this comment in the android issues.
On ADT 22 I could not access Javadoc for both commons-io-2.4.jar and android-support-v4.jar
This is the way I fixed it:
Precondition: both libraries are listed under "Referenced Libraries".
Right click on commons-io-2.4.jar and select Properties. This window appears:
commons-io-2.4.jar is bundled with commons-io-2.4-javadoc.jar, so I specified the Javadoc in archive External file path.
I did the same thing for the support library: right click on android-support-v4.jar and select Properties. This screen appears:
This time I specied the path to the source directory.
The library reference to commons-io-2.0.1.jar was broken when I upgraded to SDK Tools and ADT revision 17.
To resolve the problem I used Project -> Properties - > Java Build Path and I selected the Libraries tab. I deleted any reference to commons-io-2.0.1.jar and then used Add Jar to re-add commons-io-2.0.1.jar to the project. Then I click the ‘>’ arrow next to the library name to expand the library reference and I used the edit buttons to set the Source attachment and the Javadoc location.
Sorry I can't post an image as I don't have enough rep (please...).
Seems to be a moving target but, after having collected bits and pieces from many places (including answers to this very question that helped but failed to describe all necessary details, or maybe the system had changed slightly in the meantime), this seems to be the solution, at least as of now (August 28, 2013).
Open up a folder for your javadocs somewhere not inside your project.
Put your javadocs there unzipped, each into its own folder.
Inside your lib folder, add an xxx.jar.properties file for each lib you want to associate a javadoc with.
In that properties file, refer to the folder you unzipped the appropriate javadoc into (on Windows, escape the backslashes):
doc=d:\\Android\\javadoc\\libGoogleAnalyticsServices
Close and reopen your project in Eclipse (refreshing is not enough). You should now see the tooltips when you hover over the appropriate classes.
Failing to observe any of these steps (not unzipping the javadoc, referencing a file instead of a folder, etc) seems to break it.
I know this question is rather old, but when I was facing the same problem yesterday and the solution posted above was way too annoying for me, I found out that one can easily add a source path definition to the .classpath file of the project. Eclipse will then adapt it and you're able to browse through the source.
classpath entry before:
<classpathentry kind="lib" path="[PATH_TO_MY_JAR]"/>
After adding the path to the source
<classpathentry kind="lib" path="[PATH_TO_MY_JAR]" sourcepath="[PATH_TO_MY_SOURCE_JAR]"/>
Hope this helps
just update the ADT plugin. That worked for me!!
Start Eclipse, then select Help > Install New Software.
Click Add, in the top-right corner.
In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location:
https://dl-ssl.google.com/android/eclipse/
Note: The Android Developer Tools update site requires a secure connection. Make sure the update site URL you enter starts with HTTPS.
Click OK.
In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
In the next window, you'll see a list of the tools to be downloaded. Click Next.
Read and accept the license agreements, then click Finish.
If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.
When the installation completes, restart Eclipse
Hope that helps!
For any given jar, if you would like to see the Javadoc help on the tooltip while coding, do the following:
Right click your project > Properties > Java Build Path > Libraries Tab. Click the arrow next to your jar to expand.
Source attachment should point to the location of the actual jar (probably right in your java folder).
Javadoc location: You have two choices here: URL and archive. If your javadocs for this jar are in the form of a folder containing an index.html file at the first level, choose 'Javadoc URL' and point to that folder.
If your javadocs are in a jar, choose 'Javadoc in archive' and point to the jar.
Don't forget to restart your workspace/close and reopen your project to update the tooltip with the Javadoc info.
I hope this helps give a simple answer for what I believe should be a very simple task.
My solution:
Download an eclipse plugin called: "Java Source Attacher Feature".
Later, select a jar and attach the source code using this plugin. Click in the jar file to select it, right buttom on the mouse, and then select "attach java source".
When you have the source code you have automatically the javadoc.
Now you can use F2 over the classes to view the asociated javadoc.
Enjoy