Android7.0成长之路---新特性Jack server

准备

今天正式担任Android7.0(N)项目模块的开发和维护工作,借此机会git和make了一套系统代码用来研究。在编译的过程中,与以往系统不同的是Android7.0系统编译工具链使用了全新的Jack server来取代以往的编译器工具,所以在编译的过程中可能出现一些小问题,后面将为大家总结介绍!

Jack server

一、介绍

我们先来看一下关于Jack server官方介绍:

  Jack is a new Android toolchain that compiles Java source into Android dex bytecode. It replaces the previous Android toolchain, which consists of multiple tools, such as javac, ProGuard, jarjar, and dx.

Jack编译器工具是一套新的Android编译工具用来将Java代码转换为Android dex字节代码。

二、Jack server优点

1.适用于AOSP,意思就是说这套编译器是开源的,开发者也可以为其进行完善。
2.Jack server能够减少编译的时间
3.使用第三方包例如ProGuard将不在是必要的。

三、.jack库文件介绍

Jack拥有其自己的文件格式,即为:.jack。此文件包含了预编译dex代码的一些库文件,使得在预编译的过程中变的更快。

四、Jill工具

从官方的介绍中可以看到,Jill还处于Jack编译器之前,它的用处是用来将已存在的.jar库转换成一种新格式的库文件格式Jayce用来适配编译器Jack。

五、Jack编译(重点)

当我们了解了Jack server这一个在Android7.0的新特性后,我们接下来就可以使用Jack来对我们的系统进行整编译了。

Android7.0成长之路---新特性Jack server_第1张图片

如图,我们打开$HOME路径下的.jack文件,看到的是如下参数:

SERVER=true 开启jack server.

SERVER_PORT_SERVICE=8072 设置TCP服务器端口号用来进行汇编编译

SERVER_PORT_ADMIN=8073 设置TCP服务器端口号用来管理员的编译管理

SERVER_COUNT=1 当前未使用,一般为默认

SERVER_NB_COMPILE=4 同时编译最大线程

SERVER_TIMEOUT=60 如果server没有在60s内没有反应,那么将会关掉此服务

SERVER_LOG=${SERVER_LOG:=$SERVER_DIR/jack-$SERVER_PORT_SERVICE.log} Log输出的位置

JACK_VM_COMMAND=${JACK_VM_COMMAND:=java} 启动JVM命令

Jack编译遇到的问题—Failed to contact Jack server

如果你在编译的过程中,出现了如下的问题:

