Having issue on Real Device using vector image in android. SVG-android

I use svg-android.jar from https://github.com/pents90/svg-android at its work fine but only on emulator devices in eclipse. Agrrrr. On real devices it just empty imageView on screen. here is my code:

SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.test);
Drawable drawable = svg.createPictureDrawable();
imgView.setImageDrawable(drawable);

any suggestion?


Solution 1:

On newer devices that have hardware rendering turned on by default, you need to explicitly turn on software rendering.

imgView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

I suspect this is probably your problem.

Solution 2:

Use AppCompatImageView instead ImageView in xml like the below code

<android.support.v7.widget.AppCompatImageView
    android:tint="#d74313"
    app:srcCompat="@drawable/circle_icon"
    android:layout_width="30sp"
    android:layout_height="30sp" />

and in your build.gradle

android {
  defaultConfig {
    vectorDrawables {
      useSupportLibrary = true
    }
  }
}

If the above doesn't work, try this also in your application class

public class App extends Application {

  @Override public void onCreate() {
    super.onCreate();
    // Make sure we use vector drawables
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
  }
}