Make library basename generation more robust.

The aim is to turn (e.g.) libmonochrome.so into monochrome, but in the
secondary abi case the path passed has a directory component, which
means that an incorrect library name is generated.

This CL changes the implementation to be more robust to directory
components and the length of the extension.

(cherry picked from commit 377bdba34eada62097786c161428baed14f8fa18)

Bug: 988041
Change-Id: Idfca8a38bbb4fdd2a136a64f14c9f00b675776c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1720876
Reviewed-by: Andrew Grieve <[email protected]>
Commit-Queue: Tobias Sargeant <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#681853}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1746463
Reviewed-by: Ben Mason <[email protected]>
Cr-Commit-Position: refs/branch-heads/3865@{#300}
Cr-Branched-From: 0cdcc6158160790658d1f033d3db873603250124-refs/heads/master@{#681094}
diff --git a/build/android/gyp/write_native_libraries_java.py b/build/android/gyp/write_native_libraries_java.py
index ad29811f..c7ad066 100755
--- a/build/android/gyp/write_native_libraries_java.py
+++ b/build/android/gyp/write_native_libraries_java.py
@@ -70,9 +70,14 @@
           continue
         lib_paths.append(line)
 
+  def LibBasename(path):
+    filename = os.path.split(path)[1]
+    base = os.path.splitext(filename)[0]
+    return base[3:]  # remove lib prefix
+
   # Convert to "base" library names: e.g. libfoo.so -> foo.
   native_libraries_list = (
-      '{%s}' % ','.join(['"%s"' % s[3:-3] for s in lib_paths]))
+      '{%s}' % ','.join(['"%s"' % LibBasename(s) for s in lib_paths]))
 
   def bool_str(value):
     if value: