2 // Copyright 2006 The Android Open Source Project
4 // Build resource files from raw assets.
7 #include "AaptAssets.h"
8 #include "StringPool.h"
10 #include "ResourceTable.h"
15 // ==========================================================================
16 // ==========================================================================
17 // ==========================================================================
29 status_t
parsePackage(const sp
<AaptGroup
>& grp
);
32 // ==========================================================================
33 // ==========================================================================
34 // ==========================================================================
36 static String8
parseResourceName(const String8
& leaf
)
38 const char* firstDot
= strchr(leaf
.string(), '.');
39 const char* str
= leaf
.string();
42 return String8(str
, firstDot
-str
);
48 ResourceTypeSet::ResourceTypeSet()
50 KeyedVector
<String8
,sp
<AaptGroup
> >()
54 class ResourceDirIterator
57 ResourceDirIterator(const sp
<ResourceTypeSet
>& set
, const String8
& resType
)
58 : mResType(resType
), mSet(set
), mSetPos(0), mGroupPos(0)
62 inline const sp
<AaptGroup
>& getGroup() const { return mGroup
; }
63 inline const sp
<AaptFile
>& getFile() const { return mFile
; }
65 inline const String8
& getBaseName() const { return mBaseName
; }
66 inline const String8
& getLeafName() const { return mLeafName
; }
67 inline String8
getPath() const { return mPath
; }
68 inline const ResTable_config
& getParams() const { return mParams
; }
80 // Try to get next file in this current group.
81 if (mGroup
!= NULL
&& mGroupPos
< mGroup
->getFiles().size()) {
83 file
= group
->getFiles().valueAt(mGroupPos
++);
85 // Try to get the next group/file in this directory
86 } else if (mSetPos
< mSet
->size()) {
87 mGroup
= group
= mSet
->valueAt(mSetPos
++);
88 if (group
->getFiles().size() < 1) {
91 file
= group
->getFiles().valueAt(0);
101 String8
leaf(group
->getLeaf());
102 mLeafName
= String8(leaf
);
103 mParams
= file
->getGroupEntry().toParams();
104 NOISY(printf("Dir %s: mcc=%d mnc=%d lang=%c%c cnt=%c%c orient=%d density=%d touch=%d key=%d inp=%d nav=%d\n",
105 group
->getPath().string(), mParams
.mcc
, mParams
.mnc
,
106 mParams
.language
[0] ? mParams
.language
[0] : '-',
107 mParams
.language
[1] ? mParams
.language
[1] : '-',
108 mParams
.country
[0] ? mParams
.country
[0] : '-',
109 mParams
.country
[1] ? mParams
.country
[1] : '-',
111 mParams
.density
, mParams
.touchscreen
, mParams
.keyboard
,
112 mParams
.inputFlags
, mParams
.navigation
));
114 mPath
.appendPath(file
->getGroupEntry().toDirName(mResType
));
115 mPath
.appendPath(leaf
);
116 mBaseName
= parseResourceName(leaf
);
117 if (mBaseName
== "") {
118 fprintf(stderr
, "Error: malformed resource filename %s\n",
119 file
->getPrintableSource().string());
120 return UNKNOWN_ERROR
;
123 NOISY(printf("file name=%s\n", mBaseName
.string()));
132 const sp
<ResourceTypeSet
> mSet
;
135 sp
<AaptGroup
> mGroup
;
142 ResTable_config mParams
;
145 // ==========================================================================
146 // ==========================================================================
147 // ==========================================================================
149 bool isValidResourceType(const String8
& type
)
151 return type
== "anim" || type
== "drawable" || type
== "layout"
152 || type
== "values" || type
== "xml" || type
== "raw"
153 || type
== "color" || type
== "menu";
156 static sp
<AaptFile
> getResourceFile(const sp
<AaptAssets
>& assets
, bool makeIfNecessary
=true)
158 sp
<AaptGroup
> group
= assets
->getFiles().valueFor(String8("resources.arsc"));
161 file
= group
->getFiles().valueFor(AaptGroupEntry());
167 if (!makeIfNecessary
) {
170 return assets
->addFile(String8("resources.arsc"), AaptGroupEntry(), String8(),
174 static status_t
parsePackage(const sp
<AaptAssets
>& assets
, const sp
<AaptGroup
>& grp
)
176 if (grp
->getFiles().size() != 1) {
177 fprintf(stderr
, "WARNING: Multiple AndroidManifest.xml files found, using %s\n",
178 grp
->getFiles().valueAt(0)->getPrintableSource().string());
181 sp
<AaptFile
> file
= grp
->getFiles().valueAt(0);
184 status_t err
= parseXMLResource(file
, &block
);
185 if (err
!= NO_ERROR
) {
188 //printXMLBlock(&block);
190 ResXMLTree::event_code_t code
;
191 while ((code
=block
.next()) != ResXMLTree::START_TAG
192 && code
!= ResXMLTree::END_DOCUMENT
193 && code
!= ResXMLTree::BAD_DOCUMENT
) {
197 if (code
!= ResXMLTree::START_TAG
) {
198 fprintf(stderr
, "%s:%d: No start tag found\n",
199 file
->getPrintableSource().string(), block
.getLineNumber());
200 return UNKNOWN_ERROR
;
202 if (strcmp16(block
.getElementName(&len
), String16("manifest").string()) != 0) {
203 fprintf(stderr
, "%s:%d: Invalid start tag %s, expected <manifest>\n",
204 file
->getPrintableSource().string(), block
.getLineNumber(),
205 String8(block
.getElementName(&len
)).string());
206 return UNKNOWN_ERROR
;
209 ssize_t nameIndex
= block
.indexOfAttribute(NULL
, "package");
211 fprintf(stderr
, "%s:%d: <manifest> does not have package attribute.\n",
212 file
->getPrintableSource().string(), block
.getLineNumber());
213 return UNKNOWN_ERROR
;
216 assets
->setPackage(String8(block
.getAttributeStringValue(nameIndex
, &len
)));
221 // ==========================================================================
222 // ==========================================================================
223 // ==========================================================================
225 static status_t
makeFileResources(Bundle
* bundle
, const sp
<AaptAssets
>& assets
,
226 ResourceTable
* table
,
227 const sp
<ResourceTypeSet
>& set
,
230 String8
type8(resType
);
231 String16
type16(resType
);
233 bool hasErrors
= false;
235 ResourceDirIterator
it(set
, String8(resType
));
237 while ((res
=it
.next()) == NO_ERROR
) {
238 if (bundle
->getVerbose()) {
239 printf(" (new resource id %s from %s)\n",
240 it
.getBaseName().string(), it
.getFile()->getPrintableSource().string());
242 String16
baseName(it
.getBaseName());
243 const char16_t* str
= baseName
.string();
244 const char16_t* const end
= str
+ baseName
.size();
246 if (!((*str
>= 'a' && *str
<= 'z')
247 || (*str
>= '0' && *str
<= '9')
248 || *str
== '_' || *str
== '.')) {
249 fprintf(stderr
, "%s: Invalid file name: must contain only [a-z0-9_.]\n",
250 it
.getPath().string());
255 String8 resPath
= it
.getPath();
256 resPath
.convertToResPath();
257 table
->addEntry(SourcePos(it
.getPath(), 0), String16(assets
->getPackage()),
263 assets
->addResource(it
.getLeafName(), resPath
, it
.getFile(), type8
);
266 return hasErrors
? UNKNOWN_ERROR
: NO_ERROR
;
269 static status_t
preProcessImages(Bundle
* bundle
, const sp
<AaptAssets
>& assets
,
270 const sp
<ResourceTypeSet
>& set
)
272 ResourceDirIterator
it(set
, String8("drawable"));
273 Vector
<sp
<AaptFile
> > newNameFiles
;
274 Vector
<String8
> newNamePaths
;
276 while ((res
=it
.next()) == NO_ERROR
) {
277 res
= preProcessImage(bundle
, assets
, it
.getFile(), NULL
);
278 if (res
!= NO_ERROR
) {
286 status_t
postProcessImages(const sp
<AaptAssets
>& assets
,
287 ResourceTable
* table
,
288 const sp
<ResourceTypeSet
>& set
)
290 ResourceDirIterator
it(set
, String8("drawable"));
292 while ((res
=it
.next()) == NO_ERROR
) {
293 res
= postProcessImage(assets
, table
, it
.getFile());
294 if (res
!= NO_ERROR
) {
299 return res
< NO_ERROR
? res
: (status_t
)NO_ERROR
;
302 static void collect_files(const sp
<AaptDir
>& dir
,
303 KeyedVector
<String8
, sp
<ResourceTypeSet
> >* resources
)
305 const DefaultKeyedVector
<String8
, sp
<AaptGroup
> >& groups
= dir
->getFiles();
306 int N
= groups
.size();
307 for (int i
=0; i
<N
; i
++) {
308 String8 leafName
= groups
.keyAt(i
);
309 const sp
<AaptGroup
>& group
= groups
.valueAt(i
);
311 const DefaultKeyedVector
<AaptGroupEntry
, sp
<AaptFile
> >& files
314 if (files
.size() == 0) {
318 String8 resType
= files
.valueAt(0)->getResourceType();
320 ssize_t index
= resources
->indexOfKey(resType
);
323 sp
<ResourceTypeSet
> set
= new ResourceTypeSet();
324 set
->add(leafName
, group
);
325 resources
->add(resType
, set
);
327 sp
<ResourceTypeSet
> set
= resources
->valueAt(index
);
328 index
= set
->indexOfKey(leafName
);
330 set
->add(leafName
, group
);
332 sp
<AaptGroup
> existingGroup
= set
->valueAt(index
);
333 int M
= files
.size();
334 for (int j
=0; j
<M
; j
++) {
335 existingGroup
->addFile(files
.valueAt(j
));
342 static void collect_files(const sp
<AaptAssets
>& ass
,
343 KeyedVector
<String8
, sp
<ResourceTypeSet
> >* resources
)
345 const Vector
<sp
<AaptDir
> >& dirs
= ass
->resDirs();
348 for (int i
=0; i
<N
; i
++) {
349 sp
<AaptDir
> d
= dirs
.itemAt(i
);
350 collect_files(d
, resources
);
352 // don't try to include the res dir
353 ass
->removeDir(d
->getLeaf());
360 ATTR_LEADING_SPACES
= -3,
361 ATTR_TRAILING_SPACES
= -4
363 static int validateAttr(const String8
& path
, const ResXMLParser
& parser
,
364 const char* ns
, const char* attr
, const char* validChars
, bool required
)
368 ssize_t index
= parser
.indexOfAttribute(ns
, attr
);
370 if (index
>= 0 && (str
=parser
.getAttributeStringValue(index
, &len
)) != NULL
) {
372 for (size_t i
=0; i
<len
; i
++) {
374 const char* p
= validChars
;
384 fprintf(stderr
, "%s:%d: Tag <%s> attribute %s has invalid character '%c'.\n",
385 path
.string(), parser
.getLineNumber(),
386 String8(parser
.getElementName(&len
)).string(), attr
, (char)str
[i
]);
392 fprintf(stderr
, "%s:%d: Tag <%s> attribute %s can not start with a space.\n",
393 path
.string(), parser
.getLineNumber(),
394 String8(parser
.getElementName(&len
)).string(), attr
);
395 return ATTR_LEADING_SPACES
;
397 if (str
[len
-1] == ' ') {
398 fprintf(stderr
, "%s:%d: Tag <%s> attribute %s can not end with a space.\n",
399 path
.string(), parser
.getLineNumber(),
400 String8(parser
.getElementName(&len
)).string(), attr
);
401 return ATTR_TRAILING_SPACES
;
406 fprintf(stderr
, "%s:%d: Tag <%s> missing required attribute %s.\n",
407 path
.string(), parser
.getLineNumber(),
408 String8(parser
.getElementName(&len
)).string(), attr
);
409 return ATTR_NOT_FOUND
;
414 static void checkForIds(const String8
& path
, ResXMLParser
& parser
)
416 ResXMLTree::event_code_t code
;
417 while ((code
=parser
.next()) != ResXMLTree::END_DOCUMENT
418 && code
> ResXMLTree::BAD_DOCUMENT
) {
419 if (code
== ResXMLTree::START_TAG
) {
420 ssize_t index
= parser
.indexOfAttribute(NULL
, "id");
422 fprintf(stderr
, "%s:%d: WARNING: found plain 'id' attribute; did you mean the new 'android:id' name?\n",
423 path
.string(), parser
.getLineNumber());
429 static void applyFileOverlay(const sp
<AaptAssets
>& assets
,
430 const sp
<ResourceTypeSet
>& baseSet
,
433 // Replace any base level files in this category with any found from the overlay
434 // Also add any found only in the overlay.
435 sp
<AaptAssets
> overlay
= assets
->getOverlay();
436 String8
resTypeString(resType
);
438 // work through the linked list of overlays
439 while (overlay
.get()) {
440 KeyedVector
<String8
, sp
<ResourceTypeSet
> >* overlayRes
= overlay
->getResources();
442 // get the overlay resources of the requested type
443 ssize_t index
= overlayRes
->indexOfKey(resTypeString
);
445 sp
<ResourceTypeSet
> overlaySet
= overlayRes
->valueAt(index
);
447 // for each of the resources, check for a match in the previously built
448 // non-overlay "baseset".
449 size_t overlayCount
= overlaySet
->size();
450 for (size_t overlayIndex
=0; overlayIndex
<overlayCount
; overlayIndex
++) {
451 size_t baseIndex
= baseSet
->indexOfKey(overlaySet
->keyAt(overlayIndex
));
452 if (baseIndex
!= UNKNOWN_ERROR
) {
453 // look for same flavor. For a given file (strings.xml, for example)
454 // there may be a locale specific or other flavors - we want to match
456 sp
<AaptGroup
> overlayGroup
= overlaySet
->valueAt(overlayIndex
);
457 sp
<AaptGroup
> baseGroup
= baseSet
->valueAt(baseIndex
);
459 DefaultKeyedVector
<AaptGroupEntry
, sp
<AaptFile
> > baseFiles
=
460 baseGroup
->getFiles();
461 DefaultKeyedVector
<AaptGroupEntry
, sp
<AaptFile
> > overlayFiles
=
462 overlayGroup
->getFiles();
463 size_t overlayGroupSize
= overlayFiles
.size();
464 for (size_t overlayGroupIndex
= 0;
465 overlayGroupIndex
<overlayGroupSize
;
466 overlayGroupIndex
++) {
467 size_t baseFileIndex
=
468 baseFiles
.indexOfKey(overlayFiles
.keyAt(overlayGroupIndex
));
469 if(baseFileIndex
< UNKNOWN_ERROR
) {
470 baseGroup
->removeFile(baseFileIndex
);
472 // didn't find a match fall through and add it..
474 baseGroup
->addFile(overlayFiles
.valueAt(overlayGroupIndex
));
477 // this group doesn't exist (a file that's only in the overlay)
479 baseSet
->add(overlaySet
->keyAt(overlayIndex
),
480 overlaySet
->valueAt(overlayIndex
));
483 // this overlay didn't have resources for this type
486 overlay
= overlay
->getOverlay();
491 void addTagAttribute(const sp
<XMLNode
>& node
, const char* ns8
,
492 const char* attr8
, const char* value
)
498 const String16
ns(ns8
);
499 const String16
attr(attr8
);
501 if (node
->getAttribute(ns
, attr
) != NULL
) {
502 fprintf(stderr
, "Warning: AndroidManifest.xml already defines %s (in %s)\n",
503 String8(attr
).string(), String8(ns
).string());
507 node
->addAttribute(ns
, attr
, String16(value
));
510 status_t
massageManifest(Bundle
* bundle
, sp
<XMLNode
> root
)
512 root
= root
->searchElement(String16(), String16("manifest"));
514 fprintf(stderr
, "No <manifest> tag.\n");
515 return UNKNOWN_ERROR
;
518 addTagAttribute(root
, RESOURCES_ANDROID_NAMESPACE
, "versionCode",
519 bundle
->getVersionCode());
520 addTagAttribute(root
, RESOURCES_ANDROID_NAMESPACE
, "versionName",
521 bundle
->getVersionName());
523 if (bundle
->getMinSdkVersion() != NULL
524 || bundle
->getTargetSdkVersion() != NULL
525 || bundle
->getMaxSdkVersion() != NULL
) {
526 sp
<XMLNode
> vers
= root
->getChildElement(String16(), String16("uses-sdk"));
528 vers
= XMLNode::newElement(root
->getFilename(), String16(), String16("uses-sdk"));
529 root
->insertChildAt(vers
, 0);
532 addTagAttribute(vers
, RESOURCES_ANDROID_NAMESPACE
, "minSdkVersion",
533 bundle
->getMinSdkVersion());
534 addTagAttribute(vers
, RESOURCES_ANDROID_NAMESPACE
, "targetSdkVersion",
535 bundle
->getTargetSdkVersion());
536 addTagAttribute(vers
, RESOURCES_ANDROID_NAMESPACE
, "maxSdkVersion",
537 bundle
->getMaxSdkVersion());
543 #define ASSIGN_IT(n) \
545 ssize_t index = resources->indexOfKey(String8(#n)); \
547 n ## s = resources->valueAt(index); \
551 status_t
buildResources(Bundle
* bundle
, const sp
<AaptAssets
>& assets
)
553 // First, look for a package file to parse. This is required to
554 // be able to generate the resource information.
555 sp
<AaptGroup
> androidManifestFile
=
556 assets
->getFiles().valueFor(String8("AndroidManifest.xml"));
557 if (androidManifestFile
== NULL
) {
558 fprintf(stderr
, "ERROR: No AndroidManifest.xml file found.\n");
559 return UNKNOWN_ERROR
;
562 status_t err
= parsePackage(assets
, androidManifestFile
);
563 if (err
!= NO_ERROR
) {
567 NOISY(printf("Creating resources for package %s\n",
568 assets
->getPackage().string()));
570 ResourceTable
table(bundle
, String16(assets
->getPackage()));
571 err
= table
.addIncludedResources(bundle
, assets
);
572 if (err
!= NO_ERROR
) {
576 NOISY(printf("Found %d included resource packages\n", (int)table
.size()));
578 // --------------------------------------------------------------
579 // First, gather all resource information.
580 // --------------------------------------------------------------
582 // resType -> leafName -> group
583 KeyedVector
<String8
, sp
<ResourceTypeSet
> > *resources
=
584 new KeyedVector
<String8
, sp
<ResourceTypeSet
> >;
585 collect_files(assets
, resources
);
587 sp
<ResourceTypeSet
> drawables
;
588 sp
<ResourceTypeSet
> layouts
;
589 sp
<ResourceTypeSet
> anims
;
590 sp
<ResourceTypeSet
> xmls
;
591 sp
<ResourceTypeSet
> raws
;
592 sp
<ResourceTypeSet
> colors
;
593 sp
<ResourceTypeSet
> menus
;
603 assets
->setResources(resources
);
604 // now go through any resource overlays and collect their files
605 sp
<AaptAssets
> current
= assets
->getOverlay();
606 while(current
.get()) {
607 KeyedVector
<String8
, sp
<ResourceTypeSet
> > *resources
=
608 new KeyedVector
<String8
, sp
<ResourceTypeSet
> >;
609 current
->setResources(resources
);
610 collect_files(current
, resources
);
611 current
= current
->getOverlay();
613 // apply the overlay files to the base set
614 applyFileOverlay(assets
, drawables
, "drawable");
615 applyFileOverlay(assets
, layouts
, "layout");
616 applyFileOverlay(assets
, anims
, "anim");
617 applyFileOverlay(assets
, xmls
, "xml");
618 applyFileOverlay(assets
, raws
, "raw");
619 applyFileOverlay(assets
, colors
, "color");
620 applyFileOverlay(assets
, menus
, "menu");
622 bool hasErrors
= false;
624 if (drawables
!= NULL
) {
625 err
= preProcessImages(bundle
, assets
, drawables
);
626 if (err
== NO_ERROR
) {
627 err
= makeFileResources(bundle
, assets
, &table
, drawables
, "drawable");
628 if (err
!= NO_ERROR
) {
636 if (layouts
!= NULL
) {
637 err
= makeFileResources(bundle
, assets
, &table
, layouts
, "layout");
638 if (err
!= NO_ERROR
) {
644 err
= makeFileResources(bundle
, assets
, &table
, anims
, "anim");
645 if (err
!= NO_ERROR
) {
651 err
= makeFileResources(bundle
, assets
, &table
, xmls
, "xml");
652 if (err
!= NO_ERROR
) {
658 err
= makeFileResources(bundle
, assets
, &table
, raws
, "raw");
659 if (err
!= NO_ERROR
) {
666 while(current
.get()) {
667 KeyedVector
<String8
, sp
<ResourceTypeSet
> > *resources
=
668 current
->getResources();
670 ssize_t index
= resources
->indexOfKey(String8("values"));
672 ResourceDirIterator
it(resources
->valueAt(index
), String8("values"));
674 while ((res
=it
.next()) == NO_ERROR
) {
675 sp
<AaptFile
> file
= it
.getFile();
676 res
= compileResourceFile(bundle
, assets
, file
, it
.getParams(),
677 (current
!=assets
), &table
);
678 if (res
!= NO_ERROR
) {
683 current
= current
->getOverlay();
686 if (colors
!= NULL
) {
687 err
= makeFileResources(bundle
, assets
, &table
, colors
, "color");
688 if (err
!= NO_ERROR
) {
694 err
= makeFileResources(bundle
, assets
, &table
, menus
, "menu");
695 if (err
!= NO_ERROR
) {
700 // --------------------------------------------------------------------
701 // Assignment of resource IDs and initial generation of resource table.
702 // --------------------------------------------------------------------
704 if (table
.hasResources()) {
705 sp
<AaptFile
> resFile(getResourceFile(assets
));
706 if (resFile
== NULL
) {
707 fprintf(stderr
, "Error: unable to generate entry for resource data\n");
708 return UNKNOWN_ERROR
;
711 err
= table
.assignResourceIds();
712 if (err
< NO_ERROR
) {
717 // --------------------------------------------------------------
718 // Finally, we can now we can compile XML files, which may reference
720 // --------------------------------------------------------------
722 if (layouts
!= NULL
) {
723 ResourceDirIterator
it(layouts
, String8("layout"));
724 while ((err
=it
.next()) == NO_ERROR
) {
725 String8 src
= it
.getFile()->getPrintableSource();
726 err
= compileXmlFile(assets
, it
.getFile(), &table
);
727 if (err
== NO_ERROR
) {
729 block
.setTo(it
.getFile()->getData(), it
.getFile()->getSize(), true);
730 checkForIds(src
, block
);
736 if (err
< NO_ERROR
) {
743 ResourceDirIterator
it(anims
, String8("anim"));
744 while ((err
=it
.next()) == NO_ERROR
) {
745 err
= compileXmlFile(assets
, it
.getFile(), &table
);
746 if (err
!= NO_ERROR
) {
751 if (err
< NO_ERROR
) {
758 ResourceDirIterator
it(xmls
, String8("xml"));
759 while ((err
=it
.next()) == NO_ERROR
) {
760 err
= compileXmlFile(assets
, it
.getFile(), &table
);
761 if (err
!= NO_ERROR
) {
766 if (err
< NO_ERROR
) {
772 if (drawables
!= NULL
) {
773 err
= postProcessImages(assets
, &table
, drawables
);
774 if (err
!= NO_ERROR
) {
779 if (colors
!= NULL
) {
780 ResourceDirIterator
it(colors
, String8("color"));
781 while ((err
=it
.next()) == NO_ERROR
) {
782 err
= compileXmlFile(assets
, it
.getFile(), &table
);
783 if (err
!= NO_ERROR
) {
788 if (err
< NO_ERROR
) {
795 ResourceDirIterator
it(menus
, String8("menu"));
796 while ((err
=it
.next()) == NO_ERROR
) {
797 String8 src
= it
.getFile()->getPrintableSource();
798 err
= compileXmlFile(assets
, it
.getFile(), &table
);
799 if (err
!= NO_ERROR
) {
803 block
.setTo(it
.getFile()->getData(), it
.getFile()->getSize(), true);
804 checkForIds(src
, block
);
807 if (err
< NO_ERROR
) {
813 const sp
<AaptFile
> manifestFile(androidManifestFile
->getFiles().valueAt(0));
814 String8
manifestPath(manifestFile
->getPrintableSource());
816 // Perform a basic validation of the manifest file. This time we
817 // parse it with the comments intact, so that we can use them to
818 // generate java docs... so we are not going to write this one
819 // back out to the final manifest data.
820 err
= compileXmlFile(assets
, manifestFile
, &table
,
821 XML_COMPILE_ASSIGN_ATTRIBUTE_IDS
822 | XML_COMPILE_STRIP_WHITESPACE
| XML_COMPILE_STRIP_RAW_VALUES
);
823 if (err
< NO_ERROR
) {
827 block
.setTo(manifestFile
->getData(), manifestFile
->getSize(), true);
828 String16
manifest16("manifest");
829 String16
permission16("permission");
830 String16
permission_group16("permission-group");
831 String16
uses_permission16("uses-permission");
832 String16
instrumentation16("instrumentation");
833 String16
application16("application");
834 String16
provider16("provider");
835 String16
service16("service");
836 String16
receiver16("receiver");
837 String16
activity16("activity");
838 String16
action16("action");
839 String16
category16("category");
840 String16
data16("scheme");
841 const char* packageIdentChars
= "abcdefghijklmnopqrstuvwxyz"
842 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789";
843 const char* packageIdentCharsWithTheStupid
= "abcdefghijklmnopqrstuvwxyz"
844 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789-";
845 const char* classIdentChars
= "abcdefghijklmnopqrstuvwxyz"
846 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789$";
847 const char* processIdentChars
= "abcdefghijklmnopqrstuvwxyz"
848 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789:";
849 const char* authoritiesIdentChars
= "abcdefghijklmnopqrstuvwxyz"
850 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789-:;";
851 const char* typeIdentChars
= "abcdefghijklmnopqrstuvwxyz"
852 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789:-/*+";
853 const char* schemeIdentChars
= "abcdefghijklmnopqrstuvwxyz"
854 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789-";
855 ResXMLTree::event_code_t code
;
856 sp
<AaptSymbols
> permissionSymbols
;
857 sp
<AaptSymbols
> permissionGroupSymbols
;
858 while ((code
=block
.next()) != ResXMLTree::END_DOCUMENT
859 && code
> ResXMLTree::BAD_DOCUMENT
) {
860 if (code
== ResXMLTree::START_TAG
) {
862 if (block
.getElementNamespace(&len
) != NULL
) {
865 if (strcmp16(block
.getElementName(&len
), manifest16
.string()) == 0) {
866 if (validateAttr(manifestPath
, block
, NULL
, "package",
867 packageIdentChars
, true) != ATTR_OKAY
) {
870 } else if (strcmp16(block
.getElementName(&len
), permission16
.string()) == 0
871 || strcmp16(block
.getElementName(&len
), permission_group16
.string()) == 0) {
872 const bool isGroup
= strcmp16(block
.getElementName(&len
),
873 permission_group16
.string()) == 0;
874 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
875 isGroup
? packageIdentCharsWithTheStupid
876 : packageIdentChars
, true) != ATTR_OKAY
) {
879 SourcePos
srcPos(manifestPath
, block
.getLineNumber());
880 sp
<AaptSymbols
> syms
;
882 syms
= permissionSymbols
;
884 sp
<AaptSymbols
> symbols
=
885 assets
->getSymbolsFor(String8("Manifest"));
886 syms
= permissionSymbols
= symbols
->addNestedSymbol(
887 String8("permission"), srcPos
);
890 syms
= permissionGroupSymbols
;
892 sp
<AaptSymbols
> symbols
=
893 assets
->getSymbolsFor(String8("Manifest"));
894 syms
= permissionGroupSymbols
= symbols
->addNestedSymbol(
895 String8("permission_group"), srcPos
);
899 ssize_t index
= block
.indexOfAttribute(RESOURCES_ANDROID_NAMESPACE
, "name");
900 const uint16_t* id
= block
.getAttributeStringValue(index
, &len
);
902 fprintf(stderr
, "%s:%d: missing name attribute in element <%s>.\n",
903 manifestPath
.string(), block
.getLineNumber(),
904 String8(block
.getElementName(&len
)).string());
909 char* p
= idStr
.lockBuffer(idStr
.size());
910 char* e
= p
+ idStr
.size();
911 bool begins_with_digit
= true; // init to true so an empty string fails
914 if (*e
>= '0' && *e
<= '9') {
915 begins_with_digit
= true;
918 if ((*e
>= 'a' && *e
<= 'z') ||
919 (*e
>= 'A' && *e
<= 'Z') ||
921 begins_with_digit
= false;
924 if (isGroup
&& (*e
== '-')) {
926 begins_with_digit
= false;
932 idStr
.unlockBuffer();
933 // verify that we stopped because we hit a period or
934 // the beginning of the string, and that the
935 // identifier didn't begin with a digit.
936 if (begins_with_digit
|| (e
!= p
&& *(e
-1) != '.')) {
938 "%s:%d: Permission name <%s> is not a valid Java symbol\n",
939 manifestPath
.string(), block
.getLineNumber(), idStr
.string());
942 syms
->addStringSymbol(String8(e
), idStr
, srcPos
);
943 const uint16_t* cmt
= block
.getComment(&len
);
944 if (cmt
!= NULL
&& *cmt
!= 0) {
945 //printf("Comment of %s: %s\n", String8(e).string(),
946 // String8(cmt).string());
947 syms
->appendComment(String8(e
), String16(cmt
), srcPos
);
949 //printf("No comment for %s\n", String8(e).string());
951 syms
->makeSymbolPublic(String8(e
), srcPos
);
952 } else if (strcmp16(block
.getElementName(&len
), uses_permission16
.string()) == 0) {
953 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
954 packageIdentChars
, true) != ATTR_OKAY
) {
957 } else if (strcmp16(block
.getElementName(&len
), instrumentation16
.string()) == 0) {
958 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
959 classIdentChars
, true) != ATTR_OKAY
) {
962 if (validateAttr(manifestPath
, block
,
963 RESOURCES_ANDROID_NAMESPACE
, "targetPackage",
964 packageIdentChars
, true) != ATTR_OKAY
) {
967 } else if (strcmp16(block
.getElementName(&len
), application16
.string()) == 0) {
968 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
969 classIdentChars
, false) != ATTR_OKAY
) {
972 if (validateAttr(manifestPath
, block
,
973 RESOURCES_ANDROID_NAMESPACE
, "permission",
974 packageIdentChars
, false) != ATTR_OKAY
) {
977 if (validateAttr(manifestPath
, block
,
978 RESOURCES_ANDROID_NAMESPACE
, "process",
979 processIdentChars
, false) != ATTR_OKAY
) {
982 if (validateAttr(manifestPath
, block
,
983 RESOURCES_ANDROID_NAMESPACE
, "taskAffinity",
984 processIdentChars
, false) != ATTR_OKAY
) {
987 } else if (strcmp16(block
.getElementName(&len
), provider16
.string()) == 0) {
988 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
989 classIdentChars
, true) != ATTR_OKAY
) {
992 if (validateAttr(manifestPath
, block
,
993 RESOURCES_ANDROID_NAMESPACE
, "authorities",
994 authoritiesIdentChars
, true) != ATTR_OKAY
) {
997 if (validateAttr(manifestPath
, block
,
998 RESOURCES_ANDROID_NAMESPACE
, "permission",
999 packageIdentChars
, false) != ATTR_OKAY
) {
1002 if (validateAttr(manifestPath
, block
,
1003 RESOURCES_ANDROID_NAMESPACE
, "process",
1004 processIdentChars
, false) != ATTR_OKAY
) {
1007 } else if (strcmp16(block
.getElementName(&len
), service16
.string()) == 0
1008 || strcmp16(block
.getElementName(&len
), receiver16
.string()) == 0
1009 || strcmp16(block
.getElementName(&len
), activity16
.string()) == 0) {
1010 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
1011 classIdentChars
, true) != ATTR_OKAY
) {
1014 if (validateAttr(manifestPath
, block
,
1015 RESOURCES_ANDROID_NAMESPACE
, "permission",
1016 packageIdentChars
, false) != ATTR_OKAY
) {
1019 if (validateAttr(manifestPath
, block
,
1020 RESOURCES_ANDROID_NAMESPACE
, "process",
1021 processIdentChars
, false) != ATTR_OKAY
) {
1024 if (validateAttr(manifestPath
, block
,
1025 RESOURCES_ANDROID_NAMESPACE
, "taskAffinity",
1026 processIdentChars
, false) != ATTR_OKAY
) {
1029 } else if (strcmp16(block
.getElementName(&len
), action16
.string()) == 0
1030 || strcmp16(block
.getElementName(&len
), category16
.string()) == 0) {
1031 if (validateAttr(manifestPath
, block
,
1032 RESOURCES_ANDROID_NAMESPACE
, "name",
1033 packageIdentChars
, true) != ATTR_OKAY
) {
1036 } else if (strcmp16(block
.getElementName(&len
), data16
.string()) == 0) {
1037 if (validateAttr(manifestPath
, block
,
1038 RESOURCES_ANDROID_NAMESPACE
, "mimeType",
1039 typeIdentChars
, true) != ATTR_OKAY
) {
1042 if (validateAttr(manifestPath
, block
,
1043 RESOURCES_ANDROID_NAMESPACE
, "scheme",
1044 schemeIdentChars
, true) != ATTR_OKAY
) {
1051 if (table
.validateLocalizations()) {
1056 return UNKNOWN_ERROR
;
1059 // Generate final compiled manifest file.
1060 manifestFile
->clearData();
1061 sp
<XMLNode
> manifestTree
= XMLNode::parse(manifestFile
);
1062 if (manifestTree
== NULL
) {
1063 return UNKNOWN_ERROR
;
1065 err
= massageManifest(bundle
, manifestTree
);
1066 if (err
< NO_ERROR
) {
1069 err
= compileXmlFile(assets
, manifestTree
, manifestFile
, &table
);
1070 if (err
< NO_ERROR
) {
1075 //printXMLBlock(&block);
1077 // --------------------------------------------------------------
1078 // Generate the final resource table.
1079 // Re-flatten because we may have added new resource IDs
1080 // --------------------------------------------------------------
1082 if (table
.hasResources()) {
1083 sp
<AaptSymbols
> symbols
= assets
->getSymbolsFor(String8("R"));
1084 err
= table
.addSymbols(symbols
);
1085 if (err
< NO_ERROR
) {
1089 sp
<AaptFile
> resFile(getResourceFile(assets
));
1090 if (resFile
== NULL
) {
1091 fprintf(stderr
, "Error: unable to generate entry for resource data\n");
1092 return UNKNOWN_ERROR
;
1095 err
= table
.flatten(bundle
, resFile
);
1096 if (err
< NO_ERROR
) {
1100 if (bundle
->getPublicOutputFile()) {
1101 FILE* fp
= fopen(bundle
->getPublicOutputFile(), "w+");
1103 fprintf(stderr
, "ERROR: Unable to open public definitions output file %s: %s\n",
1104 (const char*)bundle
->getPublicOutputFile(), strerror(errno
));
1105 return UNKNOWN_ERROR
;
1107 if (bundle
->getVerbose()) {
1108 printf(" Writing public definitions to %s.\n", bundle
->getPublicOutputFile());
1110 table
.writePublicDefinitions(String16(assets
->getPackage()), fp
);
1116 rt
.add(resFile
->getData(), resFile
->getSize(), NULL
);
1117 printf("Generated resources:\n");
1121 // These resources are now considered to be a part of the included
1122 // resources, for others to reference.
1123 err
= assets
->addIncludedResources(resFile
);
1124 if (err
< NO_ERROR
) {
1125 fprintf(stderr
, "ERROR: Unable to parse generated resources, aborting.\n");
1132 static const char* getIndentSpace(int indent
)
1134 static const char whitespace
[] =
1137 return whitespace
+ sizeof(whitespace
) - 1 - indent
*4;
1140 static status_t
fixupSymbol(String16
* inoutSymbol
)
1142 inoutSymbol
->replaceAll('.', '_');
1143 inoutSymbol
->replaceAll(':', '_');
1147 static String16
getAttributeComment(const sp
<AaptAssets
>& assets
,
1148 const String8
& name
,
1149 String16
* outTypeComment
= NULL
)
1151 sp
<AaptSymbols
> asym
= assets
->getSymbolsFor(String8("R"));
1153 //printf("Got R symbols!\n");
1154 asym
= asym
->getNestedSymbols().valueFor(String8("attr"));
1156 //printf("Got attrs symbols! comment %s=%s\n",
1157 // name.string(), String8(asym->getComment(name)).string());
1158 if (outTypeComment
!= NULL
) {
1159 *outTypeComment
= asym
->getTypeComment(name
);
1161 return asym
->getComment(name
);
1167 static status_t
writeLayoutClasses(
1168 FILE* fp
, const sp
<AaptAssets
>& assets
,
1169 const sp
<AaptSymbols
>& symbols
, int indent
, bool includePrivate
)
1171 const char* indentStr
= getIndentSpace(indent
);
1172 if (!includePrivate
) {
1173 fprintf(fp
, "%s/** @doconly */\n", indentStr
);
1175 fprintf(fp
, "%spublic static final class styleable {\n", indentStr
);
1178 String16
attr16("attr");
1179 String16
package16(assets
->getPackage());
1181 indentStr
= getIndentSpace(indent
);
1182 bool hasErrors
= false;
1185 size_t N
= symbols
->getNestedSymbols().size();
1186 for (i
=0; i
<N
; i
++) {
1187 sp
<AaptSymbols
> nsymbols
= symbols
->getNestedSymbols().valueAt(i
);
1188 String16
nclassName16(symbols
->getNestedSymbols().keyAt(i
));
1189 String8
realClassName(nclassName16
);
1190 if (fixupSymbol(&nclassName16
) != NO_ERROR
) {
1193 String8
nclassName(nclassName16
);
1195 SortedVector
<uint32_t> idents
;
1196 Vector
<uint32_t> origOrder
;
1197 Vector
<bool> publicFlags
;
1200 size_t NA
= nsymbols
->getSymbols().size();
1201 for (a
=0; a
<NA
; a
++) {
1202 const AaptSymbolEntry
& sym(nsymbols
->getSymbols().valueAt(a
));
1203 int32_t code
= sym
.typeCode
== AaptSymbolEntry::TYPE_INT32
1205 bool isPublic
= true;
1207 String16
name16(sym
.name
);
1208 uint32_t typeSpecFlags
;
1209 code
= assets
->getIncludedResources().identifierForName(
1210 name16
.string(), name16
.size(),
1211 attr16
.string(), attr16
.size(),
1212 package16
.string(), package16
.size(), &typeSpecFlags
);
1214 fprintf(stderr
, "ERROR: In <declare-styleable> %s, unable to find attribute %s\n",
1215 nclassName
.string(), sym
.name
.string());
1218 isPublic
= (typeSpecFlags
&ResTable_typeSpec::SPEC_PUBLIC
) != 0;
1221 origOrder
.add(code
);
1222 publicFlags
.add(isPublic
);
1227 String16 comment
= symbols
->getComment(realClassName
);
1228 fprintf(fp
, "%s/** ", indentStr
);
1229 if (comment
.size() > 0) {
1230 fprintf(fp
, "%s\n", String8(comment
).string());
1232 fprintf(fp
, "Attributes that can be used with a %s.\n", nclassName
.string());
1234 bool hasTable
= false;
1235 for (a
=0; a
<NA
; a
++) {
1236 ssize_t pos
= idents
.indexOf(origOrder
.itemAt(a
));
1241 "%s <p>Includes the following attributes:</p>\n"
1242 "%s <table border=\"2\" width=\"85%%\" align=\"center\" frame=\"hsides\" rules=\"all\" cellpadding=\"5\">\n"
1243 "%s <colgroup align=\"left\" />\n"
1244 "%s <colgroup align=\"left\" />\n"
1245 "%s <tr><th>Attribute<th>Summary</tr>\n",
1252 const AaptSymbolEntry
& sym
= nsymbols
->getSymbols().valueAt(a
);
1253 if (!publicFlags
.itemAt(a
) && !includePrivate
) {
1256 String8
name8(sym
.name
);
1257 String16
comment(sym
.comment
);
1258 if (comment
.size() <= 0) {
1259 comment
= getAttributeComment(assets
, name8
);
1261 if (comment
.size() > 0) {
1262 const char16_t* p
= comment
.string();
1263 while (*p
!= 0 && *p
!= '.') {
1265 while (*p
!= 0 && *p
!= '}') {
1275 comment
= String16(comment
.string(), p
-comment
.string());
1277 String16
name(name8
);
1279 fprintf(fp
, "%s <tr><th><code>{@link #%s_%s %s:%s}</code><td>%s</tr>\n",
1280 indentStr
, nclassName
.string(),
1281 String8(name
).string(),
1282 assets
->getPackage().string(),
1283 String8(name
).string(),
1284 String8(comment
).string());
1288 fprintf(fp
, "%s </table>\n", indentStr
);
1290 for (a
=0; a
<NA
; a
++) {
1291 ssize_t pos
= idents
.indexOf(origOrder
.itemAt(a
));
1293 const AaptSymbolEntry
& sym
= nsymbols
->getSymbols().valueAt(a
);
1294 if (!publicFlags
.itemAt(a
) && !includePrivate
) {
1297 String16
name(sym
.name
);
1299 fprintf(fp
, "%s @see #%s_%s\n",
1300 indentStr
, nclassName
.string(),
1301 String8(name
).string());
1304 fprintf(fp
, "%s */\n", getIndentSpace(indent
));
1307 "%spublic static final int[] %s = {\n"
1309 indentStr
, nclassName
.string(),
1310 getIndentSpace(indent
+1));
1312 for (a
=0; a
<NA
; a
++) {
1315 fprintf(fp
, ",\n%s", getIndentSpace(indent
+1));
1320 fprintf(fp
, "0x%08x", idents
[a
]);
1323 fprintf(fp
, "\n%s};\n", indentStr
);
1325 for (a
=0; a
<NA
; a
++) {
1326 ssize_t pos
= idents
.indexOf(origOrder
.itemAt(a
));
1328 const AaptSymbolEntry
& sym
= nsymbols
->getSymbols().valueAt(a
);
1329 if (!publicFlags
.itemAt(a
) && !includePrivate
) {
1332 String8
name8(sym
.name
);
1333 String16
comment(sym
.comment
);
1334 String16 typeComment
;
1335 if (comment
.size() <= 0) {
1336 comment
= getAttributeComment(assets
, name8
, &typeComment
);
1338 getAttributeComment(assets
, name8
, &typeComment
);
1340 String16
name(name8
);
1341 if (fixupSymbol(&name
) != NO_ERROR
) {
1345 uint32_t typeSpecFlags
= 0;
1346 String16
name16(sym
.name
);
1347 assets
->getIncludedResources().identifierForName(
1348 name16
.string(), name16
.size(),
1349 attr16
.string(), attr16
.size(),
1350 package16
.string(), package16
.size(), &typeSpecFlags
);
1351 //printf("%s:%s/%s: 0x%08x\n", String8(package16).string(),
1352 // String8(attr16).string(), String8(name16).string(), typeSpecFlags);
1353 const bool pub
= (typeSpecFlags
&ResTable_typeSpec::SPEC_PUBLIC
) != 0;
1355 fprintf(fp
, "%s/**\n", indentStr
);
1356 if (comment
.size() > 0) {
1357 fprintf(fp
, "%s <p>\n%s @attr description\n", indentStr
, indentStr
);
1358 fprintf(fp
, "%s %s\n", indentStr
, String8(comment
).string());
1361 "%s <p>This symbol is the offset where the {@link %s.R.attr#%s}\n"
1362 "%s attribute's value can be found in the {@link #%s} array.\n",
1364 pub
? assets
->getPackage().string()
1365 : assets
->getSymbolsPrivatePackage().string(),
1366 String8(name
).string(),
1367 indentStr
, nclassName
.string());
1369 if (typeComment
.size() > 0) {
1370 fprintf(fp
, "\n\n%s %s\n", indentStr
, String8(typeComment
).string());
1372 if (comment
.size() > 0) {
1375 "%s <p>This corresponds to the global attribute"
1376 "%s resource symbol {@link %s.R.attr#%s}.\n",
1377 indentStr
, indentStr
,
1378 assets
->getPackage().string(),
1379 String8(name
).string());
1382 "%s <p>This is a private symbol.\n", indentStr
);
1385 fprintf(fp
, "%s @attr name %s:%s\n", indentStr
,
1386 "android", String8(name
).string());
1387 fprintf(fp
, "%s*/\n", indentStr
);
1389 "%spublic static final int %s_%s = %d;\n",
1390 indentStr
, nclassName
.string(),
1391 String8(name
).string(), (int)pos
);
1397 fprintf(fp
, "%s};\n", getIndentSpace(indent
));
1398 return hasErrors
? UNKNOWN_ERROR
: NO_ERROR
;
1401 static status_t
writeSymbolClass(
1402 FILE* fp
, const sp
<AaptAssets
>& assets
, bool includePrivate
,
1403 const sp
<AaptSymbols
>& symbols
, const String8
& className
, int indent
)
1405 fprintf(fp
, "%spublic %sfinal class %s {\n",
1406 getIndentSpace(indent
),
1407 indent
!= 0 ? "static " : "", className
.string());
1411 status_t err
= NO_ERROR
;
1413 size_t N
= symbols
->getSymbols().size();
1414 for (i
=0; i
<N
; i
++) {
1415 const AaptSymbolEntry
& sym
= symbols
->getSymbols().valueAt(i
);
1416 if (sym
.typeCode
!= AaptSymbolEntry::TYPE_INT32
) {
1419 if (!includePrivate
&& !sym
.isPublic
) {
1422 String16
name(sym
.name
);
1423 String8
realName(name
);
1424 if (fixupSymbol(&name
) != NO_ERROR
) {
1425 return UNKNOWN_ERROR
;
1427 String16
comment(sym
.comment
);
1428 bool haveComment
= false;
1429 if (comment
.size() > 0) {
1433 getIndentSpace(indent
), String8(comment
).string());
1434 } else if (sym
.isPublic
&& !includePrivate
) {
1435 sym
.sourcePos
.warning("No comment for public symbol %s:%s/%s",
1436 assets
->getPackage().string(), className
.string(),
1437 String8(sym
.name
).string());
1439 String16
typeComment(sym
.typeComment
);
1440 if (typeComment
.size() > 0) {
1445 getIndentSpace(indent
), String8(typeComment
).string());
1449 getIndentSpace(indent
), String8(typeComment
).string());
1453 fprintf(fp
,"%s */\n", getIndentSpace(indent
));
1455 fprintf(fp
, "%spublic static final int %s=0x%08x;\n",
1456 getIndentSpace(indent
),
1457 String8(name
).string(), (int)sym
.int32Val
);
1460 for (i
=0; i
<N
; i
++) {
1461 const AaptSymbolEntry
& sym
= symbols
->getSymbols().valueAt(i
);
1462 if (sym
.typeCode
!= AaptSymbolEntry::TYPE_STRING
) {
1465 if (!includePrivate
&& !sym
.isPublic
) {
1468 String16
name(sym
.name
);
1469 if (fixupSymbol(&name
) != NO_ERROR
) {
1470 return UNKNOWN_ERROR
;
1472 String16
comment(sym
.comment
);
1473 if (comment
.size() > 0) {
1477 getIndentSpace(indent
), String8(comment
).string(),
1478 getIndentSpace(indent
));
1479 } else if (sym
.isPublic
&& !includePrivate
) {
1480 sym
.sourcePos
.warning("No comment for public symbol %s:%s/%s",
1481 assets
->getPackage().string(), className
.string(),
1482 String8(sym
.name
).string());
1484 fprintf(fp
, "%spublic static final String %s=\"%s\";\n",
1485 getIndentSpace(indent
),
1486 String8(name
).string(), sym
.stringVal
.string());
1489 sp
<AaptSymbols
> styleableSymbols
;
1491 N
= symbols
->getNestedSymbols().size();
1492 for (i
=0; i
<N
; i
++) {
1493 sp
<AaptSymbols
> nsymbols
= symbols
->getNestedSymbols().valueAt(i
);
1494 String8
nclassName(symbols
->getNestedSymbols().keyAt(i
));
1495 if (nclassName
== "styleable") {
1496 styleableSymbols
= nsymbols
;
1498 err
= writeSymbolClass(fp
, assets
, includePrivate
, nsymbols
, nclassName
, indent
);
1500 if (err
!= NO_ERROR
) {
1505 if (styleableSymbols
!= NULL
) {
1506 err
= writeLayoutClasses(fp
, assets
, styleableSymbols
, indent
, includePrivate
);
1507 if (err
!= NO_ERROR
) {
1513 fprintf(fp
, "%s}\n", getIndentSpace(indent
));
1517 status_t
writeResourceSymbols(Bundle
* bundle
, const sp
<AaptAssets
>& assets
,
1518 const String8
& package
, bool includePrivate
)
1520 if (!bundle
->getRClassDir()) {
1524 const size_t N
= assets
->getSymbols().size();
1525 for (size_t i
=0; i
<N
; i
++) {
1526 sp
<AaptSymbols
> symbols
= assets
->getSymbols().valueAt(i
);
1527 String8
className(assets
->getSymbols().keyAt(i
));
1528 String8
dest(bundle
->getRClassDir());
1529 if (bundle
->getMakePackageDirs()) {
1530 String8
pkg(package
);
1531 const char* last
= pkg
.string();
1532 const char* s
= last
-1;
1535 if (s
> last
&& (*s
== '.' || *s
== 0)) {
1536 String8
part(last
, s
-last
);
1537 dest
.appendPath(part
);
1538 #ifdef HAVE_MS_C_RUNTIME
1539 _mkdir(dest
.string());
1541 mkdir(dest
.string(), S_IRUSR
|S_IWUSR
|S_IXUSR
|S_IRGRP
|S_IXGRP
);
1547 dest
.appendPath(className
);
1548 dest
.append(".java");
1549 FILE* fp
= fopen(dest
.string(), "w+");
1551 fprintf(stderr
, "ERROR: Unable to open class file %s: %s\n",
1552 dest
.string(), strerror(errno
));
1553 return UNKNOWN_ERROR
;
1555 if (bundle
->getVerbose()) {
1556 printf(" Writing symbols for class %s.\n", className
.string());
1560 "/* AUTO-GENERATED FILE. DO NOT MODIFY.\n"
1562 " * This class was automatically generated by the\n"
1563 " * aapt tool from the resource data it found. It\n"
1564 " * should not be modified by hand.\n"
1567 "package %s;\n\n", package
.string());
1569 status_t err
= writeSymbolClass(fp
, assets
, includePrivate
, symbols
, className
, 0);
1570 if (err
!= NO_ERROR
) {