public final class SymbolUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
SymbolUtils.SymbolTableGenerationMode |
Constructor and Description |
---|
SymbolUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
canonicalizeValueResourceName(java.lang.String name)
Updates the value resource name to mimic aapt's behaviour - replaces all dots and colons with
underscores.
|
static java.util.List<java.lang.String> |
generateMainDexKeepRules(ManifestData manifest,
java.io.File mergedResources)
Generates keep rules based on the nodes declared in the manifest file.
|
static java.util.List<java.lang.String> |
generateMinifyKeepRules(ManifestData manifest,
java.io.File mergedResources)
Generates keep rules based on the nodes declared in the manifest file.
|
static void |
generateRTxt(com.android.builder.symbols.SymbolTable table,
java.io.File directory)
Creates and writes a symbol table into an R.txt file in a given directory.
|
static java.lang.String |
getPackageNameFromManifest(java.io.File manifestFile)
Pulls out the package name from the given android manifest.
|
static java.lang.String |
getPackageNameFromManifest(ManifestData manifest)
Pulls out the package name from the given parsed android manifest.
|
static java.util.Set<com.android.builder.symbols.SymbolTable> |
loadDependenciesSymbolTables(java.util.Set<java.io.File> libraries,
java.lang.String mainPackageName)
Load symbol tables of each library on which the main library/application depends on.
|
static ManifestData |
parseManifest(java.io.File manifestFile) |
static void |
processLibraryMainSymbolTable(com.android.builder.symbols.SymbolTable librarySymbols,
java.util.Set<java.io.File> libraries,
java.lang.String mainPackageName,
java.io.File manifestFile,
java.io.File sourceOut,
java.io.File symbolsOut,
java.io.File proguardOut,
java.io.File mergedResources,
com.android.builder.symbols.SymbolTable platformSymbols,
boolean disableMergeInLib)
Processes the symbol table and generates necessary files: R.txt, R.java and proguard rules
(
aapt_rules.txt ). |
public static void processLibraryMainSymbolTable(@NonNull com.android.builder.symbols.SymbolTable librarySymbols, @NonNull java.util.Set<java.io.File> libraries, @Nullable java.lang.String mainPackageName, @NonNull java.io.File manifestFile, @NonNull java.io.File sourceOut, @NonNull java.io.File symbolsOut, @Nullable java.io.File proguardOut, @Nullable java.io.File mergedResources, @NonNull com.android.builder.symbols.SymbolTable platformSymbols, boolean disableMergeInLib) throws java.io.IOException
aapt_rules.txt
). Afterwards generates R.java
for all libraries the main
library depends on.librarySymbols
- table with symbols of resources for the library.libraries
- libraries which this library depends onmainPackageName
- package name of this librarymanifestFile
- manifest filesourceOut
- directory to contain R.javasymbolsOut
- directory to contain R.txtproguardOut
- directory to contain proguard rulesmergedResources
- directory containing merged resourcesjava.io.IOException
@NonNull public static java.util.Set<com.android.builder.symbols.SymbolTable> loadDependenciesSymbolTables(@NonNull java.util.Set<java.io.File> libraries, @NonNull java.lang.String mainPackageName) throws java.io.IOException
libraries
- libraries which the main library/application depends onmainPackageName
- package name of the main library/applicationjava.io.IOException
@NonNull public static java.lang.String getPackageNameFromManifest(@NonNull java.io.File manifestFile) throws java.io.IOException
manifestFile
- manifest file of the libraryjava.io.IOException
- if there is a problem reading the manifest or if the manifest does not
contain a package name@NonNull public static java.lang.String getPackageNameFromManifest(@NonNull ManifestData manifest)
manifest
- the parsed manifest of the librarypublic static java.util.List<java.lang.String> generateMinifyKeepRules(@NonNull ManifestData manifest, @Nullable java.io.File mergedResources) throws java.io.IOException
Used in the new resource processing, since aapt is not used in processing libraries'
resources and the aapt_rules.txt
file and its rules are required by minify.
Goes through all application
, instrumentation
, activity
, service
, provider
and receiver
keep class data in the manifest, generates
keep rules for each of them and returns them as a list.
For examples refer to SymbolUtilsTest.java
.
manifest
- containing keep class datajava.io.IOException
public static java.util.List<java.lang.String> generateMainDexKeepRules(@NonNull ManifestData manifest, @Nullable java.io.File mergedResources) throws java.io.IOException
When AAPT2 is enabled, this method is called to generate manifest_keep.txt
file
for Dex. Goes through all application
, instrumentation
, activity
,
service
, provider
and receiver
nodes and generates keep rules for
each of them, as long as the node doesn't declare it belongs to a private process. Returns
the keep rules as a list.
For examples refer to SymbolUtilsTest.java
.
manifest
- containing keep class datajava.io.IOException
public static void generateRTxt(@NonNull com.android.builder.symbols.SymbolTable table, @NonNull java.io.File directory)
table
- the tabledirectory
- the directory where the table should be writtenpublic static ManifestData parseManifest(@NonNull java.io.File manifestFile) throws java.io.IOException
java.io.IOException
@NonNull public static java.lang.String canonicalizeValueResourceName(@NonNull java.lang.String name)
If the name contains whitespaces or other illegal characters, they are not checked in this
method, but caught in the Symbol constructor call to Symbol#validateSymbol
.
name
- the resource name to be updated