Merge "Convert to Android.bp"
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..0559846
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,39 @@
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+filegroup {
+    name: "dicttool_deps",
+    srcs: [
+        "java/src/com/android/inputmethod/latin/makedict/**/*.java",
+
+        // Dependencies for Dicttool. Most of these files are needed by BinaryDictionary.java. Note that
+        // a significant part of the dependencies are mocked in the compat/ directory, with empty or
+        // nearly-empty implementations, for parts that we don't use in Dicttool.
+        "java/src/com/android/inputmethod/latin/BinaryDictionary.java",
+        "java/src/com/android/inputmethod/latin/DicTraverseSession.java",
+        "java/src/com/android/inputmethod/latin/Dictionary.java",
+        "java/src/com/android/inputmethod/latin/NgramContext.java",
+        "java/src/com/android/inputmethod/latin/SuggestedWords.java",
+        "java/src/com/android/inputmethod/latin/settings/SettingsValuesForSuggestion.java",
+        "java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java",
+        "java/src/com/android/inputmethod/latin/utils/CombinedFormatUtils.java",
+        "java/src/com/android/inputmethod/latin/utils/JniUtils.java",
+
+        "java-overridable/src/com/android/inputmethod/latin/define/DebugFlags.java",
+        "java-overridable/src/com/android/inputmethod/latin/define/DecoderSpecificConstants.java",
+
+        "tests/src/com/android/inputmethod/latin/utils/ByteArrayDictBuffer.java",
+        "tests/src/com/android/inputmethod/latin/makedict/**/*.java",
+    ],
+}
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index 17eeba8..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-# Copyright (C) 2013 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-subdirs := common native java tests tools
-include $(call all-named-subdir-makefiles, $(subdirs))
diff --git a/common/Android.bp b/common/Android.bp
new file mode 100644
index 0000000..925eef7
--- /dev/null
+++ b/common/Android.bp
@@ -0,0 +1,21 @@
+// Copyright (C) 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+java_library {
+    name: "latinime-common",
+    host_supported: true,
+    srcs: ["src/**/*.java"],
+    static_libs: ["jsr305"],
+    sdk_version: "21",
+}
diff --git a/common/Android.mk b/common/Android.mk
deleted file mode 100644
index 132a223..0000000
--- a/common/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-LOCAL_MODULE := latinime-common
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_STATIC_JAVA_LIBRARIES := jsr305
-LOCAL_SDK_VERSION := 21
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-# Also build a host side library
-include $(CLEAR_VARS)
-LOCAL_MODULE := latinime-common-host
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_STATIC_JAVA_LIBRARIES := jsr305lib
-include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/java-overridable/Android.bp b/java-overridable/Android.bp
new file mode 100644
index 0000000..88de244
--- /dev/null
+++ b/java-overridable/Android.bp
@@ -0,0 +1,18 @@
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+filegroup {
+    name: "LatinIME_java-overridable",
+    srcs: ["src/**/*.java"],
+}
diff --git a/java/Android.bp b/java/Android.bp
new file mode 100644
index 0000000..8681c84
--- /dev/null
+++ b/java/Android.bp
@@ -0,0 +1,46 @@
+// Copyright (C) 2011 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+android_app {
+    name: "LatinIME",
+
+    srcs: [
+        "src/**/*.java",
+        ":LatinIME_java-overridable",
+    ],
+
+    certificate: "shared",
+
+    jni_libs: ["libjni_latinime"],
+
+    static_libs: [
+        "android-common",
+        "inputmethod-common",
+        "jsr305",
+        "latinime-common",
+        "android-support-v4",
+    ],
+
+    // Do not compress dictionary files to mmap dict data runtime
+    aaptflags: ["-0 .dict"],
+
+    // Include all the resources regardless of system supported locales
+    aapt_include_all_resources: true,
+
+    sdk_version: "current",
+
+    optimize: {
+        proguard_flags_files: ["proguard.flags"],
+    },
+}
diff --git a/java/Android.mk b/java/Android.mk
deleted file mode 100644
index 154f3a2..0000000
--- a/java/Android.mk
+++ /dev/null
@@ -1,46 +0,0 @@
-# Copyright (C) 2011 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src ../java-overridable/src)
-
-LOCAL_PACKAGE_NAME := LatinIME
-
-LOCAL_CERTIFICATE := shared
-
-LOCAL_JNI_SHARED_LIBRARIES := libjni_latinime
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-        android-common inputmethod-common jsr305 latinime-common
-
-LOCAL_STATIC_ANDROID_LIBRARIES := \
-        android-support-v4
-
-LOCAL_USE_AAPT2 := true
-
-# Do not compress dictionary files to mmap dict data runtime
-LOCAL_AAPT_FLAGS := -0 .dict
-
-# Include all the resources regardless of system supported locales
-LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
-
-LOCAL_SDK_VERSION := current
-
-LOCAL_PROGUARD_FLAG_FILES := proguard.flags
-
-include $(BUILD_PACKAGE)
diff --git a/native/Android.mk b/native/Android.mk
deleted file mode 100644
index 5053e7d..0000000
--- a/native/Android.mk
+++ /dev/null
@@ -1 +0,0 @@
-include $(call all-subdir-makefiles)
diff --git a/native/dicttoolkit/Android.bp b/native/dicttoolkit/Android.bp
new file mode 100644
index 0000000..b214ff9
--- /dev/null
+++ b/native/dicttoolkit/Android.bp
@@ -0,0 +1,94 @@
+// Copyright (C) 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_defaults {
+    name: "dicttoolkit_defaults",
+
+    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"],
+    // TODO
+    include_dirs: ["packages/inputmethods/LatinIME/native/jni/src"],
+
+    product_variables: {
+        unbundled_build: {
+            enabled: false,
+        },
+    },
+}
+
+cc_library_host_static {
+    name: "liblatinime_dicttoolkit",
+    defaults: ["dicttoolkit_defaults"],
+
+    srcs: [
+        "src/command_executors/diff_executor.cpp",
+        "src/command_executors/header_executor.cpp",
+        "src/command_executors/help_executor.cpp",
+        "src/command_executors/info_executor.cpp",
+        "src/command_executors/makedict_executor.cpp",
+        "src/offdevice_intermediate_dict/offdevice_intermediate_dict.cpp",
+        "src/utils/arguments_parser.cpp",
+        "src/utils/command_utils.cpp",
+        "src/utils/utf8_utils.cpp",
+
+        ":LATIN_IME_CORE_SRC_FILES",
+    ],
+}
+
+cc_binary_host {
+    name: "dicttoolkit",
+    defaults: ["dicttoolkit_defaults"],
+
+    srcs: ["dict_toolkit_main.cpp"],
+    static_libs: ["liblatinime_dicttoolkit"],
+}
+
+cc_test_host {
+    name: "dicttoolkit_unittests",
+    defaults: ["dicttoolkit_defaults"],
+
+    srcs: [
+        "tests/command_executors/diff_executor_test.cpp",
+        "tests/command_executors/header_executor_test.cpp",
+        "tests/command_executors/info_executor_test.cpp",
+        "tests/command_executors/makedict_executor_test.cpp",
+        "tests/dict_toolkit_defines_test.cpp",
+        "tests/offdevice_intermediate_dict/offdevice_intermediate_dict_test.cpp",
+        "tests/utils/arguments_parser_test.cpp",
+        "tests/utils/command_utils_test.cpp",
+        "tests/utils/utf8_utils_test.cpp",
+    ],
+    static_libs: ["liblatinime_dicttoolkit"],
+}
diff --git a/native/dicttoolkit/Android.mk b/native/dicttoolkit/Android.mk
deleted file mode 100644
index 7a44686..0000000
--- a/native/dicttoolkit/Android.mk
+++ /dev/null
@@ -1,66 +0,0 @@
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-ifeq (,$(TARGET_BUILD_APPS))
-
-# Only build if it's explicitly requested, or running mm/mmm.
-ifneq ($(ONE_SHOT_MAKEFILE)$(filter $(MAKECMDGOALS),dicttoolkit),)
-
-# HACK: Temporarily disable host tool build on Mac until the build system is ready for C++11.
-LATINIME_HOST_OSNAME := $(shell uname -s)
-ifneq ($(LATINIME_HOST_OSNAME), Darwin) # TODO: Remove this
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LATIN_IME_CORE_PATH := $(LOCAL_PATH)/../jni
-
-LATIN_IME_DICT_TOOLKIT_SRC_DIR := src
-LATIN_IME_CORE_SRC_DIR := ../jni/src
-
-LOCAL_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.
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
-
-include $(LOCAL_PATH)/NativeFileList.mk
-include $(LATIN_IME_CORE_PATH)/NativeFileList.mk
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_DICT_TOOLKIT_SRC_DIR) \
-    $(LATIN_IME_CORE_PATH)/$(LATIN_IME_CORE_SRC_DIR)
-
-LOCAL_SRC_FILES := $(LATIN_IME_DICT_TOOLKIT_MAIN_SRC_FILES) \
-    $(addprefix $(LATIN_IME_DICT_TOOLKIT_SRC_DIR)/, $(LATIN_IME_DICT_TOOLKIT_SRC_FILES)) \
-    $(addprefix $(LATIN_IME_CORE_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES))
-
-LOCAL_MODULE := dicttoolkit
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CXX_STL := libc++
-
-include $(BUILD_HOST_EXECUTABLE)
-#################### Clean up the tmp vars
-include $(LOCAL_PATH)/CleanupNativeFileList.mk
-#################### Unit test
-include $(LOCAL_PATH)/UnitTests.mk
-
-endif # Darwin - TODO: Remove this
-
-endif
-
-endif # TARGET_BUILD_APPS
diff --git a/native/dicttoolkit/CleanupNativeFileList.mk b/native/dicttoolkit/CleanupNativeFileList.mk
deleted file mode 100644
index b804b41..0000000
--- a/native/dicttoolkit/CleanupNativeFileList.mk
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LATIN_IME_DICT_TOOLKIT_MAIN_SRC_FILES :=
-LATIN_IME_DICT_TOOLKIT_SRC_FILES :=
-LATIN_IME_DICT_TOOLKIT_TEST_FILES :=
diff --git a/native/dicttoolkit/NativeFileList.mk b/native/dicttoolkit/NativeFileList.mk
deleted file mode 100644
index 9a547b0..0000000
--- a/native/dicttoolkit/NativeFileList.mk
+++ /dev/null
@@ -1,44 +0,0 @@
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LATIN_IME_DICT_TOOLKIT_MAIN_SRC_FILES := \
-    dict_toolkit_main.cpp
-
-LATIN_IME_DICT_TOOLKIT_SRC_FILES := \
-    $(addprefix command_executors/, \
-        diff_executor.cpp \
-        header_executor.cpp \
-        help_executor.cpp \
-        info_executor.cpp \
-        makedict_executor.cpp) \
-    $(addprefix offdevice_intermediate_dict/, \
-        offdevice_intermediate_dict.cpp) \
-    $(addprefix utils/, \
-        arguments_parser.cpp \
-        command_utils.cpp \
-        utf8_utils.cpp)
-
-LATIN_IME_DICT_TOOLKIT_TEST_FILES := \
-    $(addprefix command_executors/, \
-        diff_executor_test.cpp \
-        header_executor_test.cpp \
-        info_executor_test.cpp \
-        makedict_executor_test.cpp) \
-    dict_toolkit_defines_test.cpp \
-    $(addprefix offdevice_intermediate_dict/, \
-        offdevice_intermediate_dict_test.cpp) \
-    $(addprefix utils/, \
-        arguments_parser_test.cpp \
-        command_utils_test.cpp \
-        utf8_utils_test.cpp)
diff --git a/native/dicttoolkit/UnitTests.mk b/native/dicttoolkit/UnitTests.mk
deleted file mode 100644
index 55177c0..0000000
--- a/native/dicttoolkit/UnitTests.mk
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-ifeq (,$(TARGET_BUILD_APPS))
-
-LOCAL_PATH := $(call my-dir)
-
-######################################
-include $(CLEAR_VARS)
-
-LATIN_IME_CORE_PATH := $(LOCAL_PATH)/../jni
-
-LATIN_IME_DICT_TOOLKIT_SRC_DIR := src
-LATIN_IME_CORE_SRC_DIR := ../jni/src
-LATIN_DICT_TOOLKIT_TEST_SRC_DIR := tests
-
-include $(LOCAL_PATH)/NativeFileList.mk
-include $(LATIN_IME_CORE_PATH)/NativeFileList.mk
-
-LATIN_IME_SRC_DIR := src
-LOCAL_ADDRESS_SANITIZER := true
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
-LOCAL_CXX_STL := libc++
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_DICT_TOOLKIT_SRC_DIR) \
-    $(LATIN_IME_CORE_PATH)/$(LATIN_IME_CORE_SRC_DIR)
-LOCAL_MODULE := liblatinime_dicttoolkit_host_static_for_unittests
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := \
-    $(addprefix $(LATIN_IME_DICT_TOOLKIT_SRC_DIR)/, $(LATIN_IME_DICT_TOOLKIT_SRC_FILES)) \
-    $(addprefix $(LATIN_IME_CORE_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES))
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-
-LOCAL_ADDRESS_SANITIZER := true
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
-LOCAL_CXX_STL := libc++
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_DICT_TOOLKIT_SRC_DIR) \
-    $(LATIN_IME_CORE_PATH)/$(LATIN_IME_CORE_SRC_DIR)
-LOCAL_MODULE := dicttoolkit_unittests
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := \
-    $(addprefix $(LATIN_DICT_TOOLKIT_TEST_SRC_DIR)/, $(LATIN_IME_DICT_TOOLKIT_TEST_FILES))
-LOCAL_STATIC_LIBRARIES += liblatinime_dicttoolkit_host_static_for_unittests
-include $(BUILD_HOST_NATIVE_TEST)
-
-include $(LOCAL_PATH)/CleanupNativeFileList.mk
-
-#################### Clean up the tmp vars
-LATINIME_HOST_OSNAME :=
-LATIN_IME_SRC_DIR :=
-LATIN_IME_TEST_SRC_DIR :=
-
-endif # TARGET_BUILD_APPS
diff --git a/native/dicttoolkit/src/offdevice_intermediate_dict/offdevice_intermediate_dict.h b/native/dicttoolkit/src/offdevice_intermediate_dict/offdevice_intermediate_dict.h
index 13d26ba..ea17a31 100644
--- a/native/dicttoolkit/src/offdevice_intermediate_dict/offdevice_intermediate_dict.h
+++ b/native/dicttoolkit/src/offdevice_intermediate_dict/offdevice_intermediate_dict.h
@@ -20,7 +20,7 @@
 #include "dict_toolkit_defines.h"
 #include "offdevice_intermediate_dict/offdevice_intermediate_dict_header.h"
 #include "offdevice_intermediate_dict/offdevice_intermediate_dict_pt_node_array.h"
