Copy multiple txt files in /system using Android.mk

倖福魔咒の 提交于 2019-12-03 05:17:53

问题


Aim : I want to copy multiple txt files in /system ( of Android Device ) using Android.mk

My Findings :

We can copy file using two approach 1) Use PRODUCT_COPY_FILES. This is done from devices/ / makefile.mk

ex:

PRODUCT_COPY_FILES := \
  frameworks/base/data/etc/telephony.gsm.xml:system/etc/permissions/telephony.gsm.xml \
  some/other/sourc/file:some/destination \
  some/other/sourcefile2: some/destination

2) Using BUILD_PREBUILD

ex :

##############copy txt file##################
include $(CLEAR_VARS)
#LOCAL_MODULE := mydata.txt
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT)/myfolder
LOCAL_SRC_FILES := mydata.txt
include $(BUILD_PREBUILT)

for above to work make entry of mydata.txt in build/target/product/core.mk

My Specific Query is : Now i can copy multiple files using 2nd approach by re-writing the above code one after the other. But i want to use 2nd approach (BUILD_PERBUILD ) to copy multiple txt files without re-writing code for all files.

1) Can i do that with just one include $(BUILD_PREBUILT) call ?

2 )Can BUILD_MULTI_PREBUILD be used to solve the purpose? how ?


回答1:


Ok, I found one hack ( which i knew exists ) ,which i was not looking for but it worked and solved my problem in a very simple way.

You can run shell commands in mk file.

So if you want to copy multiple files just in a single go use following code and place it in your mk file.

In following scenario the files i need to copy are present in file_folder ( directory ) , which is in same directory where my mk file is. And i wan to copy all the files present in file_folder to system/file_folder.

#create a directory in /system/
    $(shell mkdir -p $(TARGET_OUT)/file_folder/)
#copy stuff
    $(shell cp $(LOCAL_PATH)/file_folder/* `pwd`/$(TARGET_OUT)/file_folder/)

This worked fine. So now in all we have 3 ways to do it. Hope it will help someone like me.




回答2:


See the following example in Android font handling: https://android.googlesource.com/platform/frameworks/base/+/master/data/fonts/Android.mk#66

This creates a makefile function for a single font file, and uses a foreach loop to iterate over multiple files: https://android.googlesource.com/platform/frameworks/base/+/master/data/fonts/Android.mk#79

You can use any mechanism to populate font_src_files



来源:https://stackoverflow.com/questions/14380357/copy-multiple-txt-files-in-system-using-android-mk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!