꿈소년의 개발 이야기

Vector drawable, error and backward compatibility 본문

Android Development

Vector drawable, error and backward compatibility

꿈소년 2018. 9. 12. 19:31
반응형

벡터 이미지를 적용해 스크린 해상도나 크기와 상관없이 단일 리소스로만 처리할 수 있게 개발 하는 중 API 16 버전에서 문제가 생겼다. 벡터 이미지를 찾지 못해서 NullPointerException 이 발생하는 이슈가 생긴 것이다.


https://developer.android.com/guide/topics/graphics/vector-drawable-resources#vector-drawables-backward-solution

확인해봐도 딱히 빠진 게 없다.


도대체 뭐가 문제인지 모르던 차에 적용된 버전이었던 android support library 23.2 버전을 다시 훝어보았다.

보통 ASL 의 경우, 릴리즈 히스토리에 적힌 내용을 참고하면 좋은 결과가 있었던 적이 있었기에 다시 확인해보았다. 

역시나,,, 이후 버전 릴리즈 히스토리에서 아래와 같은 내용을 확인했다.


Revision 23.4.0

May 2016

Changes for v7 appcompat library:

다시 Age of the vectors 링크를 따라 들어갔다. 그리고 문제의 원인을 찾았다.


The ‘magic’ way

First up, this functionality was originally released in 23.2.0, but then we found some memory usage and Configuration updating issues so we it removed in 23.3.0. In 23.4.0 (technically a fix release) we’ve re-added the same functionality but behind a flag which you need to manually enable.

If you want re-enable this, just stick this at the top of your Activity:

static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

The rest of this post may then work.

AppCompat can intercept some drawable inflation from the framework. What this enables is you can use all of the standard attributes for a vector asset and everything may just work.

So let me tell you what may work:

DrawableContainers which reference other drawables resources which contain only a vector resource.

For example, a StateListDrawable which references other files which contain a vector.


결국, DrawableContainers 때문에 추가 옵션이 생겼고, 나는 그걸 놓치고 있었다.

이걸 Application class 에 추가함으로서 문제를 해결했다.




[References]

https://developer.android.com/guide/topics/graphics/vector-drawable-resources

https://medium.com/androiddevelopers/appcompat-v23-2-age-of-the-vectors-91cbafa87c88

https://developer.android.com/topic/libraries/support-library/rev-archive