Skip to content

Commit 2abde6e

Browse files
author
Ficus Kirkpatrick
committed
Add --max-res-version flag to aapt.
aapt will ignore any versioned resource directories over the specified version (if used). e.g. --max-res-version=6 will cause layout-land-v7 to be ignored. Merged from eclair. Change-Id: I40ccf820c8a6e3074fccc987dd60a511dd8eb0de
1 parent 4f3c537 commit 2abde6e

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

tools/aapt/AaptAssets.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,16 @@ ssize_t AaptAssets::slurpResourceTree(Bundle* bundle, const String8& srcDir)
18251825
continue;
18261826
}
18271827

1828+
if (bundle->getMaxResVersion() != NULL && group.version.length() != 0) {
1829+
int maxResInt = atoi(bundle->getMaxResVersion());
1830+
const char *verString = group.version.string();
1831+
int dirVersionInt = atoi(verString + 1); // skip 'v' in version name
1832+
if (dirVersionInt > maxResInt) {
1833+
fprintf(stderr, "max res %d, skipping %s\n", maxResInt, entry->d_name);
1834+
continue;
1835+
}
1836+
}
1837+
18281838
FileType type = getFileType(subdirName.string());
18291839

18301840
if (type == kFileTypeDirectory) {

tools/aapt/Bundle.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Bundle {
4545
mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
4646
mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
4747
mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL),
48+
mMaxResVersion(NULL),
4849
mArgc(0), mArgv(NULL)
4950
{}
5051
~Bundle(void) {}
@@ -134,6 +135,8 @@ class Bundle {
134135
void setVersionName(const char* val) { mVersionName = val; }
135136
const char* getCustomPackage() const { return mCustomPackage; }
136137
void setCustomPackage(const char* val) { mCustomPackage = val; }
138+
const char* getMaxResVersion() const { return mMaxResVersion; }
139+
void setMaxResVersion(const char * val) { mMaxResVersion = val; }
137140

138141
/*
139142
* Set and get the file specification.
@@ -230,6 +233,7 @@ class Bundle {
230233
const char* mVersionCode;
231234
const char* mVersionName;
232235
const char* mCustomPackage;
236+
const char* mMaxResVersion;
233237

234238
/* file specification */
235239
int mArgc;

tools/aapt/Main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void usage(void)
6262
" [--rename-manifest-package PACKAGE] \\\n"
6363
" [--rename-instrumentation-target-package PACKAGE] \\\n"
6464
" [--utf16] [--auto-add-overlay] \\\n"
65+
" [--max-res-version VAL] \\\n"
6566
" [-I base-package [-I base-package ...]] \\\n"
6667
" [-A asset-source-dir] [-G class-list-file] [-P public-definitions-file] \\\n"
6768
" [-S resource-sources [-S resource-sources ...]] "
@@ -128,6 +129,8 @@ void usage(void)
128129
" higher, the default encoding for resources will be in UTF-8.\n"
129130
" --target-sdk-version\n"
130131
" inserts android:targetSdkVersion in to manifest.\n"
132+
" --max-res-version\n"
133+
" ignores versioned resource directories above the given value.\n"
131134
" --values\n"
132135
" when used with \"dump resources\" also includes resource values.\n"
133136
" --version-code\n"
@@ -416,6 +419,15 @@ int main(int argc, char* const argv[])
416419
goto bail;
417420
}
418421
bundle.setMaxSdkVersion(argv[0]);
422+
} else if (strcmp(cp, "-max-res-version") == 0) {
423+
argc--;
424+
argv++;
425+
if (!argc) {
426+
fprintf(stderr, "ERROR: No argument supplied for '--max-res-version' option\n");
427+
wantUsage = true;
428+
goto bail;
429+
}
430+
bundle.setMaxResVersion(argv[0]);
419431
} else if (strcmp(cp, "-version-code") == 0) {
420432
argc--;
421433
argv++;

0 commit comments

Comments
 (0)