tools/android/find_unused_resources.py
def GetUsedResources(source_paths, resource_types):
  """Returns the types and names of resources used in Java or resource files.

  Args:
    source_paths: a list of files or folders collectively containing all the
        Java files, resource files, and the AndroidManifest.xml.
    resource_types: a list of resource types to look for.  Example:
        ['string', 'drawable']

  Returns:
    The resources referenced by the Java and resource files as a list of tuples
    (type, name).  Example:
    [('drawable', 'app_icon'), ('layout', 'month_picker'), ...]
  """
  type_regex = '|'.join(map(re.escape, resource_types))
  patterns = [
      # @+drawable/id and @drawable/id
      r'@((\+?))(%s)/(\w+)' % type_regex,
      # package.R.style.id
      r'\b((\w+\.)*)R\.(%s)\.(\w+)' % type_regex,
      # <style name="child" parent="id">
      r'<(())(%s).*parent="(\w+)">' % type_regex,
  ]
  resources = []
  for pattern in patterns:
    p = subprocess.Popen(
        ['grep', '-REIhoe', pattern] + source_paths,
        stdout=subprocess.PIPE)
    grep_out, grep_err = p.communicate()
    # Check stderr instead of return code, since return code is 1 when no
    # matches are found.
    assert not grep_err, 'grep failed'
    matches = re.finditer(pattern, grep_out)
    for match in matches:
      package = match.group(1)
      if package == 'android.':
        continue
      type_ = match.group(3)
      name = match.group(4)
      resources.append((type_, name))
  return resources
Returns the types and names of resources used in Java or resource files.

  Args:
    source_paths: a list of files or folders collectively containing all the
        Java files, resource files, and the AndroidManifest.xml.
    resource_types: a list of resource types to look for.  Example:
        ['string', 'drawable']

  Returns:
    The resources referenced by the Java and resource files as a list of tuples
    (type, name).  Example:
    [('drawable', 'app_icon'), ('layout', 'month_picker'), ...]
  
Returns the types and names of resources used in Java or resource files.
Returns the types and names of resources used in Java or resource files .
def GetUsedResources(source_paths, resource_types):
  type_regex = '|'.join(map(re.escape, resource_types))
  patterns = [
      r'@((\+?))(%s)/(\w+)' % type_regex,
      r'\b((\w+\.)*)R\.(%s)\.(\w+)' % type_regex,
      r'<(())(%s).*parent="(\w+)">' % type_regex,
  ]
  resources = []
  for pattern in patterns:
    p = subprocess.Popen(
        ['grep', '-REIhoe', pattern] + source_paths,
        stdout=subprocess.PIPE)
    grep_out, grep_err = p.communicate()
    assert not grep_err, 'grep failed'
    matches = re.finditer(pattern, grep_out)
    for match in matches:
      package = match.group(1)
      if package == 'android.':
        continue
      type_ = match.group(3)
      name = match.group(4)
      resources.append((type_, name))
  return resources
def GetUsedResources ( source_paths , resource_types ) : type_regex = '|' . join ( map ( re . escape , resource_types ) ) patterns = [ r'@((\+?))(%s)/(\w+)' % type_regex , r'\b((\w+\.)*)R\.(%s)\.(\w+)' % type_regex , r'<(())(%s).*parent="(\w+)">' % type_regex , ] resources = [ ] for pattern in patterns : p = subprocess . Popen ( [ 'grep' , '-REIhoe' , pattern ] + source_paths , stdout = subprocess . PIPE ) grep_out , grep_err = p . communicate ( ) assert not grep_err , 'grep failed' matches = re . finditer ( pattern , grep_out ) for match in matches : package = match . group ( 1 ) if package == 'android.' : continue type_ = match . group ( 3 ) name = match . group ( 4 ) resources . append ( ( type_ , name ) ) return resources
Returns the types and names of resources used in Java or resource files.
Returns the types and names of resources used in Java or resource files .
"""Returns the types and names of resources used in Java or resource files.

  Args:
    source_paths: a list of files or folders collectively containing all the
        Java files, resource files, and the AndroidManifest.xml.
    resource_types: a list of resource types to look for.  Example:
        ['string', 'drawable']

  Returns:
    The resources referenced by the Java and resource files as a list of tuples
    (type, name).  Example:
    [('drawable', 'app_icon'), ('layout', 'month_picker'), ...]
  """ # @+drawable/id and @drawable/id # package.R.style.id # <style name="child" parent="id"> # Check stderr instead of return code, since return code is 1 when no # matches are found.
The resources referenced by the Java and resource files as a list of tuples
(type, name).
The resources referenced by the Java and resource files as a list of tuples ( type name ) .
source_paths
a list of files or folders collectively containing all the
Java files, resource files, and the AndroidManifest.xml.
a list of files or folders collectively containing all the Java files resource files and the AndroidManifest . xml .
resource_types
a list of resource types to look for.  Example:
['string', 'drawable']
a list of resource types to look for . Example : [ ' string ' ' drawable ' ]