public final class SymbolIo
extends java.lang.Object
AAR Format:
- R.txt in AARs
- Format is
- Contains the resources for this library and all its transitive dependencies.
- Written using writeForAar()
- Only read as part of writeSymbolListWithPackageName() as there are corrupt files with
styleable children not below their parents in the wild.
- IDs and styleable children don't matter, as this is only used to filtering symbols when
generating R classes.
- public.txt in AARs
- Format is
- Contains all the resources from this AAR that are public (missing public.txt means all
resources should be public)
- There are no IDs or styleable children here, needs to be merged with R.txt and filtered by
the public visibility to actually get a full list of public resources from the AAR
AAPT2 Outputs the following formats:
- R.txt as output by AAPT2, where ID values matter.
- Format is
- Read using readFromAapt().
- This is what the R class is generated from.
- Partial R file format.
- Format is
- Contains only the resources defined in a single source file.
- Used to push R class generation earlier.
Internal intermediates:
- Symbol list with package name. Used to filter down the generated R class for this library in
the non-namespaced case.
- Format is [ [, [...]]], with the first line as the package name.
- Contains resources from this sub-project and all its transitive dependencies.
- Read by readSymbolListWithPackageName()
- Generated from AARs and AAPT2 symbol tables by writeSymbolListWithPackageName()
- R def format,
- Used for namespace backward compatibility.
- Contains only the resources defined in a single library.
- Has the package name as the first line.
- May contain internal resource types (e.g. "maybe attributes" defined under declare
styleable resources).
All files are written in UTF-8. R files use linux-type line separators, while R.java use system
line separators.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ANDROID_ATTR_PREFIX |
| Modifier and Type | Method and Description |
|---|---|
static java.io.File |
exportToJava(com.android.ide.common.symbols.SymbolTable table,
java.io.File directory,
boolean finalIds)
Exports a symbol table to a java
R class source. |
static com.android.ide.common.symbols.SymbolTable |
readFromAapt(java.io.File file,
java.lang.String tablePackage)
Loads a symbol table from a symbol file created by aapt.
|
static com.android.ide.common.symbols.SymbolTable |
readFromAaptNoValues(java.io.File file,
java.lang.String tablePackage)
Loads a symbol table from a symbol file created by aapt, but ignores all the resource values.
|
static com.android.ide.common.symbols.SymbolTable |
readFromPartialRFile(java.io.File file,
java.lang.String tablePackage)
Loads a symbol table from a partial symbol file created by aapt during compilation.
|
static com.android.ide.common.symbols.SymbolTable |
readFromPublicTxtFile(java.io.File file,
java.lang.String tablePackage) |
static com.android.ide.common.symbols.SymbolTable |
readRDef(java.nio.file.Path file)
Loads a symbol table from an partial file.
|
static com.android.ide.common.symbols.SymbolTable |
readSymbolListWithPackageName(java.nio.file.Path file)
Loads a symbol table from a synthetic namespaced symbol file.
|
static void |
writeForAar(com.android.ide.common.symbols.SymbolTable table,
java.io.File file)
Writes a symbol table to a symbol file.
|
static void |
writeForAar(com.android.ide.common.symbols.SymbolTable table,
java.nio.file.Path file)
Writes a symbol table to a symbol file.
|
static void |
writeRDef(com.android.ide.common.symbols.SymbolTable table,
java.nio.file.Path file)
Writes a file listing the resources provided by the library.
|
static void |
writeSymbolListWithPackageName(java.nio.file.Path symbolTable,
java.nio.file.Path manifest,
java.nio.file.Path outputFile)
Writes the abridged symbol table with the package name as the first line.
|
static void |
writeSymbolListWithPackageName(java.nio.file.Path symbolTable,
java.lang.String packageName,
java.nio.file.Path outputFile)
Writes the symbol table with the package name as the first line.
|
public static final java.lang.String ANDROID_ATTR_PREFIX
@NonNull
public static com.android.ide.common.symbols.SymbolTable readFromAapt(@NonNull
java.io.File file,
@Nullable
java.lang.String tablePackage)
throws java.io.IOException
file - the symbol filetablePackage - the package name associated with the tablejava.io.IOException - failed to read the table@NonNull
public static com.android.ide.common.symbols.SymbolTable readFromAaptNoValues(@NonNull
java.io.File file,
@Nullable
java.lang.String tablePackage)
throws java.io.IOException
file - the symbol filetablePackage - the package name associated with the tablejava.io.IOException - failed to read the table@NonNull
public static com.android.ide.common.symbols.SymbolTable readFromPartialRFile(@NonNull
java.io.File file,
@Nullable
java.lang.String tablePackage)
throws java.io.IOException
file - the partial symbol filetablePackage - the package name associated with the tablejava.io.IOException - failed to read the table@NonNull
public static com.android.ide.common.symbols.SymbolTable readFromPublicTxtFile(@NonNull
java.io.File file,
@Nullable
java.lang.String tablePackage)
throws java.io.IOException
java.io.IOException@NonNull
public static com.android.ide.common.symbols.SymbolTable readSymbolListWithPackageName(@NonNull
java.nio.file.Path file)
throws java.io.IOException
See writeSymbolListWithPackageName(Path, Path, Path) for format details.
file - the symbol filejava.io.IOException - failed to read the table@NonNull
public static com.android.ide.common.symbols.SymbolTable readRDef(@NonNull
java.nio.file.Path file)
throws java.io.IOException
file - the symbol filejava.io.IOException - failed to read the tablepublic static void writeForAar(@NonNull
com.android.ide.common.symbols.SymbolTable table,
@NonNull
java.io.File file)
throws java.io.IOException
table - the tablefile - the file where the table should be writtenjava.io.IOException - I/O errorpublic static void writeForAar(@NonNull
com.android.ide.common.symbols.SymbolTable table,
@NonNull
java.nio.file.Path file)
throws java.io.IOException
table - the tablefile - the file where the table should be writtenjava.io.IOException - I/O errorpublic static void writeRDef(@NonNull
com.android.ide.common.symbols.SymbolTable table,
@NonNull
java.nio.file.Path file)
throws java.io.IOException
This uses the symbol list with package name format of "<type> <name>[ <child>[
<child>[ ...]]]" .
java.io.IOExceptionpublic static void writeSymbolListWithPackageName(@NonNull
java.nio.file.Path symbolTable,
@NonNull
java.nio.file.Path manifest,
@NonNull
java.nio.file.Path outputFile)
throws java.io.IOException
This collapses the styleable children so the subsequent lines have the format "<type> <canonical_name>[ <child>[ <child>[ ...]]]"
symbolTable - The R.txt file. If it does not exist, the result will be a file containing
only the package namemanifest - The AndroidManifest.xml file for this library. The package name is extracted
and written as the first line of the output.outputFile - The file to write the result to.java.io.IOExceptionpublic static void writeSymbolListWithPackageName(@NonNull
java.nio.file.Path symbolTable,
@Nullable
java.lang.String packageName,
@NonNull
java.nio.file.Path outputFile)
throws java.io.IOException
This collapses the styleable children so the subsequent lines have the format "<type> <canonical_name>[ <child>[ <child>[ ...]]]"
symbolTable - The R.txt file. If it does not exist, the result will be a file containing
only the package namepackageName - The package name for the module. If not null, it will be written as the
first line of output.outputFile - The file to write the result to.java.io.IOException@NonNull
public static java.io.File exportToJava(@NonNull
com.android.ide.common.symbols.SymbolTable table,
@NonNull
java.io.File directory,
boolean finalIds)
R class source. This method will create the source
file and any necessary directories. For example, if the package is a.b and the class
name is RR, this method will generate a file called RR.java in directory
directory/a/b creating directories a and b if necessary.table - the table to exportdirectory - the directory where the R source should be generatedfinalIds - should the generated IDs be final?java.io.UncheckedIOException - failed to generate the source