Vector drawable, error and backward compatibility

2018. 9. 12. 19:31·Android Development
반응형

벡터 이미지를 적용해 스크린 해상도나 크기와 상관없이 단일 리소스로만 처리할 수 있게 개발 하는 중 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:
  • Added AppCompatDelegate.setCompatVectorFromResourcesEnabled() method to re-enable usage of vector drawables in DrawableContainer objects on devices running Android 4.4 (API level 19) and lower. See AppCompat v23.2 — Age of the vectors for more information.

다시 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



저작자표시 비영리 변경금지 (새창열림)

'Android Development' 카테고리의 다른 글

Flutter init  (0) 2019.01.30
Android java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 3(offset:3).state:4 android.support.v7.widget.RecyclerView  (0) 2018.11.01
Jsoup & encoding & charset & html  (0) 2018.01.11
페이스북 앱 링크 연결 (link to Facebook app if installed in device)  (0) 2018.01.05
Span 처리  (0) 2017.10.19
'Android Development' 카테고리의 다른 글
  • Flutter init
  • Android java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 3(offset:3).state:4 android.support.v7.widget.RecyclerView
  • Jsoup & encoding & charset & html
  • 페이스북 앱 링크 연결 (link to Facebook app if installed in device)
fogthegreat
fogthegreat
아주 오랫동안 이것 저것 개발하면서 배우고 찾아 본 것들을 적거나 모았습니다. 불편한 점이 있다면 알려주세요. (과거에 불펌한 글들을 모두 제거하고 있는 중이에요. 🙏)
  • fogthegreat
    꿈소년의 개발 이야기
    fogthegreat
  • 전체
    오늘
    어제
    • 전체보기 (242)
      • Software Engineering (56)
      • Android Development (78)
      • 일상다반사 (63)
      • 책에 대한 거의 모든 것 (11)
      • 영어공부 (1)
      • ETC (0)
      • 챌린지 (1)
      • Do it 스터디! (32)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 향로
    • 청하가 제안하는 소프트웨어 엔지니어로써 재미있게 사는 …
    • WhoRU? Story...♡
    • Snapshot
    • 두잇! - 이지스퍼블리싱
    • 제이펍의 참 똑똑한 2비트 책 이야기
    • Inpa Dev
  • 공지사항

  • 인기 글

  • 태그

    하버드
    kotlin
    자바
    JavaScript
    코틀린
    안철수
    Android 4.1
    css
    google
    보안
    hcj
    OOM
    build.gradle
    C++
    linux
    html
    안드로이드
    Android
    Eclipse
    ActiveX
    탐지기법
    노개북
    git
    리눅스
    개발
    js
    안드로이드 개발
    gradle
    구글
    java
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
fogthegreat
Vector drawable, error and backward compatibility
상단으로

티스토리툴바