]> git.saurik.com Git - android/aapt.git/commitdiff
am 3c05f1fb: am b5fb50a1: Merge "Add instrumentation as a source tag for proguard...
authorYing Wang <wangying@google.com>
Fri, 22 Jan 2010 17:45:31 +0000 (09:45 -0800)
committerAndroid Git Automerger <android-git-automerger@android.com>
Fri, 22 Jan 2010 17:45:31 +0000 (09:45 -0800)
Merge commit '3c05f1fbac2ce35483f61dbd5d5bfb6341da6d9c'

* commit '3c05f1fbac2ce35483f61dbd5d5bfb6341da6d9c':
  Add instrumentation as a source tag for proguard keep options.

1  2 
Resource.cpp

diff --combined Resource.cpp
index ae8f2423e91fd6b6a8b9666921f852e7c5969a3c,e2aeddfebfa5e6c6948c2d2861344a1da43b1590..c530dd4cc93c23ce759f9d3427f9f9c6371d596e
@@@ -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;
              }
@@@ -1750,51 -1727,59 +1750,59 @@@ writeProguardForAndroidManifest(Proguar
          depth++;
          String8 tag(tree.getElementName(&len));
          // printf("Depth %d tag %s\n", depth, tag.string());
+         bool keepTag = false;
          if (depth == 1) {
              if (tag != "manifest") {
                  fprintf(stderr, "ERROR: manifest does not start with <manifest> tag\n");
                  return -1;
              }
              pkg = getAttribute(tree, NULL, "package", NULL);
-         } else if (depth == 2 && tag == "application") {
-             inApplication = true;
-         }
-         if (inApplication) {
-             if (tag == "application" || tag == "activity" || tag == "service" || tag == "receiver"
-                     || tag == "provider") {
-                 String8 name = getAttribute(tree, "http://schemas.android.com/apk/res/android",
-                         "name", &error);
-                 if (error != "") {
-                     fprintf(stderr, "ERROR: %s\n", error.string());
-                     return -1;
+         } else if (depth == 2) {
+             if (tag == "application") {
+                 inApplication = true;
+                 keepTag = true;
+             } else if (tag == "instrumentation") {
+                 keepTag = true;
+             }
+         }
+         if (!keepTag && inApplication && depth == 3) {
+             if (tag == "activity" || tag == "service" || tag == "receiver" || tag == "provider") {
+                 keepTag = true;
+             }
+         }
+         if (keepTag) {
+             String8 name = getAttribute(tree, "http://schemas.android.com/apk/res/android",
+                     "name", &error);
+             if (error != "") {
+                 fprintf(stderr, "ERROR: %s\n", error.string());
+                 return -1;
+             }
+             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;
                  }
-                 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);
              }
          }
      }