Android 从M开始Java code都是用Jack来编译了,在Android M的时候,我们可以在makefile里面添加 LOCAL_JACK_ENABLED = disabled, 来编译出可供eclipse或者Android studio使用的中间文件。
但是到了Android N开始,由于默认已经不生成.class的中间文件,只生成.jack的中间文件,所以没办法生成 classes.jar文件了,
所以从Android N开始必须在 build/ 下打上附件的patch,然后用下面的方式编译:
方式一:
首先,在 build目录打上附件的 0001-Add-targets-for-building-individual-modules-using-ja.patch
执行 make javac-check-$(LOCAL_MODULE)
如果你需要编译的module是"ABCD"的话,那就是:
make javac-check-ABCD
生成的文件 classes-full-debug.jar,会在 out\target\common\obj\JAVA_LIBRARIES\ABCD_intermediates\ 下面
classes-full-debug.jar就是可供eclipse或者Android studio使用的中间文件
patch:
From 534eea434f8cc8209888e9a076b11e6a1652e210 Mon Sep 17 00:00:00 2001
From: Paul Duffin <paulduffin@google.com>
Date: Thu, 15 Sep 2016 14:34:42 +0100
Subject: [PATCH] Add targets for building individual modules using javac
This is needed in order to be able to run error prone (which is
a plugin replacement for javac) on a subset of the java code.
Bug: 31507496
Test: Build javac-check-core-tests and check the resulting JAR
Change-Id: I5a556920572fcdad7b39d67e3f00fe0e0f1f8f46
Conflicts:
core/host_java_library.mk
core/java.mk
---
core/host_java_library.mk | 3 +++
core/java.mk | 3 +++
2 files changed, 6 insertions(+)
diff --git a/core/host_java_library.mk b/core/host_java_library.mk
index 97079fd..14992d6 100644
--- a/core/host_java_library.mk
+++ b/core/host_java_library.mk
@@ -70,6 +70,9 @@ $(full_classes_compiled_jar): \
$(LOCAL_ADDITIONAL_DEPENDENCIES)
$(transform-host-java-to-package)
+javac-check : $(full_classes_compiled_jar)
+javac-check-$(LOCAL_MODULE) : $(full_classes_compiled_jar)
+
# Run jarjar if necessary, otherwise just copy the file.
ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
diff --git a/core/java.mk b/core/java.mk
index 2602daf..d515e36 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -447,6 +447,9 @@ $(full_classes_compiled_jar): \
$(LOCAL_ADDITIONAL_DEPENDENCIES)
$(transform-java-to-classes.jar)
+javac-check : $(full_classes_compiled_jar)
+javac-check-$(LOCAL_MODULE) : $(full_classes_compiled_jar)
+
# Run jarjar if necessary, otherwise just copy the file.
ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
--
1.7.9.5
方式二:
1. 在frameworks/base下作如下修改, 把你的要编的jar 模块名字加进去
--- a/Android.mk
+++ b/Android.mk
@@ -823,7 +823,9 @@ framework_docs_LOCAL_API_CHECK_JAVA_LIBRARIES := \
icu4j \
framework \
telephony-common \
- voip-common
+ voip-common \
+ droidlogic \
+ droidlogic-tv
+++ b/Android.mk
@@ -823,7 +823,9 @@ framework_docs_LOCAL_API_CHECK_JAVA_LIBRARIES := \
icu4j \
framework \
telephony-common \
- voip-common
+ voip-common \
+ droidlogic \
+ droidlogic-tv
2. make otapackage
3. 找到 out/target/common/obj/JAVA_LIBRARIES/droidlogic_intermediates/classes.jar