0

I know that official support for SVG didn't start until api level 23, but how do I use it in an app with the min sdk at 17?

I have had it working before, and I don't know what changed. I am using AndroidSVG library.

I get this error when I try to build a production APK

Error:(163) Error: Expected resource of type drawable [ResourceType]

Here is one of the 150 lines of code that I get this error in

socialTypeImage.setImageResource(R.raw.icon_other_blue);

I don't know what other info to provide, so if you need more, please let me know.

Thanks

I don't know if my problem is a duplicate, but if it is, none of those solutions work.

buildscript {
repositories {
    mavenCentral()
    jcenter()
    maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
    maven { url 'http://repository.codehaus.org' }
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0-alpha1'
    //classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.14.7'
    classpath 'com.google.code.ksoap2-android:ksoap2-android:3.1.1'
    classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2'
    classpath 'io.fabric.tools:gradle:1.+'
}
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
maven { url "https://repo.commonsware.com.s3.amazonaws.com" }
maven { url "http://repository.codehaus.org" }
maven { url 'https://maven.fabric.io/public' }
}

import groovyx.net.http.HTTPBuilder

def getBuildNumber(projectName) {
    def http = new HTTPBuilder('http://eco-crossbar-620.appspot.com')
try {
    def resp = http.get(path: "/${projectName}")
    println "NEW BUILD NUMBER: ${resp.BODY}"
    resp.BODY
} catch (ignored) {
    println "ERROR RETRIEVING BUILD NUMBER"
    0
}
}

def getWorkingBranch() {
def workingBranch = "build"
try {
    workingBranch = """git --git-dir=${rootDir}/.git
                           --work-tree=${rootDir}/
                           rev-parse --abbrev-ref HEAD""".execute().text.trim()
} catch (ignored) {
    // git unavailable or incorrectly configured
}
println "Working branch: " + workingBranch
return workingBranch.replaceAll("/", "-")
}

android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion '23.0.2'

def build = getBuildNumber("lookcounter-android")

defaultConfig {
    applicationId "com.lookcounter"
    minSdkVersion 17
    targetSdkVersion 23
    versionCode 67
    versionName "0.1.$versionCode"
    vectorDrawables.useSupportLibrary = true
    buildConfigField "String", "DEFAULT_USERNAME", "\"\""
    buildConfigField "String", "DEFAULT_PASSWORD", "\"\""
    resValue "string", "base64_encoded_public_key", "key"
}

buildTypes {
    release {
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        buildConfigField "String", "DEFAULT_USERNAME", "\"\""
        buildConfigField "String", "DEFAULT_PASSWORD", "\"\""
        debuggable false
        jniDebuggable false
        renderscriptDebuggable false
        pseudoLocalesEnabled false
    }
    debug {
        minifyEnabled false
        debuggable true
        jniDebuggable true
        renderscriptDebuggable true
        pseudoLocalesEnabled true
        zipAlignEnabled false
    }
}

signingConfigs {
    dev {
        storeFile file("../LookCounter.keystore")
        storePassword "izpa55word"
        keyAlias "lookcounterkey"
    }
    prod {
        storeFile file("../LookCounter.keystore")
        keyAlias "lookcounterprodkey"
    }
}

productFlavors {
    production {
        buildConfigField "boolean", "DEV_BUILD", "false"
        resValue "string", "app_name", "Lookcounter"
        signingConfig signingConfigs.prod
        versionCode 2
        minSdkVersion 17
        targetSdkVersion 23
    }
    dev {
        buildConfigField "boolean", "DEV_BUILD", "true"
        resValue "string", "app_name", "(DEV) Lookcounter"
        signingConfig signingConfigs.dev            
        applicationId 'com.lookcounter'
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}

android.applicationVariants.all { variant ->
    if (variant.buildType.name.equals("release")) {
        variant.assemble.doLast {
            def apkName
            def dirName = System.getProperty("user.home") + "/Desktop/lookcounter/apk"
            if (variant.name.contains("production")) {
                dirName += "PlayStore"
                apkName = "Lookcounter_v${versionCode}_PlayStore_${versionName}.apk"
            } else {
                dirName += "dev"
                def branchName = getWorkingBranch()
                if (branchName.equals("develop")) {
                    apkName = "Lookcounter_v${versionCode}_DEV_${build}.apk"
                } else {
                    apkName = "Lookcounter_v${versionCode}_DEV_${branchName}_${build}.apk"
                }
            }
            copy {
                def source = variant.outputs.get(0).getOutputFile()
                from source
                into dirName
                include source.name
                rename source.name, apkName
                println "Output APK copied to $dirName/$apkName"
            }
        }
    }
}
}

