Batch import SVGs as Drawables in AndroidStudio 3.6 (How?)
Asked Answered
B

3

21

I have quite a few (208 currently) SVG files that I programmatically turn into .imageset assets for my iOS app. I'd like to do the same for Android somehow.

I'm pretty pleased with the result I get by using New>>Vector Asset from the Studio menu. But I really don't want to do that 208 times. And more times in the future when the SVGs get updated.

Is there a way I can somehow script this import process?

I don't want to batch process them on some website somewhere. And I'd like to use the current studio tools if possible somehow. Or a completely independent command line tool.

Brook answered 28/2, 2020 at 23:32 Comment(0)
A
89

The Resource Manager tool that was added in Android Studio version 3.4 can bulk import SVGs and convert them into vector drawables.

  1. ToolsResource Manager
  2. Select the Drawable tab
  3. Click the + button in the top left corner
  4. Select Import Drawables

There you can select all the files you want to import at once. More details here.

Autogamy answered 22/5, 2020 at 17:34 Comment(2)
Definitely should be top answer! Integrated directly into Android Studio without using any third-party tool. Thank you!Marengo
The more I use Android Studio, the more I learn a lot of my old 3rd-party tools are now baked in.Mountford
T
2

You can download this jar file: Svg2VectorAndroid-1.0.1.jar

Just run this command:

java -jar C:\Users\Administrator\Downloads\Svg2VectorAndroid-1.0.1.jar C:\Users\Administrator\Desktop\your_svg_folder

Hope it will work for you.

Tinishatinker answered 29/2, 2020 at 5:27 Comment(4)
Is there any reason this isn't an open source project somehwere? Or maybe it is? It's working, but I'm not a big fan of random binaries from the internet...Brook
For any others that stumble on this, one thing I've found is that it's important that your drawable filenames end up as lower_case_under_score_names. AndroidStudio will complain about weird things if they are not in that format.Brook
I'm finding that while this converts some images, a lot of images are not converted correctly. Parts are left out. No error message is given that even tells that there were problems, visual inspection alone is the only way to detect the omissions. Some of these failed conversions import fine with the interactive New>>Vector Asset approach, so I think this library is not as good as the current one, even though it can do batch processing.Brook
@TravisGriggs it is an open source project, you just gotta truncate the URL to get to the github repo github.com/ravibhojwani86/Svg2VectorAndroidSilicon
S
-2

Add these to your gradle file

android {
defaultConfig {
    vectorDrawables.useSupportLibrary = true
}}
dependencies {
implementation 'com.android.support:appcompat-v7:23.2.0'}
Sectarianize answered 30/5, 2023 at 17:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.