diff --git a/android_clean_app.py b/android_clean_app.py index 04f66aa..5d72df8 100644 --- a/android_clean_app.py +++ b/android_clean_app.py @@ -23,6 +23,7 @@ class Issue: Stores a single issue reported by Android Lint """ pattern = re.compile('The resource `?([^`]+)`? appears to be unused') + pattern_array = re.compile('<`?([^`]+)`? name="`?([^`]+)`?">') def __init__(self, filepath, remove_file): self.filepath = filepath @@ -40,7 +41,13 @@ def add_element(self, message): if res_all: res = res_all[0] bits = res.split('.')[-2:] - self.elements.append((bits[0], bits[1])) + if bits[0] != 'array': + type = bits[0] + else: + # array is a generic type, which may take form string-array, integer-array, etc. + # The only way to get type is to parse from errorLine1 which is less reliable than message. + type = re.findall(Issue.pattern_array, errorLine1)[0][0] + self.elements.append((type, bits[1])) else: print("The pattern '%s' seems to find nothing in the error message '%s'. We can't find the resource and can't remove it. The pattern might have changed, please check and report this in github issues." % ( Issue.pattern, message)) diff --git a/test/android_app/res/values/strings.xml b/test/android_app/res/values/strings.xml index 4cd5def..42d93db 100644 --- a/test/android_app/res/values/strings.xml +++ b/test/android_app/res/values/strings.xml @@ -2,4 +2,8 @@ android_app missing + + Test1 + Test2 +