답변:
에 안드로이드 스튜디오 :
메뉴 -> 분석 -> 이름으로 검사 실행 -> 사용하지 않은 자원
확인 파일 마스크 (들) 체크 박스를 넣어 strings.xml텍스트 필드에.
tools:ignore="UnusedResources"
상당히 쉬운 또 다른 솔루션이 있습니다. Android Studio 메뉴에서
리팩토링은> 사용하지 않는 리소스를 제거 ... .
미사용 리소스가 무엇인지 확인하고 선택적으로 제거 하려면 미리보기 를 클릭하십시오 .
ADT 16을 사용하면 가능한 한 간단하게 수행 할 수 있습니다. ADT 16으로 업데이트하고 Android Lint를 사용하십시오 . 정말 놀라운 도구입니다. 사용되지 않는 모든 리소스 (문자열뿐만 아니라)와 그 이상을 찾을 수 있습니다 . 공식 사이트에서 :
Here are some examples of the types of errors that it looks for:
- Missing translations (and unused translations)
- Layout performance problems (all the issues the old layoutopt tool used to find, and more)
- Unused resources
- Inconsistent array sizes (when arrays are defined in multiple configurations)
- Accessibility and internationalization problems (hardcoded strings, missing contentDescription, etc)
- Icon problems (like missing densities, duplicate icons, wrong sizes, etc)
- Usability problems (like not specifying an input type on a text field)
- Manifest errors
and many more.
Warning: The resource R.string.... appears to be unused [UnusedResources] [lint] <string name="...">some text</string>
string.xml을 확인하려면
쉽습니다 (적어도 내 버전의 Eclipse에서는)
Android 용 Eclipse에서 (버전 v22.6.2-1085508이 있습니다)
이제 strings.xml을 열면 사용되지 않는 문자열이 강조 표시됩니다.
다른 잠재적 인 문제를 해결할 수 있습니다.
이것이 Android 3.3에서 수행 한 방법입니다.
저장되지 않은 변경 사항을 저장소에 체크인하십시오.
참고 : 프로젝트를 빌드하십시오. 컴파일에 실패하면 이러한 strings.xml이 일부 레이아웃 / 메뉴 xml에서 참조 될 가능성이 높습니다. 따라서 해당 레이아웃 xml을 수동으로 삭제할 수도 있습니다!
빌드하고 실행하십시오. 테스트!
프로젝트의 루트에서이 스크립트를 실행하십시오.
`fins res / values / *. xml`의 리소스 파일; 하다
`grep '. * / \ 1 / g'의 문자열 이름; 하다
count1 =`grep -rc "R.string. $ {stringname}"src | egrep -v ': 0 $'| 화장실 -l`
count2 =`grep -rc "@string / $ {stringname}"해상도 / 레이아웃 | egrep -v ': 0 $'| 화장실 -l`
count3 =`grep -rc "@string / $ {stringname}"해상도 / 메뉴 | egrep -v ': 0 $'| 화장실 -l`
count4 =`grep -rc "@string / $ {stringname}"AndroidManifest.xml | egrep -v '^ 0 $'| 화장실 -l`
count5 =`grep -rc "@string / $ {stringname}"res / xml | egrep -v ': 0 $'| 화장실 -l`
[$ count1 -eq 0 -a $ count2 -eq 0 -a $ count3 -eq 0 -a $ count4 -eq 0 -a $ count5 -eq 0] 인 경우; 그때
echo $ resourcefile : $ 문자열 이름
fi
끝난
끝난
`find res / drawable * -type f -name '*. ???'`의 리소스 이름; 하다
resource =`echo $ resourcename | xargs 기본 이름 | sed "s / ^ \ (. * \) \ .... $ / \ 1 / g"`
count1 =`grep -rc "R \ .drawable \. $ {resource}"src | egrep -v ': 0 $'| 화장실 -l`
count2 =`grep -rc "@drawable / $ {resource}"해상도 / 레이아웃 | egrep -v ': 0 $'| 화장실 -l`
count3 =`grep -rc "@drawable / $ {resource}"res / drawable * / *. xml | egrep -v ': 0 $'| 화장실 -l`
count4 =`grep -rc "@drawable / $ {resource}"해상도 / 메뉴 | egrep -v ': 0 $'| 화장실 -l`
count5 =`grep -rc "@drawable / $ {resource}"AndroidManifest.xml | egrep -v '^ 0 $'| 화장실 -l`
[$ count1 -eq 0 -a $ count2 -eq 0 -a $ count3 -eq 0 -a $ count4 -eq 0 -a $ count5 -eq 0] 인 경우; 그때
echo $ resourcename
fi
끝난
`find res / layout / *. xml`의 리소스 이름; 하다
resource =`echo $ resourcename | xargs 기본 이름 | sed "s / ^ \ (. * \) \ .... $ / \ 1 / g"`
count1 =`grep -rc "R \ .layout \. $ {resource}"src | egrep -v ': 0 $'| 화장실 -l`
[$ count1 -eq 0]이면; 그때
echo $ resourcename
fi
끝난
그것은 나에게 이런 종류의 출력을 제공합니다 :
res / values / activity_strings.xml : activity_more res / values / activity_strings.xml : activity_as_reply_to res / values / db_strings.xml : sql_backlog_count res / values / db_strings.xml : sql_backlog_update_last_resend ...
Custom scope선택하여 정의 할 수 있습니다 .Production classesappvalues