分类: Android平台
2018-05-12 11:49:25
一、问题
MTK5658方案,源码下载后,第一次编译报错停止,不要make clean,直接再编译一次却可以正常编译。
就是说新下载的代码第一次会报错,之后就不会了。
编译错误,有如下信息
out/host/linux-x86/bin/jack: line 66: SETTING_VERSION: unbound variable Writing client settings in /home/kangde/.jack-settings No Jack server running. Try 'jack-admin start-server' 1 error during configuration. Try --help-properties for help.
####################################################### Build: Android_Body Fail [X] encoder->protected_->state = FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; fprintf(stderr, "Error allocating temporary storage for tim sort: need %lu bytes", sizeof(SORT_TYPE) * new_size); PROMPT_NONE, PR_FATAL }, PROMPT_NONE, PR_FATAL }, PROMPT_NONE, PR_FATAL }, PROMPT_NONE, PR_FATAL }, PROMPT_NONE, PR_FATAL }, PROMPT_NONE, PR_FATAL }, PROMPT_NONE, PR_FATAL }, PROMPT_NONE, PR_FATAL }, make[1]: *** [ninja_wrapper] Error 1 CHK LOG sh: -c: line 0: unexpected EOF while looking for matching `'' sh: -c: line 1: syntax error: unexpected end of file sh: -c: line 0: unexpected EOF while looking for matching `'' sh: -c: line 1: syntax error: unexpected end of file
二、修改
1、一开始以为SETTING_VERSION没设置导致的错误,调试过后,觉得应该是jack server没有正常启动导致的。
vi prebuilts/sdk/tools/jack-admin 把 SERVERS_PID=$(ps -A -o "pid args" -u `id -u -n` | grep $LAUNCHER_NAME| grep -v grep | awk '{print $1}') 改为 SERVERS_PID=$(ps -A -o "pid args" -u `id -u -n` | grep $LAUNCHER_NAME |grep $JACK_HOME | grep -v grep | awk '{print $1}')
|grep $JACK_HOME 加这句话的话,jack-admin kill-server只杀死自己的启动的jack server,不加的话,会去杀死其他用户的jack server,当然,没有权限杀死,只是不会报错退出而已。
clean掉代码,或者新下载的代码,第一次编译还是会报错。
2、接着查看log报错的提示,总是一个模块最先报错,这个模块是编译jar包的模块,这个jar包编译自定义的framework资源。
在该模块Android.mk改动,如下
LOCAL_REQUIRED_MODULES := \
framework \
再编译,可以了。
三、注意
1、另外Android.mk加依赖规则,用add-dependency这个好像无效
$(call add-dependency(modules_a,modules_b))
改为下面才成功。
LOCAL_REQUIRED_MODULES := \
framework \
2、关于LOCAL_NO_STANDARD_LIBRARIES := true
系统根据Android.mk编译jar包,默认会自动找需要的系统jar包,而自定义的jar包用LOCAL_JAVA_LIBRARIES指明。
如果设置LOCAL_NO_STANDARD_LIBRARIES := true的话,就要手动写依赖的jar包了。无论是系统的还是用户自己的。
以上只是经验,仅供参考。
=============================================================================================
20180512再次修改
一、博客发完后, 发现第一编译又错了。再次修改,如下
#第一次编译错误,引起这么诡异的事,就是这个LOCAL_INTERMEDIATE_SOURCES变量引起的,它依赖了外部的R.java文件,所以编译方式不一样,不能直接include $(BUILD_JAVA_LIBRARY)
framework_tvos_res_source_path := APPS/tvos-framework-res_intermediates/src LOCAL_INTERMEDIATE_SOURCES += $(framework_tvos_res_source_path)/tvos/R.java # $(framework_tvos_res_source_path)/tvos/Manifest.java LOCAL_REQUIRED_MODULES := \ framework \ tvos-framework-res # 20180511 代码下载后,第一次编译错误 start # 编译这个jar包,不能直接include $(BUILD_JAVA_LIBRARY)就完事。设置LOCAL_NO_STANDARD_LIBRARIES := true,这个设置后,所依赖的jar和所以依赖的目标要自己写,写法,如下
LOCAL_NO_STANDARD_LIBRARIES := true
# 指明所依赖的所有jar包 LOCAL_JAVA_LIBRARIES := core-oj core-libart core-lambda-stubs conscrypt okhttp core-junit bouncycastle ext LOCAL_JAVA_LIBRARIES += framework include $(BUILD_JAVA_LIBRARY) android_tclwidget_module := $(LOCAL_INSTALLED_MODULE) # 下面是最核心的地方,请参考frameworks/base/Android.mk,看里面是怎么编译framework.jar,这个也是参考那个写。
# 里面一段重要的话,如下
# We have a special case here where we build the library's resources
# independently from its code, so we need to find where the resource
# class source got placed in the course of building the resources.
# Thus, the magic here.
# Also, this module cannot depend directly on the R.java file; if it
# did, the PRIVATE_* vars for R.java wouldn't be guaranteed to be correct.
# Instead, it depends on the R.stamp file, which lists the corresponding
# R.java file as a prerequisite.
# TODO: find a more appropriate way to do this.
# 它依赖外部的R.java,但是依赖规则又不能直接依赖R.java,要依赖R.stamp
# Make sure that R.java and Manifest.java are built before we build # the source for this library. tvos_framework_res_R_stamp := \ $(call intermediates-dir-for,APPS,tvos-framework-res,,COMMON)/src/R.stamp $(full_classes_compiled_jar): $(tvos_framework_res_R_stamp) $(built_dex_intermediate): $(tvos_framework_res_R_stamp) $(android_tclwidget_module): | $(dir $(android_tclwidget_module))tvos-framework-res/tvos-framework-res.apk android_tclwidget_built := $(call java-lib-deps,android.tclwidget) # 20180511 代码下载后,第一次编译错误 end
二、另外再补充,
$(call add-dependency(modules_a,modules_b))这种写法语法错误,被前面写makefile的人带沟里去了,
正确的语法应该是$(call add-dependency,modules_a,modules_b)
call的语法是$(call VARIABLE,PARAM,PARAM,...),是用逗号分隔的,不是用括号。
还有,就算是改正语法错误,也是不行的,Android.mk正确的写法应该按照我上面改正后的写法。