我正在尝试构建AOSP拉丁IME(源代码:https://android.googlesource.com/platform/packages/inputmethods/LatinIME/+/master),而无需下载整个AOSP源代码。理想情况下,我想将该项目构建为Gradle项目,以便可以轻松地将其与现有的Android应用程序集成。
我已经取得了一些进步
1]在Android Studio中创建一个空白项目
2]复制粘贴“ java”和“ java-overridable”文件夹,并将“ res”文件夹的内容复制粘贴到我的项目中
但是,在编译项目时,由于以下错误,打开键盘时会崩溃:
无法加载本地库jni_latinime
此错误是有道理的,因为我尚未构建并包括键盘起作用所需的C ++本机库(可在此处找到:https://android.googlesource.com/platform/packages/inputmethods/LatinIME/+/master/native/jni/)。
如何构建在以上链接中找到的本机库并将其包含在我的Gradle项目中?有什么方法可以编译这些C ++文件,而无需下载整个AOSP源代码?
该项目带有一个“ Android.bp”文件,该文件似乎指定了如何编译C ++文件。不幸的是,我不知道如何使用Soong构建系统。 https://android.googlesource.com/platform/packages/inputmethods/LatinIME/+/master/native/jni/Android.bp
答案 0 :(得分:0)
根据我的说法,您不能在AOSP tree.so之外使用soong构建系统,因此要使用Android.bp编译本机文件,您将必须在AOSP tree中进行构建。
但是您可以只签到一个稳定的分支,而不使用主分支代码。
Soong is the replacement for the old Android make-based build system.
It replaces Android.mk files with Android.bp files,
which are JSON-like simple declarative descriptions of modules to build.
This Makefile-based system is in the process of being replaced with Soong,
a new build system written in Go.
During the transition, all of these makefiles are read by Kati, and generate a ninja file instead of being executed directly.
That's combined with a ninja file read by Soong so that the build graph of the two systems can be combined and run as one.
如果您将代码签出到稳定的分支(如pie-release或oreo-r6-release),则将获得没有此soong构建系统的源代码,并且将拥有旧的构建系统文件,例如Android.mk
但是,如果您仍然想要最新的源代码,则可以阅读此Android.bp文件并创建模块本机模块,然后使用CMake进行构建。
您必须将此Android.bp文件转换为CMakeLists.txt,才能使用cmake进行构建。 我认为这不会很困难
Main segement that you want to build is : libjni_latinime
cc_library
{
name: "libjni_latinime",
host_supported: true,
product_specific: true,
sdk_version: "14",
cflags: [
"-Werror",
"-Wall",
"-Wextra",
"-Weffc++",
"-Wformat=2",
"-Wcast-qual",
"-Wcast-align",
"-Wwrite-strings",
"-Wfloat-equal",
"-Wpointer-arith",
"-Winit-self",
"-Wredundant-decls",
"-Woverloaded-virtual",
"-Wsign-promo",
"-Wno-system-headers",
// To suppress compiler warnings for unused variables/functions used for debug features etc.
"-Wno-unused-parameter",
"-Wno-unused-function",
],
local_include_dirs: ["src"],
srcs: [
"com_android_inputmethod_keyboard_ProximityInfo.cpp",
"com_android_inputmethod_latin_BinaryDictionary.cpp",
"com_android_inputmethod_latin_BinaryDictionaryUtils.cpp",
"com_android_inputmethod_latin_DicTraverseSession.cpp",
"jni_common.cpp",
":LATIN_IME_CORE_SRC_FILES",
],
target: {
android_x86: {
// HACK: -mstackrealign is required for x86 builds running on pre-KitKat devices to avoid crashes
// with SSE instructions.
cflags: ["-mstackrealign"],
},
android: {
stl: "libc++_static",
},
host: {
cflags: ["-DHOST_TOOL"],
},
}
您必须传递这些CFLAGS并包括dir,源文件列表以及从目标传递而来的android libc ++ _ static,因为其他事情对您没有用。
如果您想了解有关宋的信息:https://android.googlesource.com/platform/build/soong/
答案 1 :(得分:0)
Colin为LatinIme创建了一个不错的gradle构建。 我为毕业论文做了一个修饰的拉丁语,我真的希望当时存在这样的项目。
如果要更改应用程序包名称,则还需要相应地更改cpp文件,因为使用这些文件可以构建本机库。