-#include "suggest/core/dictionary/property/word_property.h"
+#include "dictionary/property/word_property.h"
 #include "utils/int_array_view.h"
 
 namespace latinime {
diff --git a/native/dicttoolkit/src/offdevice_intermediate_dict/offdevice_intermediate_dict_pt_node.h b/native/dicttoolkit/src/offdevice_intermediate_dict/offdevice_intermediate_dict_pt_node.h
index 721ccd7..e7d7e13 100644
--- a/native/dicttoolkit/src/offdevice_intermediate_dict/offdevice_intermediate_dict_pt_node.h
+++ b/native/dicttoolkit/src/offdevice_intermediate_dict/offdevice_intermediate_dict_pt_node.h
@@ -21,7 +21,7 @@
 
 #include "dict_toolkit_defines.h"
 #include "offdevice_intermediate_dict/offdevice_intermediate_dict_pt_node_array.h"
-#include "suggest/core/dictionary/property/word_property.h"
+#include "dictionary/property/word_property.h"
 #include "utils/int_array_view.h"
 
 namespace latinime {
diff --git a/native/dicttoolkit/tests/offdevice_intermediate_dict/offdevice_intermediate_dict_test.cpp b/native/dicttoolkit/tests/offdevice_intermediate_dict/offdevice_intermediate_dict_test.cpp
index f2e24ab..89598de 100644
--- a/native/dicttoolkit/tests/offdevice_intermediate_dict/offdevice_intermediate_dict_test.cpp
+++ b/native/dicttoolkit/tests/offdevice_intermediate_dict/offdevice_intermediate_dict_test.cpp
@@ -20,7 +20,7 @@
 
 #include <vector>
 
-#include "suggest/core/dictionary/property/word_property.h"
+#include "dictionary/property/word_property.h"
 #include "utils/int_array_view.h"
 
 namespace latinime {
diff --git a/native/jni/Android.bp b/native/jni/Android.bp
new file mode 100644
index 0000000..3bf70ad
--- /dev/null
+++ b/native/jni/Android.bp
@@ -0,0 +1,213 @@
+// Copyright (C) 2013 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+filegroup {
+    name: "LATIN_IME_CORE_SRC_FILES",
+    srcs: [
+        "src/dictionary/header/header_policy.cpp",
+        "src/dictionary/header/header_read_write_utils.cpp",
+        "src/dictionary/property/ngram_context.cpp",
+        "src/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp",
+        "src/dictionary/structure/pt_common/bigram/bigram_list_read_write_utils.cpp",
+        "src/dictionary/structure/pt_common/dynamic_pt_gc_event_listeners.cpp",
+        "src/dictionary/structure/pt_common/dynamic_pt_reading_helper.cpp",
+        "src/dictionary/structure/pt_common/dynamic_pt_reading_utils.cpp",
+        "src/dictionary/structure/pt_common/dynamic_pt_updating_helper.cpp",
+        "src/dictionary/structure/pt_common/dynamic_pt_writing_utils.cpp",
+        "src/dictionary/structure/pt_common/patricia_trie_reading_utils.cpp",
+        "src/dictionary/structure/pt_common/shortcut/shortcut_list_reading_utils.cpp",
+        "src/dictionary/structure/v2/patricia_trie_policy.cpp",
+        "src/dictionary/structure/v2/ver2_patricia_trie_node_reader.cpp",
+        "src/dictionary/structure/v2/ver2_pt_node_array_reader.cpp",
+        "src/dictionary/structure/v4/ver4_dict_buffers.cpp",
+        "src/dictionary/structure/v4/ver4_dict_constants.cpp",
+        "src/dictionary/structure/v4/ver4_patricia_trie_node_reader.cpp",
+        "src/dictionary/structure/v4/ver4_patricia_trie_node_writer.cpp",
+        "src/dictionary/structure/v4/ver4_patricia_trie_policy.cpp",
+        "src/dictionary/structure/v4/ver4_patricia_trie_reading_utils.cpp",
+        "src/dictionary/structure/v4/ver4_patricia_trie_writing_helper.cpp",
+        "src/dictionary/structure/v4/ver4_pt_node_array_reader.cpp",
+        "src/dictionary/structure/v4/content/dynamic_language_model_probability_utils.cpp",
+        "src/dictionary/structure/v4/content/language_model_dict_content.cpp",
+        "src/dictionary/structure/v4/content/language_model_dict_content_global_counters.cpp",
+        "src/dictionary/structure/v4/content/shortcut_dict_content.cpp",
+        "src/dictionary/structure/v4/content/sparse_table_dict_content.cpp",
+        "src/dictionary/structure/v4/content/terminal_position_lookup_table.cpp",
+        "src/dictionary/utils/buffer_with_extendable_buffer.cpp",
+        "src/dictionary/utils/byte_array_utils.cpp",
+        "src/dictionary/utils/dict_file_writing_utils.cpp",
+        "src/dictionary/utils/file_utils.cpp",
+        "src/dictionary/utils/forgetting_curve_utils.cpp",
+        "src/dictionary/utils/format_utils.cpp",
+        "src/dictionary/utils/mmapped_buffer.cpp",
+        "src/dictionary/utils/multi_bigram_map.cpp",
+        "src/dictionary/utils/probability_utils.cpp",
+        "src/dictionary/utils/sparse_table.cpp",
+        "src/dictionary/utils/trie_map.cpp",
+        "src/suggest/core/suggest.cpp",
+        "src/suggest/core/dicnode/dic_node.cpp",
+        "src/suggest/core/dicnode/dic_node_utils.cpp",
+        "src/suggest/core/dicnode/dic_nodes_cache.cpp",
+        "src/suggest/core/dictionary/dictionary.cpp",
+        "src/suggest/core/dictionary/dictionary_utils.cpp",
+        "src/suggest/core/dictionary/digraph_utils.cpp",
+        "src/suggest/core/dictionary/error_type_utils.cpp",
+        "src/suggest/core/layout/additional_proximity_chars.cpp",
+        "src/suggest/core/layout/proximity_info.cpp",
+        "src/suggest/core/layout/proximity_info_params.cpp",
+        "src/suggest/core/layout/proximity_info_state.cpp",
+        "src/suggest/core/layout/proximity_info_state_utils.cpp",
+        "src/suggest/core/policy/weighting.cpp",
+        "src/suggest/core/session/dic_traverse_session.cpp",
+        "src/suggest/core/result/suggestion_results.cpp",
+        "src/suggest/core/result/suggestions_output_utils.cpp",
+        "src/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp",
+        "src/suggest/policyimpl/typing/scoring_params.cpp",
+        "src/suggest/policyimpl/typing/typing_scoring.cpp",
+        "src/suggest/policyimpl/typing/typing_suggest_policy.cpp",
+        "src/suggest/policyimpl/typing/typing_traversal.cpp",
+        "src/suggest/policyimpl/typing/typing_weighting.cpp",
+        "src/utils/autocorrection_threshold_utils.cpp",
+        "src/utils/char_utils.cpp",
+        "src/utils/jni_data_utils.cpp",
+        "src/utils/log_utils.cpp",
+        "src/utils/time_keeper.cpp",
+
+        // BACKWARD_V402
+        "src/dictionary/structure/backward/v402/ver4_dict_buffers.cpp",
+        "src/dictionary/structure/backward/v402/ver4_dict_constants.cpp",
+        "src/dictionary/structure/backward/v402/ver4_patricia_trie_node_reader.cpp",
+        "src/dictionary/structure/backward/v402/ver4_patricia_trie_node_writer.cpp",
+        "src/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp",
+        "src/dictionary/structure/backward/v402/ver4_patricia_trie_reading_utils.cpp",
+        "src/dictionary/structure/backward/v402/ver4_patricia_trie_writing_helper.cpp",
+        "src/dictionary/structure/backward/v402/ver4_pt_node_array_reader.cpp",
+        "src/dictionary/structure/backward/v402/content/bigram_dict_content.cpp",
+        "src/dictionary/structure/backward/v402/content/probability_dict_content.cpp",
+        "src/dictionary/structure/backward/v402/content/shortcut_dict_content.cpp",
+        "src/dictionary/structure/backward/v402/content/sparse_table_dict_content.cpp",
+        "src/dictionary/structure/backward/v402/content/terminal_position_lookup_table.cpp",
+        "src/dictionary/structure/backward/v402/bigram/ver4_bigram_list_policy.cpp",
+    ],
+}
+
+cc_library {
+    name: "libjni_latinime",
+    host_supported: 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"],
+        },
+    },
+}
+
+cc_library_static {
+    name: "liblatinime_static_for_unittests",
+    host_supported: true,
+
+    cflags: [
+        "-Wno-unused-parameter",
+        "-Wno-unused-function",
+        "-Wall",
+        "-Werror",
+    ],
+    local_include_dirs: ["src"],
+    sdk_version: "14",
+    stl: "libc++_static",
+
+    srcs: [":LATIN_IME_CORE_SRC_FILES"],
+}
+
+cc_test {
+    name: "liblatinime_unittests",
+    host_supported: true,
+
+    cflags: [
+        "-Wno-unused-parameter",
+        "-Wno-unused-function",
+        "-Wall",
+        "-Werror",
+    ],
+    local_include_dirs: ["src"],
+    sdk_version: "14",
+    stl: "libc++_static",
+
+    srcs: [
+        "tests/defines_test.cpp",
+        "tests/dictionary/header/header_read_write_utils_test.cpp",
+        "tests/dictionary/structure/v4/content/language_model_dict_content_test.cpp",
+        "tests/dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp",
+        "tests/dictionary/structure/v4/content/probability_entry_test.cpp",
+        "tests/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp",
+        "tests/dictionary/utils/bloom_filter_test.cpp",
+        "tests/dictionary/utils/buffer_with_extendable_buffer_test.cpp",
+        "tests/dictionary/utils/byte_array_utils_test.cpp",
+        "tests/dictionary/utils/format_utils_test.cpp",
+        "tests/dictionary/utils/probability_utils_test.cpp",
+        "tests/dictionary/utils/sparse_table_test.cpp",
+        "tests/dictionary/utils/trie_map_test.cpp",
+        "tests/suggest/core/dicnode/dic_node_pool_test.cpp",
+        "tests/suggest/core/layout/geometry_utils_test.cpp",
+        "tests/suggest/core/layout/normal_distribution_2d_test.cpp",
+        "tests/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy_test.cpp",
+        "tests/utils/autocorrection_threshold_utils_test.cpp",
+        "tests/utils/char_utils_test.cpp",
+        "tests/utils/int_array_view_test.cpp",
+        "tests/utils/time_keeper_test.cpp",
+    ],
+    static_libs: ["liblatinime_static_for_unittests"],
+}
diff --git a/native/jni/Android.mk b/native/jni/Android.mk
deleted file mode 100644
index 5384648..0000000
--- a/native/jni/Android.mk
+++ /dev/null
@@ -1,103 +0,0 @@
-# Copyright (C) 2011 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-
-############ some local flags
-# If you change any of those flags, you need to rebuild both libjni_latinime_common_static
-# and the shared library that uses libjni_latinime_common_static.
-FLAG_DBG ?= false
-FLAG_DO_PROFILE ?= false
-
-######################################
-include $(CLEAR_VARS)
-
-LATIN_IME_SRC_DIR := src
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
-
-LOCAL_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.
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
-
-# HACK: -mstackrealign is required for x86 builds running on pre-KitKat devices to avoid crashes
-# with SSE instructions.
-ifeq ($(TARGET_ARCH), x86)
-    LOCAL_CFLAGS += -mstackrealign
-endif # x86
-
-include $(LOCAL_PATH)/NativeFileList.mk
-
-LOCAL_SRC_FILES := \
-    $(LATIN_IME_JNI_SRC_FILES) \
-    $(addprefix $(LATIN_IME_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES))
-
-ifeq ($(FLAG_DO_PROFILE), true)
-    $(warning Making profiling version of native library)
-    LOCAL_CFLAGS += -DFLAG_DO_PROFILE -funwind-tables
-else # FLAG_DO_PROFILE
-ifeq ($(FLAG_DBG), true)
-    $(warning Making debug version of native library)
-    LOCAL_CFLAGS += -DFLAG_DBG -funwind-tables -fno-inline
-ifeq ($(FLAG_FULL_DBG), true)
-    $(warning Making full debug version of native library)
-    LOCAL_CFLAGS += -DFLAG_FULL_DBG
-endif # FLAG_FULL_DBG
-endif # FLAG_DBG
-endif # FLAG_DO_PROFILE
-
-LOCAL_MODULE := libjni_latinime_common_static
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SDK_VERSION := 14
-LOCAL_NDK_STL_VARIANT := c++_static
-
-include $(BUILD_STATIC_LIBRARY)
-######################################
-include $(CLEAR_VARS)
-
-# All code in LOCAL_WHOLE_STATIC_LIBRARIES will be built into this shared library.
-LOCAL_WHOLE_STATIC_LIBRARIES := libjni_latinime_common_static
-
-ifeq ($(FLAG_DO_PROFILE), true)
-    $(warning Making profiling version of native library)
-    LOCAL_LDFLAGS += -llog
-else # FLAG_DO_PROFILE
-ifeq ($(FLAG_DBG), true)
-    $(warning Making debug version of native library)
-    LOCAL_LDFLAGS += -llog
-endif # FLAG_DBG
-endif # FLAG_DO_PROFILE
-
-LOCAL_MODULE := libjni_latinime
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SDK_VERSION := 14
-LOCAL_NDK_STL_VARIANT := c++_static
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_LDFLAGS += -ldl
-
-include $(BUILD_SHARED_LIBRARY)
-#################### Clean up the tmp vars
-include $(LOCAL_PATH)/CleanupNativeFileList.mk
-
-#################### Unit test on host environment
-include $(LOCAL_PATH)/HostUnitTests.mk
-
-#################### Unit test on target environment
-include $(LOCAL_PATH)/TargetUnitTests.mk
-//LOCAL_CFLAGS += -Wall -Werror
diff --git a/native/jni/Application.mk b/native/jni/Application.mk
deleted file mode 100644
index ce09535..0000000
--- a/native/jni/Application.mk
+++ /dev/null
@@ -1 +0,0 @@
-APP_STL := c++_static
diff --git a/native/jni/CleanupNativeFileList.mk b/native/jni/CleanupNativeFileList.mk
deleted file mode 100644
index eed6f1e..0000000
--- a/native/jni/CleanupNativeFileList.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright (C) 2013 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LATIN_IME_CORE_SRC_FILES :=
-LATIN_IME_CORE_SRC_FILES_BACKWARD_V401 :=
-LATIN_IME_CORE_TEST_FILES :=
-LATIN_IME_JNI_SRC_FILES :=
-LATIN_IME_SRC_DIR :=
diff --git a/native/jni/HostUnitTests.mk b/native/jni/HostUnitTests.mk
deleted file mode 100644
index 94cd764..0000000
--- a/native/jni/HostUnitTests.mk
+++ /dev/null
@@ -1,63 +0,0 @@
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Host build is never supported in unbundled (NDK/tapas) build
-ifeq (,$(TARGET_BUILD_APPS))
-
-# HACK: Temporarily disable host tool build on Mac until the build system is ready for C++11.
-LATINIME_HOST_OSNAME := $(shell uname -s)
-ifneq ($(LATINIME_HOST_OSNAME), Darwin) # TODO: Remove this
-
-LOCAL_PATH := $(call my-dir)
-
-######################################
-include $(CLEAR_VARS)
-
-include $(LOCAL_PATH)/NativeFileList.mk
-
-#################### Host library for unit test
-LATIN_IME_SRC_DIR := src
-LOCAL_ADDRESS_SANITIZER := true
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function -Wall -Werror
-LOCAL_CXX_STL := libc++
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
-LOCAL_MODULE := liblatinime_host_static_for_unittests
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(addprefix $(LATIN_IME_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES))
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-#################### Host native tests
-include $(CLEAR_VARS)
-LATIN_IME_TEST_SRC_DIR := tests
-LOCAL_ADDRESS_SANITIZER := true
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
-LOCAL_CFLAGS += -Wall -Werror
-LOCAL_CXX_STL := libc++
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
-LOCAL_MODULE := liblatinime_host_unittests
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := $(addprefix $(LATIN_IME_TEST_SRC_DIR)/, $(LATIN_IME_CORE_TEST_FILES))
-LOCAL_STATIC_LIBRARIES += liblatinime_host_static_for_unittests
-include $(BUILD_HOST_NATIVE_TEST)
-
-include $(LOCAL_PATH)/CleanupNativeFileList.mk
-
-endif # Darwin - TODO: Remove this
-
-endif # TARGET_BUILD_APPS
-
-#################### Clean up the tmp vars
-LATINIME_HOST_OSNAME :=
-LATIN_IME_SRC_DIR :=
-LATIN_IME_TEST_SRC_DIR :=
diff --git a/native/jni/NativeFileList.mk b/native/jni/NativeFileList.mk
deleted file mode 100644
index d8b69bf..0000000
--- a/native/jni/NativeFileList.mk
+++ /dev/null
@@ -1,146 +0,0 @@
-# Copyright (C) 2013 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LATIN_IME_JNI_SRC_FILES := \
-    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 := \
-    $(addprefix dictionary/header/, \
-        header_policy.cpp \
-        header_read_write_utils.cpp) \
-    dictionary/property/ngram_context.cpp \
-    dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp \
-    $(addprefix dictionary/structure/pt_common/, \
-        bigram/bigram_list_read_write_utils.cpp \
-        dynamic_pt_gc_event_listeners.cpp \
-        dynamic_pt_reading_helper.cpp \
-        dynamic_pt_reading_utils.cpp \
-        dynamic_pt_updating_helper.cpp \
-        dynamic_pt_writing_utils.cpp \
-        patricia_trie_reading_utils.cpp \
-        shortcut/shortcut_list_reading_utils.cpp) \
-    $(addprefix dictionary/structure/v2/, \
-        patricia_trie_policy.cpp \
-        ver2_patricia_trie_node_reader.cpp \
-        ver2_pt_node_array_reader.cpp) \
-    $(addprefix dictionary/structure/v4/, \
-        ver4_dict_buffers.cpp \
-        ver4_dict_constants.cpp \
-        ver4_patricia_trie_node_reader.cpp \
-        ver4_patricia_trie_node_writer.cpp \
-        ver4_patricia_trie_policy.cpp \
-        ver4_patricia_trie_reading_utils.cpp \
-        ver4_patricia_trie_writing_helper.cpp \
-        ver4_pt_node_array_reader.cpp) \
-    $(addprefix dictionary/structure/v4/content/, \
-        dynamic_language_model_probability_utils.cpp \
-        language_model_dict_content.cpp \
-        language_model_dict_content_global_counters.cpp \
-        shortcut_dict_content.cpp \
-        sparse_table_dict_content.cpp \
-        terminal_position_lookup_table.cpp) \
-    $(addprefix dictionary/utils/, \
-        buffer_with_extendable_buffer.cpp \
-        byte_array_utils.cpp \
-        dict_file_writing_utils.cpp \
-        file_utils.cpp \
-        forgetting_curve_utils.cpp \
-        format_utils.cpp \
-        mmapped_buffer.cpp \
-        multi_bigram_map.cpp \
-        probability_utils.cpp \
-        sparse_table.cpp \
-        trie_map.cpp ) \
-    suggest/core/suggest.cpp \
-    $(addprefix suggest/core/dicnode/, \
-        dic_node.cpp \
-        dic_node_utils.cpp \
-        dic_nodes_cache.cpp) \
-    $(addprefix suggest/core/dictionary/, \
-        dictionary.cpp \
-        dictionary_utils.cpp \
-        digraph_utils.cpp \
-        error_type_utils.cpp ) \
-    $(addprefix suggest/core/layout/, \
-        additional_proximity_chars.cpp \
-        proximity_info.cpp \
-        proximity_info_params.cpp \
-        proximity_info_state.cpp \
-        proximity_info_state_utils.cpp) \
-    suggest/core/policy/weighting.cpp \
-    suggest/core/session/dic_traverse_session.cpp \
-    $(addprefix suggest/core/result/, \
-        suggestion_results.cpp \
-        suggestions_output_utils.cpp) \
-    suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp \
-    $(addprefix suggest/policyimpl/typing/, \
-        scoring_params.cpp \
-        typing_scoring.cpp \
-        typing_suggest_policy.cpp \
-        typing_traversal.cpp \
-        typing_weighting.cpp) \
-    $(addprefix utils/, \
-        autocorrection_threshold_utils.cpp \
-        char_utils.cpp \
-        jni_data_utils.cpp \
-        log_utils.cpp \
-        time_keeper.cpp)
-
-LATIN_IME_CORE_SRC_FILES_BACKWARD_V402 := \
-    $(addprefix dictionary/structure/backward/v402/, \
-        ver4_dict_buffers.cpp \
-        ver4_dict_constants.cpp \
-        ver4_patricia_trie_node_reader.cpp \
-        ver4_patricia_trie_node_writer.cpp \
-        ver4_patricia_trie_policy.cpp \
-        ver4_patricia_trie_reading_utils.cpp \
-        ver4_patricia_trie_writing_helper.cpp \
-        ver4_pt_node_array_reader.cpp) \
-    $(addprefix dictionary/structure/backward/v402/content/, \
-        bigram_dict_content.cpp \
-        probability_dict_content.cpp \
-        shortcut_dict_content.cpp \
-        sparse_table_dict_content.cpp \
-        terminal_position_lookup_table.cpp) \
-    $(addprefix dictionary/structure/backward/v402/bigram/, \
-        ver4_bigram_list_policy.cpp)
-
-LATIN_IME_CORE_SRC_FILES += $(LATIN_IME_CORE_SRC_FILES_BACKWARD_V402)
-
-LATIN_IME_CORE_TEST_FILES := \
-    defines_test.cpp \
-    dictionary/header/header_read_write_utils_test.cpp \
-    dictionary/structure/v4/content/language_model_dict_content_test.cpp \
-    dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp \
-    dictionary/structure/v4/content/probability_entry_test.cpp \
-    dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp \
-    dictionary/utils/bloom_filter_test.cpp \
-    dictionary/utils/buffer_with_extendable_buffer_test.cpp \
-    dictionary/utils/byte_array_utils_test.cpp \
-    dictionary/utils/format_utils_test.cpp \
-    dictionary/utils/probability_utils_test.cpp \
-    dictionary/utils/sparse_table_test.cpp \
-    dictionary/utils/trie_map_test.cpp \
-    suggest/core/dicnode/dic_node_pool_test.cpp \
-    suggest/core/layout/geometry_utils_test.cpp \
-    suggest/core/layout/normal_distribution_2d_test.cpp \
-    suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy_test.cpp \
-    utils/autocorrection_threshold_utils_test.cpp \
-    utils/char_utils_test.cpp \
-    utils/int_array_view_test.cpp \
-    utils/time_keeper_test.cpp
diff --git a/native/jni/TargetUnitTests.mk b/native/jni/TargetUnitTests.mk
deleted file mode 100644
index 32aada0..0000000
--- a/native/jni/TargetUnitTests.mk
+++ /dev/null
@@ -1,50 +0,0 @@
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-
-######################################
-include $(CLEAR_VARS)
-
-include $(LOCAL_PATH)/NativeFileList.mk
-
-#################### Target library for unit test
-LATIN_IME_SRC_DIR := src
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function -Wall -Werror
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
-LOCAL_MODULE := liblatinime_target_static_for_unittests
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(addprefix $(LATIN_IME_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES))
-LOCAL_SDK_VERSION := 14
-LOCAL_NDK_STL_VARIANT := c++_static
-include $(BUILD_STATIC_LIBRARY)
-
-#################### Target native tests
-include $(CLEAR_VARS)
-LATIN_IME_TEST_SRC_DIR := tests
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function -Wall -Werror
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
-LOCAL_MODULE := liblatinime_target_unittests
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES :=  \
-    $(addprefix $(LATIN_IME_TEST_SRC_DIR)/, $(LATIN_IME_CORE_TEST_FILES))
-LOCAL_STATIC_LIBRARIES += liblatinime_target_static_for_unittests
-LOCAL_SDK_VERSION := 14
-LOCAL_NDK_STL_VARIANT := c++_static
-include $(BUILD_NATIVE_TEST)
-
-#################### Clean up the tmp vars
-LATIN_IME_SRC_DIR :=
-LATIN_IME_TEST_SRC_DIR :=
-include $(LOCAL_PATH)/CleanupNativeFileList.mk
diff --git a/tests/Android.bp b/tests/Android.bp
new file mode 100644
index 0000000..a99cc5b
--- /dev/null
+++ b/tests/Android.bp
@@ -0,0 +1,44 @@
+// Copyright (C) 2011 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+android_test {
+    name: "LatinIMETests",
+
+    certificate: "shared",
+
+    aaptflags: [
+        // Do not compress dictionary files to mmap dict data runtime
+        "-0 .dict",
+
+        // Do not compress test data file
+        "-0 .txt",
+    ],
+
+    static_libs: [
+        "android-support-test",
+        "mockito-target-minus-junit4",
+    ],
+    libs: [
+        "android.test.mock.stubs",
+        "android.test.runner.stubs",
+        "android.test.base.stubs",
+    ],
+
+    // Include all test java files.
+    srcs: ["src/**/*.java"],
+
+    instrumentation_for: "LatinIME",
+
+    sdk_version: "current",
+}
diff --git a/tests/Android.mk b/tests/Android.mk
deleted file mode 100644
index 7c0bb4f..0000000
--- a/tests/Android.mk
+++ /dev/null
@@ -1,46 +0,0 @@
-# Copyright (C) 2011 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-# We only want this apk build for tests.
-LOCAL_MODULE_TAGS := tests
-LOCAL_CERTIFICATE := shared
-
-# Do not compress dictionary files to mmap dict data runtime
-LOCAL_AAPT_FLAGS += -0 .dict
-# Do not compress test data file
-LOCAL_AAPT_FLAGS += -0 .txt
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    android-support-test \
-    mockito-target-minus-junit4
-
-LOCAL_JAVA_LIBRARIES := \
-    android.test.mock.stubs \
-    android.test.runner.stubs \
-    android.test.base.stubs \
-
-
-# Include all test java files.
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := LatinIMETests
-
-LOCAL_INSTRUMENTATION_FOR := LatinIME
-
-LOCAL_SDK_VERSION := current
-
-include $(BUILD_PACKAGE)
diff --git a/tools/Android.mk b/tools/Android.mk
deleted file mode 100644
index 91b2fbb..0000000
--- a/tools/Android.mk
+++ /dev/null
@@ -1,15 +0,0 @@
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(call all-subdir-makefiles)
diff --git a/tools/dicttool/Android.bp b/tools/dicttool/Android.bp
new file mode 100644
index 0000000..83b4ed3
--- /dev/null
+++ b/tools/dicttool/Android.bp
@@ -0,0 +1,32 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+java_binary_host {
+    name: "dicttool_aosp",
+
+    srcs: [
+        "src/**/*.java",
+        "tests/**/*.java",
+        "compat/**/*.java",
+        ":dicttool_deps",
+    ],
+
+    libs: ["junit"],
+    static_libs: [
+        "jsr305",
+        "latinime-common",
+    ],
+    required: ["libjni_latinime"],
+    main_class: "com.android.inputmethod.latin.dicttool.Dicttool",
+}
diff --git a/tools/dicttool/Android.mk b/tools/dicttool/Android.mk
deleted file mode 100644
index dc53cd8..0000000
--- a/tools/dicttool/Android.mk
+++ /dev/null
@@ -1,91 +0,0 @@
-#
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Only build if it's explicitly requested, or running mm/mmm.
-ifneq ($(ONE_SHOT_MAKEFILE)$(filter $(MAKECMDGOALS),dicttool_aosp),)
-
-LATINIME_DICTTOOL_AOSP_LOCAL_PATH := $(call my-dir)
-LOCAL_PATH := $(LATINIME_DICTTOOL_AOSP_LOCAL_PATH)
-LATINIME_HOST_NATIVE_LIBNAME := liblatinime-aosp-dicttool-host
-include $(LOCAL_PATH)/NativeLib.mk
-
-######################################
-LOCAL_PATH := $(LATINIME_DICTTOOL_AOSP_LOCAL_PATH)
-include $(CLEAR_VARS)
-
-LATINIME_LOCAL_DIR := ../..
-LATINIME_BASE_SRC_DIR := $(LATINIME_LOCAL_DIR)/java/src/com/android/inputmethod
-LATINIME_BASE_OVERRIDABLE_SRC_DIR := \
-        $(LATINIME_LOCAL_DIR)/java-overridable/src/com/android/inputmethod
-MAKEDICT_CORE_SRC_DIR := $(LATINIME_BASE_SRC_DIR)/latin/makedict
-LATINIME_TESTS_SRC_DIR := $(LATINIME_LOCAL_DIR)/tests/src/com/android/inputmethod/latin
-
-# Dependencies for Dicttool. Most of these files are needed by BinaryDictionary.java. Note that
-# a significant part of the dependencies are mocked in the compat/ directory, with empty or
-# nearly-empty implementations, for parts that we don't use in Dicttool.
-LATINIME_SRC_FILES_FOR_DICTTOOL := \
-        latin/BinaryDictionary.java \
-        latin/DicTraverseSession.java \
-        latin/Dictionary.java \
-        latin/NgramContext.java \
-        latin/SuggestedWords.java \
-        latin/settings/SettingsValuesForSuggestion.java \
-        latin/utils/BinaryDictionaryUtils.java \
-        latin/utils/CombinedFormatUtils.java \
-        latin/utils/JniUtils.java
-
-LATINIME_OVERRIDABLE_SRC_FILES_FOR_DICTTOOL := \
-        latin/define/DebugFlags.java \
-        latin/define/DecoderSpecificConstants.java
-
-LATINIME_TEST_SRC_FILES_FOR_DICTTOOL := \
-        utils/ByteArrayDictBuffer.java \
-        makedict/Ver2DictEncoder.java \
-        makedict/Ver4DictEncoder.java \
-        makedict/BinaryDictDecoderEncoderTests.java
-
-USED_TARGETED_SRC_FILES := \
-        $(addprefix $(LATINIME_BASE_SRC_DIR)/, $(LATINIME_SRC_FILES_FOR_DICTTOOL)) \
-        $(addprefix $(LATINIME_BASE_OVERRIDABLE_SRC_DIR)/, \
-                $(LATINIME_OVERRIDABLE_SRC_FILES_FOR_DICTTOOL)) \
-        $(addprefix $(LATINIME_TESTS_SRC_DIR)/, $(LATINIME_TEST_SRC_FILES_FOR_DICTTOOL))
-
-DICTTOOL_ONDEVICE_TESTS_DIR := \
-        $(LATINIME_LOCAL_DIR)/tests/src/com/android/inputmethod/latin/makedict/
-DICTTOOL_COMPAT_TESTS_DIR := compat
-
-LOCAL_MAIN_SRC_FILES := $(call all-java-files-under, $(MAKEDICT_CORE_SRC_DIR))
-LOCAL_TOOL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_SRC_FILES := $(LOCAL_TOOL_SRC_FILES) \
-        $(filter-out $(addprefix %/, $(notdir $(LOCAL_TOOL_SRC_FILES))), $(LOCAL_MAIN_SRC_FILES)) \
-        $(USED_TARGETED_SRC_FILES) \
-        $(call all-java-files-under, \
-                tests $(DICTTOOL_COMPAT_TESTS_DIR) $(DICTTOOL_ONDEVICE_TESTS_DIR))
-
-LOCAL_JAVA_LIBRARIES := junit-host
-LOCAL_STATIC_JAVA_LIBRARIES := jsr305lib latinime-common-host
-LOCAL_REQUIRED_MODULES := $(LATINIME_HOST_NATIVE_LIBNAME)
-LOCAL_JAR_MANIFEST := etc/manifest.txt
-LOCAL_MODULE := dicttool_aosp
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-include $(LOCAL_PATH)/etc/Android.mk
-
-# Clear our private variables
-LATINIME_DICTTOOL_AOSP_LOCAL_PATH :=
-LATINIME_LOCAL_DIR :=
-
-endif
diff --git a/tools/dicttool/NativeLib.mk b/tools/dicttool/NativeLib.mk
deleted file mode 100644
index 510f18c..0000000
--- a/tools/dicttool/NativeLib.mk
+++ /dev/null
@@ -1,46 +0,0 @@
-#
-# Copyright (C) 2013 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-# Need to define the name of the library in the caller in LATINIME_HOST_NATIVE_LIBNAME
-
-LATINIME_DIR_RELATIVE_TO_DICTTOOL := ../..
-
-ifeq ($(FLAG_DBG), true)
-    $(warning Making debug version of native library)
-    LOCAL_CFLAGS += -DFLAG_DBG -funwind-tables -fno-inline
-endif #FLAG_DBG
-
-LOCAL_CFLAGS += -DHOST_TOOL -fPIC -Wno-deprecated -Wno-unused-parameter -Wno-unused-function
-
-LATINIME_NATIVE_JNI_DIR := $(LATINIME_DIR_RELATIVE_TO_DICTTOOL)/native/jni
-LATINIME_NATIVE_SRC_DIR := $(LATINIME_DIR_RELATIVE_TO_DICTTOOL)/native/jni/src
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(LATINIME_NATIVE_SRC_DIR)
-
-include $(LOCAL_PATH)/$(LATINIME_NATIVE_JNI_DIR)/NativeFileList.mk
-
-LOCAL_SRC_FILES := \
-    $(addprefix $(LATINIME_NATIVE_JNI_DIR)/, $(LATIN_IME_JNI_SRC_FILES)) \
-    $(addprefix $(LATINIME_NATIVE_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES))
-
-LOCAL_MODULE := $(LATINIME_HOST_NATIVE_LIBNAME)
-
-include $(BUILD_HOST_SHARED_LIBRARY)
-
-# Clear our private variables
-include $(LOCAL_PATH)/$(LATINIME_NATIVE_JNI_DIR)/CleanupNativeFileList.mk
-LATINIME_DIR_RELATIVE_TO_DICTTOOL := ../..
diff --git a/tools/dicttool/compat/com/android/inputmethod/latin/define/JniLibName.java b/tools/dicttool/compat/com/android/inputmethod/latin/define/JniLibName.java
index d6d5e2d..93ac198 100644
--- a/tools/dicttool/compat/com/android/inputmethod/latin/define/JniLibName.java
+++ b/tools/dicttool/compat/com/android/inputmethod/latin/define/JniLibName.java
@@ -21,5 +21,5 @@
         // This class is not publicly instantiable.
     }
 
