Tuesday, November 12, 2013

assets folder in Android Studio

Android Studio is a new Android development environment based on IntelliJ IDEA, Gradle-based build support. It have different project structure.

In Eclipse, assets is in /assets folder under your project. In Android Studio, it is in /src/main/assets. In both Eclipse and Android Studio, /assets have the same level of /res folder.

Compare with the exercise of "Embed html using Google Maps JavaScript API v3 in Android App", where /assets/simplemap.html is a asset file of HTML. In Android Studio, it in /src/main/assets/simplemap.html. In both case, it can be accessed with "file:///android_asset/simplemap.html".

assets folder in Android Studio


reference: Gradle Plugin User Guide > Project Structure

3 comments:

John Yu said...

Thank you for the post!! It helped me compare between ADT and Android Studio.
I think there's a typo in your post, you mention in Android Studio the assets folder should be at "/src/main/assets" in the second paragraph and in the image. But in your third paragraph you wrote "/res/main/assets/simplemap.html".

Erik said...

hello John Yu,

Thanks for remind.

netdragon said...

Note to everyone, you have to use AssetManager with this approach. If you're trying to use asset URIs to later replace with http:// in ImageView.setImageUri, that approach will not work (note: You should download images in a background thread, rather than using ImageView.setImageUri unless performance is not a concern). Otherwise, for Android 2.2 ImageView supports URIs but they have to be in android.resource form. So for images, you have to put them in the res/raw folder if you aren't going to use AssetManager directly and then the URL android.resource://[package name]/" + R.raw.id ... From http://androidbook.blogspot.com/2009/08/referring-to-android-resources-using.html :
"android.resource://[package]/[res type]/[res name]"

Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/raw/myvideo");