]> git.saurik.com Git - android/aapt.git/commitdiff
am b4f41119: am a1d08886: Merge "Only output proguard keep for nonempty attribute...
authorYing Wang <wangying@google.com>
Wed, 13 Jan 2010 00:37:31 +0000 (16:37 -0800)
committerAndroid Git Automerger <android-git-automerger@android.com>
Wed, 13 Jan 2010 00:37:31 +0000 (16:37 -0800)
Merge commit 'b4f41119044e5ec7f7b76ed4ac02b5cfbaeb474d'

* commit 'b4f41119044e5ec7f7b76ed4ac02b5cfbaeb474d':
  Only output proguard keep for nonempty attribute name in the AndroidManifest.xml.

1  2 
Resource.cpp

diff --combined Resource.cpp
index de6ff14af41a45a1e9ed968a9ae4f47db45f1f82,02b46aa50852c3c9197d4a76e0e006f79c0a474d..ae8f2423e91fd6b6a8b9666921f852e7c5969a3c
@@@ -171,8 -171,7 +171,8 @@@ static sp<AaptFile> getResourceFile(con
                              NULL, String8());
  }
  
 -static status_t parsePackage(const sp<AaptAssets>& assets, const sp<AaptGroup>& grp)
 +static status_t parsePackage(Bundle* bundle, const sp<AaptAssets>& assets,
 +    const sp<AaptGroup>& grp)
  {
      if (grp->getFiles().size() != 1) {
          fprintf(stderr, "warning: Multiple AndroidManifest.xml files found, using %s\n",
  
      assets->setPackage(String8(block.getAttributeStringValue(nameIndex, &len)));
  
 +    String16 uses_sdk16("uses-sdk");
 +    while ((code=block.next()) != ResXMLTree::END_DOCUMENT
 +           && code != ResXMLTree::BAD_DOCUMENT) {
 +        if (code == ResXMLTree::START_TAG) {
 +            if (strcmp16(block.getElementName(&len), uses_sdk16.string()) == 0) {
 +                ssize_t minSdkIndex = block.indexOfAttribute("android",
 +                                                             "minSdkVersion");
 +                if (minSdkIndex >= 0) {
 +                    String8 minSdkString = String8(
 +                        block.getAttributeStringValue(minSdkIndex, &len));
 +                  bundle->setMinSdkVersion(minSdkString.string());
 +                }
 +            }
 +        }
 +    }
 +
      return NO_ERROR;
  }
  
@@@ -614,7 -597,7 +614,7 @@@ status_t buildResources(Bundle* bundle
          return UNKNOWN_ERROR;
      }
  
 -    status_t err = parsePackage(assets, androidManifestFile);
 +    status_t err = parsePackage(bundle, assets, androidManifestFile);
      if (err != NO_ERROR) {
          return err;
      }
  
      NOISY(printf("Found %d included resource packages\n", (int)table.size()));
  
 +    // Standard flags for compiled XML and optional UTF-8 encoding
 +    int xmlFlags = XML_COMPILE_STANDARD_RESOURCE;
 +    if (bundle->getUTF8()) {
 +        xmlFlags |= XML_COMPILE_UTF8;
 +    }
 +
      // --------------------------------------------------------------
      // First, gather all resource information.
      // --------------------------------------------------------------
          ResourceDirIterator it(layouts, String8("layout"));
          while ((err=it.next()) == NO_ERROR) {
              String8 src = it.getFile()->getPrintableSource();
 -            err = compileXmlFile(assets, it.getFile(), &table);
 +            err = compileXmlFile(assets, it.getFile(), &table, xmlFlags);
              if (err == NO_ERROR) {
                  ResXMLTree block;
                  block.setTo(it.getFile()->getData(), it.getFile()->getSize(), true);
      if (anims != NULL) {
          ResourceDirIterator it(anims, String8("anim"));
          while ((err=it.next()) == NO_ERROR) {
 -            err = compileXmlFile(assets, it.getFile(), &table);
 +            err = compileXmlFile(assets, it.getFile(), &table, xmlFlags);
              if (err != NO_ERROR) {
                  hasErrors = true;
              }
      if (xmls != NULL) {
          ResourceDirIterator it(xmls, String8("xml"));
          while ((err=it.next()) == NO_ERROR) {
 -            err = compileXmlFile(assets, it.getFile(), &table);
 +            err = compileXmlFile(assets, it.getFile(), &table, xmlFlags);
              if (err != NO_ERROR) {
                  hasErrors = true;
              }
      if (colors != NULL) {
          ResourceDirIterator it(colors, String8("color"));
          while ((err=it.next()) == NO_ERROR) {
 -          err = compileXmlFile(assets, it.getFile(), &table);
 +          err = compileXmlFile(assets, it.getFile(), &table, xmlFlags);
              if (err != NO_ERROR) {
                  hasErrors = true;
              }
          ResourceDirIterator it(menus, String8("menu"));
          while ((err=it.next()) == NO_ERROR) {
              String8 src = it.getFile()->getPrintableSource();
 -            err = compileXmlFile(assets, it.getFile(), &table);
 +            err = compileXmlFile(assets, it.getFile(), &table, xmlFlags);
              if (err != NO_ERROR) {
                  hasErrors = true;
              }
@@@ -1768,31 -1745,33 +1768,33 @@@ writeProguardForAndroidManifest(Proguar
                      fprintf(stderr, "ERROR: %s\n", error.string());
                      return -1;
                  }
-                 // asdf     --> package.asdf
-                 // .asdf  .a.b  --> package.asdf package.a.b
-                 // asdf.adsf --> asdf.asdf
-                 String8 rule("-keep class ");
-                 const char* p = name.string();
-                 const char* q = strchr(p, '.');
-                 if (p == q) {
-                     rule += pkg;
-                     rule += name;
-                 } else if (q == NULL) {
-                     rule += pkg;
-                     rule += ".";
-                     rule += name;
-                 } else {
-                     rule += name;
-                 }
+                 if (name.length() > 0) {
+                     // asdf     --> package.asdf
+                     // .asdf  .a.b  --> package.asdf package.a.b
+                     // asdf.adsf --> asdf.asdf
+                     String8 rule("-keep class ");
+                     const char* p = name.string();
+                     const char* q = strchr(p, '.');
+                     if (p == q) {
+                         rule += pkg;
+                         rule += name;
+                     } else if (q == NULL) {
+                         rule += pkg;
+                         rule += ".";
+                         rule += name;
+                     } else {
+                         rule += name;
+                     }
  
-                 String8 location = tag;
-                 location += " ";
-                 location += assFile->getSourceFile();
-                 char lineno[20];
-                 sprintf(lineno, ":%d", tree.getLineNumber());
-                 location += lineno;
+                     String8 location = tag;
+                     location += " ";
+                     location += assFile->getSourceFile();
+                     char lineno[20];
+                     sprintf(lineno, ":%d", tree.getLineNumber());
+                     location += lineno;
  
-                 keep->add(rule, location);
+                     keep->add(rule, location);
+                 }
              }
          }
      }