diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-04-29 20:38:15 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-04-29 20:38:20 +0000 |
commit | 53c9898e7952b966b61b0c1d74ee1186a8057a47 (patch) | |
tree | 4dda977e8de7ca5904a19d172ac9b242ce3e95b5 /tools/aapt2/java/JavaClassGenerator.cpp | |
parent | 5bb8294f926dcaf4a7288ba4457d84d57bb4ab53 (diff) | |
parent | 360182156a8e188534620de1e804993a6458470d (diff) |
Merge changes I446fb6ab,Ife3bbd29 into oc-dev
* changes:
Valid resource IDs may be negative
AAPT2: Workaround for findViewById with package ID > 0x7f
Diffstat (limited to 'tools/aapt2/java/JavaClassGenerator.cpp')
-rw-r--r-- | tools/aapt2/java/JavaClassGenerator.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index a8226c0a9082..2a23aa9e5372 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -31,6 +31,7 @@ #include "Resource.h" #include "ResourceTable.h" #include "ResourceValues.h" +#include "SdkConstants.h" #include "ValueVisitor.h" #include "java/AnnotationProcessor.h" #include "java/ClassDefinition.h" @@ -430,9 +431,15 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso const ResourceEntry& entry, ClassDefinition* out_class_def, MethodDefinition* out_rewrite_method, std::ostream* out_r_txt) { + ResourceId real_id = id; + if (context_->GetMinSdkVersion() < SDK_O && name.type == ResourceType::kId && + id.package_id() > kAppPackageId) { + real_id = ResourceId(kAppPackageId, id.package_id(), id.entry_id()); + } + const std::string field_name = TransformToFieldName(name.entry); std::unique_ptr<ResourceMember> resource_member = - util::make_unique<ResourceMember>(field_name, id); + util::make_unique<ResourceMember>(field_name, real_id); // Build the comments and annotations for this entry. AnnotationProcessor* processor = resource_member->GetCommentBuilder(); @@ -458,7 +465,7 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso out_class_def->AddMember(std::move(resource_member)); if (out_r_txt != nullptr) { - *out_r_txt << "int " << name.type << " " << field_name << " " << id << "\n"; + *out_r_txt << "int " << name.type << " " << field_name << " " << real_id << "\n"; } if (out_rewrite_method != nullptr) { |