欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Jack Server--Android N AOSP编译--Failed to contact Jack server

程序员文章站 2024-03-25 08:35:52
...
准备

今天正式担任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来对我们的系统进行整编译了。

这里写图片描述

如图,我们打开$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文件:
这里写图片描述
2.修改$HOME路径下的.jack-settings文件:
这里写图片描述
(注:此处两个文件的TCP端口号必须是没有用过的,且两个文件的端口配置要相同!)
3.jack-admin kill-server
4.jack-admin uninstall-server
5.cd prebuilts/sdk/tools->touch jack
6.jack-admin restart-server

OK!大功告成!


以上内容转载自:https://blog.csdn.net/xz10561/article/details/53886691

----------------------------------------------------------------------------------------------------------------------


背景

很多人在开发中,拉下一套新的代码会出现下列错误:

1.Failed to contact Jack server;
2.No Jack Server running;//jack server 被kill

这是由于Android7.0 采用Jack编译,不支持多人同时在线编译。出现了端口占用问题。

不明白Jack 编译的小伙伴可以看下我的这篇BLOG :

http://blog.csdn.net/Simon_Crystin/article/details/62426402

解决方法

下面就给出详细的解决方案:

我们需要做的就是改端口。

正常情况下,Android7.0(N)编译会出错三次。编译一次生成一个新的文件,下面就带领大家来爬坑。

第一次编译报错:
会在你的根目录生成一个 .jack-settings文件 (隐藏文件,如果在根目录找不到的话,请设置为显示隐藏文件)

进入修改端口:

给出修改后的结果:

Jack Server--Android N AOSP编译--Failed to contact Jack server

这里有两点需要注意
1:默认两个端口是8076和8077,你改成和别人不一样的;
2:port是在0-65536范围设置,0-1024最好不要用,通常是熟知端口

改完了之后,你再去编译,这个时候又会报错;

第二次编译报错:
会在根目录下的 .jack-server下生成一个config.properties文件
给出修改后的结果:
Jack Server--Android N AOSP编译--Failed to contact Jack server

注意:这里的修改要和上面一致。

完成了这一步,然后继续编译,又会报错:
No Jack Server running;

这个时候在.jack-server文件夹下执行 ls-al
查看文件的权限:
如图:
Jack Server--Android N AOSP编译--Failed to contact Jack server

我们可以看到config.properties权限为rwx,,意思是可读,可写,可执行。我们需要把x权限删除。至于为什么要把x权限删除呢?jack-server里面的log说的很清楚:

config.properties must have permission rw ------- but have rwx------

Jack Server--Android N AOSP编译--Failed to contact Jack server

再执行ls-al 就可以看到修改成功了。(这个是linux权限管理,不懂得可以去了解下。)

再编译,应该就可以成功了。

反正端口占用的解决方案就是这样的,你看你到了第几步,直接执行下一步就好了。


以上内容转自:https://blog.csdn.net/Simon_Crystin/article/details/70059457

-------------------------------------------------------------------------------------------------------------



以下内容为个人总结:

1.Jack server是Android N特有编译工具,在编译系统源码时使用make命令会自启动,如果没有install还会去安装

2.Jack server的命令工具在prebuilt/sdk/tools:

去到脚本所在路径cd prebuilt/sdk/tools

安装Jack server:./jack-admin install-server jack-launcher.jar jack-server-4.8.ALPHA.jar

卸载Jack server:./jack-admin uninstall-server

启动Jack server:./jack-admin start-server

杀死jack server进程:./jack-admin kill-server

3.install会自动安装在用户的根目录中的.jack-server文件夹中,自动生成.jack、.jack-settings文件,.jack-server中的文件如下图:

Jack Server--Android N AOSP编译--Failed to contact Jack server

其中红圈的两个文件是在Jack server启动成功后才会生成

4.在发生跟Jack server 有关的错误后,首先可以去看log,在.jack-server/logs/下。

5.如果提示Caused by: java.net.BindException: Address already in use,则表示端口被占用,很可能是同一服务器中其他用户也启动了Jack server,而默认Jack server使用的TCP端口是一样的,所以此时要去改端口。前面已经说到的.jack、.jack-settings、./jack-server/config.properties中端口,改成一致。

6.被多用户使用的系统使用Jack-server必须重新配置端口。如果不重新配置的话,那么一个人使用时,另外一人需要./jack-admin kill-server。

7.编译低于7.0的AOSP时,需要把Jack server杀死,即执行./jack-admin kill-server,否则会编译报错。