NativeLibraries.template revision 645501c2ab19a559ce82a1d5a29ced159a4c30fb
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package org.chromium.base.library_loader;
6
7import org.chromium.base.annotations.SuppressFBWarnings;
8
9@SuppressFBWarnings
10public class NativeLibraries {
11    /**
12     * IMPORTANT NOTE: The variables defined here must _not_ be 'final'.
13     *
14     * The reason for this is very subtle:
15     *
16     * - This template is used to generate several distinct, but similar
17     *   files used in different contexts:
18     *
19     *   o .../gen/templates/org/chromium/base/library_loader/NativeLibraries.java
20     *
21     *     This file is used to build base.jar, which is the library
22     *     jar used by chromium projects. However, the
23     *     corresponding NativeLibraries.class file will _not_ be part
24     *     of the final base.jar.
25     *
26     *   o .../$PROJECT/native_libraries_java/NativeLibraries.java
27     *
28     *     This file is used to build an APK (e.g. $PROJECT
29     *     could be 'content_shell_apk'). Its content will depend on
30     *     this target's specific build configuration, and differ from
31     *     the source file above.
32     *
33     * - During the final link, all .jar files are linked together into
34     *   a single .dex file, and the second version of NativeLibraries.class
35     *   will be put into the final output file, and used at runtime.
36     *
37     * - If the variables were defined as 'final', their value would be
38     *   optimized out inside of 'base.jar', and could not be specialized
39     *   for every chromium program. This, however, doesn't apply to arrays of
40     *   strings, which can be defined as final.
41     *
42     * This exotic scheme is used to avoid injecting project-specific, or
43     * even build-specific, values into the base layer. E.g. this is
44     * how the component build is supported on Android without modifying
45     * the sources of each and every Chromium-based target.
46     */
47
48#if defined(ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE) && \
49    !defined(ENABLE_CHROMIUM_LINKER)
50#error "Must have ENABLE_CHROMIUM_LINKER to enable library in zip file"
51#endif
52
53    // Set to true to enable the use of the Chromium Linker.
54#if defined(ENABLE_CHROMIUM_LINKER)
55    public static boolean sUseLinker = true;
56#else
57    public static boolean sUseLinker = false;
58#endif
59
60#if defined(ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE)
61    public static boolean sUseLibraryInZipFile = true;
62#else
63    public static boolean sUseLibraryInZipFile = false;
64#endif
65
66#if defined(ENABLE_CHROMIUM_LINKER_TESTS)
67    public static boolean sEnableLinkerTests = true;
68#else
69    public static boolean sEnableLinkerTests = false;
70#endif
71
72    // This is the list of native libraries to be loaded (in the correct order)
73    // by LibraryLoader.java.  The base java library is compiled with no
74    // array defined, and then the build system creates a version of the file
75    // with the real list of libraries required (which changes based upon which
76    // .apk is being built).
77    // TODO(cjhopman): This is public since it is referenced by NativeTestActivity.java
78    // directly. The two ways of library loading should be refactored into one.
79    public static final String[] LIBRARIES =
80#if defined(NATIVE_LIBRARIES_LIST)
81      NATIVE_LIBRARIES_LIST;
82#else
83      {};
84#endif
85
86    // This is the expected version of the 'main' native library, which is the one that
87    // implements the initial set of base JNI functions including
88    // base::android::nativeGetVersionName()
89    static String sVersionNumber =
90#if defined(NATIVE_LIBRARIES_VERSION_NUMBER)
91      NATIVE_LIBRARIES_VERSION_NUMBER;
92#else
93      "";
94#endif
95}
96