repositories {
maven {
    url "https://jitpack.io"
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//    compile "com.dev.sacot41:scviewpager:0.0.4"
compile project(':androidSVG')
compile files('../libraries/PriorityDeque-1.0.jar')
compile project(':cropper')
testCompile 'junit:junit:4.12'
// Possibly Keep
compile('com.doomonafireball.betterpickers:library:1.6.0') {
    exclude group: 'com.android.support', module: 'support-v4'
}
// KEEP
compile('com.nostra13.universalimageloader:universal-image-loader:1.9.5') {
    exclude group: 'com.android.support', module: 'support-v7'
}
compile('com.twitter.sdk.android:tweet-composer:0.7.3@aar') {
    transitive = true;
}
compile('com.crashlytics.sdk.android:answers:1.3.6@aar') {
    transitive = true;
}
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
    transitive = true;
}
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.jakewharton:butterknife:5.1.2'
compile 'org.apache.commons:commons-lang3:3.1'
compile 'com.github.clans:fab:1.6.2'
compile 'com.facebook.android:facebook-android-sdk:3.21.1'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.google.code.ksoap2-android:ksoap2-android:3.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:support-vector-drawable:23.2.0'
compile 'com.android.support:animated-vector-drawable:23.2.0'
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
linuxer
  • 523
  • 2
  • 4
  • 22
  • Possible duplicate of [VectorDrawable - is it available somehow for pre-Lollipop versions of Android?](http://stackoverflow.com/questions/26548354/vectordrawable-is-it-available-somehow-for-pre-lollipop-versions-of-android) – Doug Stevenson Mar 16 '16 at 05:04
  • Looks like it wants a drawable, and you are providing a `raw` resources. AndroidSVG allows you to parse and render SVGs to a canvas, but not to assign them to an ImageView, afaik. SVGAndroid gets you a bit closer. – 323go Mar 16 '16 at 05:05
  • @323go I understand that it is asking for a drawable, but to my understanding AndroidSVG and or api 23 allows the use of svgs and gradle creates the appropriate pngs at build – linuxer Mar 16 '16 at 05:21
  • `official support for SVG didn't start until api level 23` It **never** started, for real. `VectorDrawables` are **not** `SVG`s. They use a reduced **subset** of the `SVG` definition. – Phantômaxx Mar 16 '16 at 08:04
  • Is there anything weird in your proguard file? Otherwise perhaps try changing one thing at a time in your release build to match the debug one and see if it starts working. – Paul LeBeau Mar 16 '16 at 14:49
  • @PaulLeBeau I commented out the proguard and I still have the problem. I also went through and changed things like by line. Nothing worked – linuxer Mar 16 '16 at 16:10

1 Answers1

1

You can't use SVGs directly as a Resource. The Android resource loading system doesn't know what an SVG is. What you need to use is something like:

SVG svg = SVG.getFromResource(R.raw.icon_other_blue);
socialTypeImage.setImageDrawable(new PictureDrawable(svg.toPictureDrawable()));

Or you can use the SVGImageView widget class that is provided. Documentation here.

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
  • I am actually using an SvgImageView. Sorry, I inherited this code, and I am not an android guru by any means. Can you explain to me how I can do a debug build and it works just fine, no issues, but once I try a release build then it has issues? – linuxer Mar 16 '16 at 12:38
  • Ok then. I was confused by your error because that is not one I'd expect to get when using AndroidSVG. What are the difference in your debug and release buiids. Can you post your build.gradle file to the question? – Paul LeBeau Mar 16 '16 at 13:05
  • Ok, I added the build.gradle I removed some of the sensitive info, but nothing that effects the build. – linuxer Mar 16 '16 at 13:30