-    public static final String JNI_LIB_NAME = "latinime-aosp-dicttool-host";
+    public static final String JNI_LIB_NAME = "jni_latinime";
 }
diff --git a/tools/dicttool/etc/Android.mk b/tools/dicttool/etc/Android.mk
deleted file mode 100644
index 0c611b7..0000000
--- a/tools/dicttool/etc/Android.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_PREBUILT_EXECUTABLES := dicttool_aosp makedict_aosp
-include $(BUILD_HOST_PREBUILT)
diff --git a/tools/dicttool/etc/dicttool_aosp b/tools/dicttool/etc/dicttool_aosp
deleted file mode 100755
index fc918f0..0000000
--- a/tools/dicttool/etc/dicttool_aosp
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/bin/sh
-# Copyright 2011, The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Set up prog to be the path of this script, including following symlinks,
-# and set up progdir to be the fully-qualified pathname of its directory.
-prog="$0"
-while [ -h "${prog}" ]; do
-    newProg=`/bin/ls -ld "${prog}"`
-    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
-    if expr "x${newProg}" : 'x/' >/dev/null; then
-        prog="${newProg}"
-    else
-        progdir=`dirname "${prog}"`
-        prog="${progdir}/${newProg}"
-    fi
-done
-oldwd=`pwd`
-progdir=`dirname "${prog}"`
-cd "${progdir}"
-progdir=`pwd`
-prog="${progdir}"/`basename "${prog}"`
-cd "${oldwd}"
-
-classname=com.android.inputmethod.latin.dicttool.Dicttool
-jarfile=dicttool_aosp.jar
-frameworkdir="$progdir"
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
-    frameworkdir=`dirname "$progdir"`/framework
-    libdir=`dirname "$progdir"`/lib64
-fi
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
-    echo `basename "$prog"`": can't find $jarfile"
-    exit 1
-fi
-
-lib=junit.jar
-if [ ! -r "$frameworkdir/$lib" ]
-then
-    echo `basename "$prog"`": can't find lib $lib"
-    exit 1
-fi
-
-if [ "$OSTYPE" = "cygwin" ] ; then
-    jarpath=`cygpath -w  "$frameworkdir/$jarfile"`
-    libpath=`cygpath -w  "$frameworkdir/$lib"`
-    progdir=`cygpath -w  "$progdir"`
-else
-    jarpath="$frameworkdir/$jarfile"
-    libpath="$frameworkdir/$lib"
-fi
-
-# might need more memory, e.g. -Xmx128M
-exec java -ea -classpath "$libpath":"$jarpath" -Djava.library.path="$libdir" "$classname" "$@"
diff --git a/tools/dicttool/etc/makedict_aosp b/tools/dicttool/etc/makedict_aosp
deleted file mode 100755
index 095c505..0000000
--- a/tools/dicttool/etc/makedict_aosp
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2012, The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Dicttool supports making the dictionary using the 'makedict' command and
-# the same arguments that the old 'makedict' command used to accept.
-dicttool_aosp makedict $@
diff --git a/tools/dicttool/etc/manifest.txt b/tools/dicttool/etc/manifest.txt
deleted file mode 100644
index 67c8521..0000000
--- a/tools/dicttool/etc/manifest.txt
+++ /dev/null
@@ -1 +0,0 @@
-Main-Class: com.android.inputmethod.latin.dicttool.Dicttool
diff --git a/tools/make-keyboard-text/Android.bp b/tools/make-keyboard-text/Android.bp
new file mode 100644
index 0000000..4976051
--- /dev/null
+++ b/tools/make-keyboard-text/Android.bp
@@ -0,0 +1,22 @@
+//
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+java_binary_host {
+    name: "make-keyboard-text",
+
+    srcs: ["src/**/*.java"],
+    main_class: "com.android.inputmethod.keyboard.tools.MakeKeyboardText",
+    java_resource_dirs: ["res"],
+}
diff --git a/tools/make-keyboard-text/Android.mk b/tools/make-keyboard-text/Android.mk
deleted file mode 100644
index 8760148..0000000
--- a/tools/make-keyboard-text/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES += $(call all-java-files-under,src)
-LOCAL_JAR_MANIFEST := etc/manifest.txt
-LOCAL_JAVA_RESOURCE_DIRS := res
-LOCAL_MODULE := make-keyboard-text
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-include $(LOCAL_PATH)/etc/Android.mk
diff --git a/tools/make-keyboard-text/etc/Android.mk b/tools/make-keyboard-text/etc/Android.mk
deleted file mode 100644
index 0fbf4ff..0000000
--- a/tools/make-keyboard-text/etc/Android.mk
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_PREBUILT_EXECUTABLES := make-keyboard-text
-
-include $(BUILD_HOST_PREBUILT)
diff --git a/tools/make-keyboard-text/etc/make-keyboard-text b/tools/make-keyboard-text/etc/make-keyboard-text
deleted file mode 100755
index 156f9ec..0000000
--- a/tools/make-keyboard-text/etc/make-keyboard-text
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/bin/sh
-# Copyright 2012, The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Set up prog to be the path of this script, including following symlinks,
-# and set up progdir to be the fully-qualified pathname of its directory.
-prog="$0"
-while [ -h "${prog}" ]; do
-    newProg=`/bin/ls -ld "${prog}"`
-    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
-    if expr "x${newProg}" : 'x/' >/dev/null; then
-        prog="${newProg}"
-    else
-        progdir=`dirname "${prog}"`
-        prog="${progdir}/${newProg}"
-    fi
-done
-oldwd=`pwd`
-progdir=`dirname "${prog}"`
-cd "${progdir}"
-progdir=`pwd`
-prog="${progdir}"/`basename "${prog}"`
-cd "${oldwd}"
-
-jarfile=make-keyboard-text.jar
-frameworkdir="$progdir"
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
-    frameworkdir=`dirname "$progdir"`/tools/lib
-    libdir=`dirname "$progdir"`/tools/lib
-fi
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
-    frameworkdir=`dirname "$progdir"`/framework
-    libdir=`dirname "$progdir"`/lib
-fi
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
-    echo `basename "$prog"`": can't find $jarfile"
-    exit 1
-fi
-
-if [ "$OSTYPE" = "cygwin" ] ; then
-    jarpath=`cygpath -w  "$frameworkdir/$jarfile"`
-    progdir=`cygpath -w  "$progdir"`
-else
-    jarpath="$frameworkdir/$jarfile"
-fi
-
-# need to use "java.ext.dirs" because "-jar" causes classpath to be ignored
-# might need more memory, e.g. -Xmx128M
-exec java -ea -jar "$jarpath" "$@"
diff --git a/tools/make-keyboard-text/etc/manifest.txt b/tools/make-keyboard-text/etc/manifest.txt
deleted file mode 100644
index 8ad4db0..0000000
--- a/tools/make-keyboard-text/etc/manifest.txt
+++ /dev/null
@@ -1 +0,0 @@
-Main-Class: com.android.inputmethod.keyboard.tools.MakeKeyboardText