Chromium Code Reviews| Index: base/android/jni_generator/jni_generator.py |
| diff --git a/base/android/jni_generator/jni_generator.py b/base/android/jni_generator/jni_generator.py |
| index 0173a2c1172e0bf21de939fb3cd0e6fcae86e311..8632b0d32566e38a382d39231b66d43d34a1e337 100755 |
| --- a/base/android/jni_generator/jni_generator.py |
| +++ b/base/android/jni_generator/jni_generator.py |
| @@ -632,10 +632,9 @@ class JNIFromJavaP(object): |
| self.constant_fields.append( |
| ConstantField(name=match.group('name'), |
| value=value.group('value'))) |
| - |
| self.inl_header_file_generator = InlHeaderFileGenerator( |
| - self.namespace, self.fully_qualified_class, [], |
| - self.called_by_natives, self.constant_fields, options) |
| + self.namespace, self.fully_qualified_class, [], self.called_by_natives, |
| + self.constant_fields, options) |
| def GetContent(self): |
| return self.inl_header_file_generator.GetContent() |
| @@ -669,12 +668,13 @@ class JNIFromJavaSource(object): |
| jni_namespace = ExtractJNINamespace(contents) or options.namespace |
| natives = ExtractNatives(contents, options.ptr_type) |
| called_by_natives = ExtractCalledByNatives(contents) |
| + maindex = JNIFromJavaSource.InMainDex(contents) |
| if len(natives) == 0 and len(called_by_natives) == 0: |
| raise SyntaxError('Unable to find any JNI methods for %s.' % |
| fully_qualified_class) |
| inl_header_file_generator = InlHeaderFileGenerator( |
| - jni_namespace, fully_qualified_class, natives, called_by_natives, |
| - [], options) |
| + jni_namespace, fully_qualified_class, natives, called_by_natives, [], |
| + options, maindex) |
| self.content = inl_header_file_generator.GetContent() |
| @classmethod |
| @@ -705,12 +705,16 @@ class JNIFromJavaSource(object): |
| contents) |
| return JNIFromJavaSource(contents, fully_qualified_class, options) |
| + @staticmethod |
| + def InMainDex(contents): |
|
agrieve
2016/12/07 20:46:19
nit: odd name. I'd probably just inline the functi
estevenson
2016/12/07 23:00:04
Done.
|
| + return '@MainDex' in contents |
| + |
| class InlHeaderFileGenerator(object): |
| """Generates an inline header file for JNI integration.""" |
| def __init__(self, namespace, fully_qualified_class, natives, |
| - called_by_natives, constant_fields, options): |
| + called_by_natives, constant_fields, options, maindex=False): |
| self.namespace = namespace |
| self.fully_qualified_class = fully_qualified_class |
| self.class_name = self.fully_qualified_class.split('/')[-1] |
| @@ -718,6 +722,7 @@ class InlHeaderFileGenerator(object): |
| self.called_by_natives = called_by_natives |
| self.header_guard = fully_qualified_class.replace('/', '_') + '_JNI' |
| self.constant_fields = constant_fields |
| + self.maindex = maindex |
| self.options = options |
| @@ -742,6 +747,7 @@ class InlHeaderFileGenerator(object): |
| ${INCLUDES} |
| #include "base/android/jni_int_wrapper.h" |
| +#include "base/android/jni_utils.h" |
| // Step 1: forward declarations. |
| namespace { |
| @@ -864,6 +870,14 @@ ${NATIVES} |
| early_exit = """\ |
| if (base::android::IsManualJniRegistrationDisabled()) return true; |
| """ |
| + if not self.maindex: |
| + early_exit += """\ |
| + if (base::android::IsMultidexEnabled(env) && |
| + base::android::GetLibraryProcessType(env) != |
| + base::android::PROCESS_BROWSER) { |
| + return true; |
| + } |
| +""" |
| values = {'REGISTER_NATIVES_SIGNATURE': signature, |
| 'EARLY_EXIT': early_exit, |