warning: string 'bluetooth_map_email_settings_app_icon' has no default translation.
warning: string 'bluetooth_map_email_settings_cancel' has no default translation.
warning: string 'bluetooth_map_email_settings_count' has no default translation.
warning: string 'bluetooth_map_email_settings_intro' has no default translation.
warning: string 'bluetooth_map_email_settings_no_account_slots_left' has no default translation.
warning: string 'bluetooth_map_email_settings_save' has no default translation.
warning: string 'bluetooth_map_email_settings_title' has no default translation.
warning: string 'bluetooth_share_file_name' has no default translation.
warning: string 'incoming_file_confirm_Notification_caption' has no default translation.
warning: string 'incoming_file_toast_msg' has no default translation.
warning: string 'map_acceptance_timeout_message' has no default translation.
warning: string 'map_auth_notif_message' has no default translation.
warning: string 'map_auth_notif_ticker' has no default translation.
warning: string 'map_auth_notif_title' has no default translation.
warning: string 'map_authentication_timeout_message' has no default translation.
warning: string 'map_defaultname' has no default translation.
warning: string 'map_defaultnumber' has no default translation.
warning: string 'map_localPhoneName' has no default translation.
warning: string 'map_session_key_dialog_header' has no default translation.
warning: string 'map_session_key_dialog_title' has no default translation.
warning: string 'map_unknownName' has no default translation.
warning: string 'noti_caption' has no default translation.
warning: string 'permdesc_handoverStatus' has no default translation.
warning: string 'permlab_handoverStatus' has no default translation.
warning: string 'process' has no default translation.
warning: string 'sharedUserId' has no default translation.
[ 33% 13407/40165] Aidl: mediatek-framework <= vendor/mediatek/proprietary/frameworks/base/camera/mmsdk/java/com/mediatek/mmsdk/IMMSdkService.aidl
[ 33% 13408/40165] Aidl: mediatek-framework <= vendor/mediatek/proprietary/frameworks/base/camera/mmsdk/java/com/mediatek/mmsdk/IFeatureManager.aidl
[ 33% 13409/40165] Aidl: mediatek-framework <= vendor/mediatek/proprietary/frameworks/base/camera/mmsdk/java/com/mediatek/mmsdk/IEffectFactory.aidl
[ 33% 13410/40165] Aidl: mediatek-framework <= vendor/mediatek/proprietary/frameworks/base/camera/mmsdk/java/com/mediatek/mmsdk/IEffectHalClient.aidl
[ 33% 13411/40165] Aidl: mediatek-framework <= vendor/mediatek/proprietary/frameworks/base/camera/mmsdk/java/com/mediatek/mmsdk/IEffectHal.aidl
[ 33% 13412/40165] Aidl: mediatek-framework <= vendor/mediatek/proprietary/frameworks/base/camera/mmsdk/java/com/mediatek/mmsdk/IEffectListener.aidl
[ 33% 13413/40165] Protoc: out/target/common/obj/JAVA_LIBRARIES/sap-api-java-static_intermediates/src/proto/Proto.stamp <= hardware/ril/librilutils/proto/sap-api.proto
[ 33% 13414/40165] Aidl: android-support-v4 <= frameworks/support/v4/java/android/support/v4/media/session/IMediaSession.aidl
[ 33% 13415/40165] Aidl: android-support-v4 <= frameworks/support/v4/java/android/support/v4/os/IResultReceiver.aidl
[ 33% 13416/40165] Aidl: android-support-v4 <= frameworks/support/v4/java/android/support/v4/media/session/IMediaControllerCallback.aidl
[ 33% 13417/40165] Aidl: android-support-v4 <= frameworks/support/v4/java/android/support/v4/app/INotificationSideChannel.aidl
[ 33% 13418/40165] Export includes file:  -- out/target/product/tb6580p2_gmo512m_p/obj/SHARED_LIBRARIES/libja3m_intermediates/export_includes
[ 33% 13419/40165] Protoc: out/host/linux-x86/gen/STATIC_LIBRARIES/libaapt2_intermediates/proto/frameworks/base/tools/aapt2/Format.pb.cc <= frameworks/base/tools/aapt2/Format.proto
[ 33% 13420/40165] Updated header file out/host/linux-x86/gen/STATIC_LIBRARIES/libaapt2_intermediates/proto/frameworks/base/tools/aapt2/Format.pb.h.
[ 33% 13421/40165] Export includes file: out/host/linux-x86/gen/STATIC_LIBRARIES/libaapt2_intermediates/proto/frameworks/base/tools/aapt2/Format.pb.h -- out/host/linux-x86/obj/STATIC_LIBRARIES/libaapt2_intermediates/export_includes
[ 33% 13422/40165] Import includes file: out/host/linux-x86/obj/EXECUTABLES/aapt2_intermediates/import_includes
[ 33% 13423/40165] Ensure Jack server is installed and started
FAILED: /bin/bash -c "(prebuilts/sdk/tools/jack-admin install-server prebuilts/sdk/tools/jack-launcher.jar prebuilts/sdk/tools/jack-server-4.8.ALPHA.jar  2>&1 || (exit 0) ) && (JACK_SERVER_VM_ARGUMENTS=\"-Dfile.encoding=UTF-8 -XX:+TieredCompilation\" prebuilts/sdk/tools/jack-admin start-server 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update server prebuilts/sdk/tools/jack-server-4.8.ALPHA.jar 4.8.ALPHA 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-2.28.RELEASE.jar 2.28.RELEASE || exit 47; prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-3.36.CANDIDATE.jar 3.36.CANDIDATE || exit 47; prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-4.7.BETA.jar 4.7.BETA || exit 47 )"
Writing client settings in /home/user3/.jack-settings
Installing jack server in "/home/user3/.jack-server"
Communication error with Jack server (58), try 'jack-diagnose' or see Jack server log
Failed to contact Jack server: Problem reading /home/user3/.jack-server/client.pem. Try 'jack-diagnose'
Failed to contact Jack server: Problem reading /home/user3/.jack-server/client.pem. Try 'jack-diagnose'
[ 33% 13423/40165] host C++: aapt2 <= frameworks/base/tools/aapt2/Main.cpp
[ 33% 13423/40165] host C++: dexdump2 <= art/dexdump/dexdump.cc
[ 33% 13423/40165] Compiling SDK Stubs: out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/classes.jar
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
ninja: build stopped: subcommand failed.
make: *** [ninja_wrapper] Error 1

注意!此处为解决问题的关键:

Communication error with Jack server (58), try 'jack-diagnose' or see Jack server log

Failed to contact Jack server: Problem reading /home/user3/.jack-server/client.pem. Try 'jack-diagnose'

此问题是在于Android N新特性中,将同一个使用过的TCP端口将视为唯一,所以遇到这种情况下需要修改两处文件。具体步骤如下:
1.修改$HOME路径下的.jack文件:
Android7.0成长之路---新特性Jack server_第2张图片
2.修改$HOME路径下的.jack-settings文件:
Android7.0成长之路---新特性Jack server_第3张图片
(注:此处两个文件的TCP端口号必须是没有用过的,且两个文件的端口配置要相同!)
3.jack-admin kill-server
4.jack-admin uninstall-server
5.cd prebuilts/sdk/tools->touch jack
6.jack-admin restart-server

OK!大功告成!

你可能感兴趣的:(Android)