1. 第一次全编译project(随机eng/user),然后保存,以取代java代码jar包,在alps/out/target/common/obj/JAVA_LIBRARIES/xxx__intermediates夹
classes.jar
javalib.jar
2. 请将以下文件保存成java_library_prebuilt.mk,并放在alps/build/core/文件夹以下:
注意:有11处须要tab键开头(make语法对命令须要tab键开头,但站点不支持tab键),请保存成文件后打开编辑,将11处(下面有标志)又一次用tab键处理一遍。
##
LOCAL_SRC_FILES :=
ifdef LOCAL_IS_HOST_MODULE
$(error $(LOCAL_PATH): Just for target java library)
endif
LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_BUILT_MODULE_STEM := javalib.jar
intermediates.COMMON := $(call local-intermediates-dir,COMMON)
full_classes_jar := $(intermediates.COMMON)/classes.jar
common_javalib.jar := $(intermediates.COMMON)/$(LOCAL_BUILT_MODULE_STEM)
LOCAL_INTERMEDIATE_TARGETS += $(full_classes_jar) $(common_javalib.jar)
ifneq (true,$(WITH_DEXPREOPT))
LOCAL_DEX_PREOPT :=
else
ifeq (,$(TARGET_BUILD_APPS))
ifndef LOCAL_DEX_PREOPT
LOCAL_DEX_PREOPT := true
endif
endif
endif
ifeq (false,$(LOCAL_DEX_PREOPT))
LOCAL_DEX_PREOPT :=
endif
include $(BUILD_SYSTEM)/base_rules.mk
$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON)
$(full_classes_jar) : $(LOCAL_PATH)/classes.jar | $(ACP)
$(call copy-file-to-target) #注意:这里必须以tab键开头
$(common_javalib.jar) : $(LOCAL_PATH)/$(LOCAL_BUILT_MODULE_STEM) | $(full_classes_jar) $(ACP)
$(call copy-file-to-target) #注意:这里必须以tab键开头
ifdef LOCAL_DEX_PREOPT
dexpreopt_boot_jar_module := $(filter $(LOCAL_MODULE),$(DEXPREOPT_BOOT_JARS_MODULES))
ifneq ($(dexpreopt_boot_jar_module),)
dexpreopted_boot_jar := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module)_nodex.jar
$(LOCAL_BUILT_MODULE) : $(dexpreopted_boot_jar) | $(ACP)
$(call copy-file-to-target) #注意:这里必须以tab键开头
dexpreopted_boot_odex := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module).odex
built_odex := $(basename $(LOCAL_BUILT_MODULE)).odex
$(built_odex) : $(dexpreopted_boot_odex) | $(ACP)
$(call copy-file-to-target) #注意:这里必须以tab键开头
else
built_odex := $(basename $(LOCAL_BUILT_MODULE)).odex
$(built_odex): PRIVATE_MODULE := $(LOCAL_MODULE)
$(built_odex) : $(DEXPREOPT_BOOT_ODEXS)
$(built_odex) : $(common_javalib.jar) | $(DEXPREOPT) $(DEXOPT)
@echo "Dexpreopt Jar: $(PRIVATE_MODULE) ([email protected])" #注意:这里必须以tab键开头
$(hide) rm -f [email protected] #注意:这里必须以tab键开头
@mkdir -p $(dir [email protected]) #注意:这里必须以tab键开头
$(call dexpreopt-one-file,$<,[email protected]) #注意:这里必须以tab键开头
$(LOCAL_BUILT_MODULE) : $(common_javalib.jar) | $(ACP) $(AAPT)
$(call copy-file-to-target) #注意:这里必须以tab键开头
ifneq (nostripping,$(LOCAL_DEX_PREOPT))
$(call dexpreopt-remove-classes.dex,[email protected]) #注意:这里必须以tab键开头
endif
endif
else
$(LOCAL_BUILT_MODULE) : $(common_javalib.jar) | $(ACP)
$(call copy-file-to-target) #注意:这里必须以tab键开头
endif
3. 在alps/build/core/config.mk里加入:
BUILD_JAVA_LIBRARY_PREBUILT:= $(BUILD_SYSTEM)/java_library_prebuilt.mk
4. 删除相应的java代码及相应的Android.mk,然后在当前文件夹创建新的Android.mk。并复制第1步备份的2仅仅文件到Android.mk旁边(注意。文件名称不能改动,否则无法识别!!!),新的Android.mk编写例如以下:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := services
LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)
include $(BUILD_JAVA_LIBRARY_PREBUILT)
5. 又一次完整的编译project(随意eng/user),下载查看效果
6. 重要提示,因为第1步保存的classes.jar是没有经过proguard。流出去非常easy被反编译,请做自己proguard,但请不要把接口proguard,否则编译失败!
版权声明:本文博客原创文章。博客,未经同意,不得转载。