I need to add the timetest directory's executable to the system.img file so that I can access the command from the shell. The location is at : https://android.googlesource.com/platform/system/extras/+/android-4.4.4_r1/tests/timetest/. So what I did was to go into the timetest directory and issue the following command:
mm snod
The output was as follows:
PRODUCT_COPY_FILES device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml ignored.
make: Entering directory `/home/username/android_built/android'
target thumb C: timetest <= frameworks/base/cmds/timetest/timetest.c
target StaticExecutable: timetest (out/target/product/hammerhead/obj/EXECUTABLES/timetest_intermediates/LINKED/timetest)
target Symbolic: timetest (out/target/product/hammerhead/symbols/sbin/timetest)
target Strip: timetest (out/target/product/hammerhead/obj/EXECUTABLES/timetest_intermediates/timetest)
Install: out/target/product/hammerhead/root/sbin/timetest
make: Leaving directory `/home/username/android_built/android'
The file installation part has been left out for clarity.
The following output is after I tried copying the timetest into frameworks/base/cmds as detailed in this question : android AOSP, adding new executable [.c] code. I also tried it directly.
I then looked at the entire phone including the xbin,bin directories . I also used find / -name "timetest", but the executable is nowhere to be found. What am I doing wrong?
I'm not actually sure how you are installing timetest to your device, but if you are just adb pushing the result to your device then you will likely have a hard time running that.
If you look at the Android.mk file for timetest you will see that it is labeled as "optional"
LOCAL_MODULE_TAGS := optional
However after grepping through all the make files, there is no build variant which includes this in a build. If you have your own device make file you can add it there, but if you just want to make this work quickly you can add it to the list of PRODUCT_PACKAGES in the build/target/product/core_minimal.mk file. There will be a list that looks something like:
PRODUCT_PACKAGES += \
BackupRestoreConfirmation \
DownloadProvider \
HTMLViewer \
MediaProvider \
Just add timetest into that list. After that do a make installclean and rebuild your device and you should have timetest included in sbin.
Related
I'm making Marshmallow AOSP rom and trying to add device_owner.xml to /data/system to provisioning application directly to device owner.
I have added one of .mk files following product copy files
PRODUCT_COPY_FILES += abc/cba:data/system/device_owner.xml
file can be found under out/data/system/ but it doesn't seem to be included to the rom.
I have also tried to replace PRODUCT_COPY_FILES with
PRODUCT_PACKAGES += device_owner.xml
and made own Android.mk file for the file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE = device_owner.xml
LOCAL_SRC_FILES = $(LOCAL_MODULE)
LOCAL_MODULE_CLASS = ETC
LOCAL_MODULE_PATH = $(TARGET_OUT_DATA)/system
include $(BUILD_PREBUILT)
still it's not include on rom.
i have read that data partition would be part of the userdata.img but file is not there either.
I have tried also to include device_owner.xml to different location like under /system/ and then copy it in init.rc file under post-fs-data phase
copy /system/abc/device_owner.xml /data/system/device_owner.xml
chown system system /data/system/device_owner.xml
chmod 0600 /data/system/device_owner.xml
File will be then correct location but for some reason chown command doesn't change owner and group to system. by default file has root owner and group.
Any idea how this could be done?
EDIT 1.
I have now made one solution for this.
I have made set_device_owner.sh file where i have
#!/system/bin/sh
chown system:system /data/system/device_owner.xml
chmod 0600 /data/system/device_owner.xml
then i added one of .mk files following product copy files
PRODUCT_COPY_FILES += abc/cba/device_owner.xml:/system/xbin/device_owner.xml
PRODUCT_COPY_FILES += abc/cba/set_device_owner.sh:/system/xbin/set_device_owner.sh
and in init.rc i have under post-fs-data
copy /system/xbin/device_owner.xml /data/system/device_owner.xml
exec - root root -- /system/bin/sh ./system/xbin/set_device_owner.sh
Now this works but i would still like to know what would be correct or preferable way of doing it.
And i don't know why that copy and chown and chmod didn't work directly on init.rc
The AOSP build process cannot put files into the data directory, so I believe your solution is the correct one. You'll see that init.rc actually creates the data directory, and also doing a factory reset will clear /data. So as far as I can tell, there's no other good way to do this and nothing really wrong with your approach.
The chmod command should work directly in the init.rc file though, not sure why it's not working for you, it's used multiple times elsewhere in the file.
I just implemented this myself, and was able to do it without using a separate script. Here are the lines I added to my init.rc file at the end of the post-fs-data section:
copy /system/device_owner.xml /data/system/device_owner.xml
copy /system/device_policies.xml /data/system/device_policies.xml
chmod 0600 /data/system/device_owner.xml
chmod 0600 /data/system/device_policies.xml
chown system system /data/system/device_owner.xml
chown system system /data/system/device_policies.xml
Note that I have PRODUCT_COPY_FILES in my device config to copy the files to /system on build, or this obviously wouldn't work.
Also to prevent the message to the user about immersive mode that shows up the first time your app launches, you can add your package id to the def_immersive_mode_confirmations section in packages/SettingsProvider/res/values/default.xml using a device overlay. More info on that here: How does the Android source overlays work?. Though for whatever reason, although I appear to have my overlay setup correctly, it still shows the message and I don't have time to debug it right now as I've found most "simple" things with AOSP somehow just don't work and then eat up entire days figuring out the random thing I'm doing wrong... When I figure it out, I'll edit this answer confirming it works.
EDIT: So turns out the overlay works fine. It's the documentation that's wrong... To disable the warning, use the value confirmed for the def_immersive_mode_confirmations section in packages/SettingsProvider/res/values/default.xml
Here's the issue tracker post about it: https://issuetracker.google.com/issues/37093452#c1
So you actually need this:
<string name="def_immersive_mode_confirmations" translatable="false">confirmed</string>
I have multiple static libs that are built using jni. I have a scheme that includes other mk files, etc to allow me to share compile settings, include files from other dependent projects, etc.
I have set it up successfully on the mac and have been building it. However, when I tried to do the same in windows under cygwin I'm running into issues...
Here is my jni/Android.mk file..
LOCAL_PATH := $(call my-dir)
INJ_PROJECT_PATH := $(PWD)
include $(INJ_PROJECT_PATH)/jni/Project.mk
The problem I'm seeing is that ndk-build is complaining about the Project.mk file. Here is what I'm seeing..
shammi#SHAMMIDEV /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core
$ ndk-build.cmd NDK_APP_OUT=../../build/Android/Engine/release
jni/Android.mk:5: /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk: No such file or directory
jni/Android.mk:5: /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk: No such file or directory
jni/Android.mk:5: /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk: No such file or directory
jni/Android.mk:5: /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk: No such file or directory
C:/projects/Android/sdk/ndk-bundle/build//../build/core/build-all.mk:89: Android NDK: WARNING: There are no modules to build in this project!
make: *** No rule to make target `/cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk'. Stop.
I have confirmed that /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk does exist, and I am the owner and it has read permissions for user/group/other.
Again, this exact same setup works absolutely fine on the mac. I'm just looking at having a portable dev environment.
What am I missing here..?
I guess I forgot that ndk-build.cmd was a windows shell batch script (DOH).
The answer was that I was able to call /build/ndk-build which is a sh script that is comfortable running in cygwin.
You probably need to use LOCAL_PATH instead of PWD. I'm not really sure how PWD gets set (I think it's a make builtin?), but we actually have control over LOCAL_PATH and can make sure it gets set in the right way for cygwin.
Instead of include what if you define it to be APP_BUILD_SCRIPT?
for ex.
APP_BUILD_SCRIPT := jni/Android.mk
Also Id try $(shell $pwd) instead of $(PWD) if the above doesn't work, usually ndk doesn't interpret shell commands for me if I don't use the shell in the parenthesis.
I have following AOSP project setup
1) I have test.cpp in (AOSP root directory)/vendor/myProject/test.cpp
2) In Android.mk i have used
LOCAL_CFLAGS += -g -fprofile-arcs -ftest-coverage
LOCAL_LDFLAGS += -lgcov
3) When I compile the code i get test.gcno in:
(AOSP root directory)/out/target/product/generic/obj/EXECUTABLES/myProject_intermediates
4) Then i put the test on device (adb sync)
5) Then on device i have used following:
export GCOV_PREFIX=/vendor
export GCOV_PREFIX_STRIP=13 (to strip down the un-necessary path)
6) I run the test ./system/bin/test and i get test.gcda file on
device (shell) /vendor/test.gcda
7) I copy the test.gcda (from device) to my build directory (/out/target/product/generic/obj/EXECUTABLES/myProject_intermediates) where i already have test.gcno
8) Now i am in /out/target/product/generic/obj/EXECUTABLES/myProject_intermediates
Then run gcov as follows:
(AOSP root
directory)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcov
test
For this i get output as follows:
File 'vendor/myProject/test.cpp' Lines executed:23.00% of 223
vendor/myProject/test.cpp:creating 'test.cpp.gcov'
vendor/myProject/test.cpp:cannot open source file
Can anybody help me on how to solve this. It says test.cpp:cannot open source file
gcov is not generating complete report. I have also checked -b option by specifying the path to source as follows:
(AOSP root
directory)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcov
-b (AOSP root directory)/vendor/myProject test
It didn't worked.
I guess the problem is because of distributed files (gcno,gcda,test.cpp) in different directories.
Thanks
Solution is while building the test in which directory you were, you should be in the same directory while running gcov later, then all the .gcov files will be created successfully.
For example:
Project directory : android/frameworks/Myproj
In this you have test.cpp and Android.mk
Then say suppose from android directory you'll build the app or test.cpp, i.e. android$
Then the *.gcno files will be present in android/out/Myproj_Intermediates/
You will get the *.gcda files by running app in device, you will bring that *.gcda files from device to folder android/out/Myproj_intermediates/
Now to run gcov on these:
You should be in the android directory (since you built app from there)
android$ ./prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-gcov \
-o out/Myproj_intermediates/ -a frameworks/Myproj/test.cpp -b -c
There has been a better approach in AOSP for several months now.
Add LOCAL_NATIVE_COVERAGE := true to your makefile.
$ export NATIVE_COVERAGE := true
Build, sync, run.
$ acov
acov will pull all the coverage files off the device, put them in the right place, and lcov (iirc this will prompt you to install if you don't already have it), and generate and HTML report for you.
I have glibc compiled for arm which is different from Android glibc or the bionic C as the glibc environment I have complied will help in providing more api's.
Now I can copy the glibc environment on /system/ folder while Android is running, and on doing chroot I can run my programs on glibc environment.
Currently I am compiling glibc and Android separately and then tarring the glibc and copying it on Android emulator sdcard and then untarring it on /system folder and then doing chroot on /system/glibc
I compile glibc separately and then place it somewhere in Android source code.
Now while compiling Android source, what should I do so that the entire prebuilt folder structure of glibc gets copied to /system folder and become part of part of system.img.
With this when I copy the system.img to Android emulator and launch it, glibc is already present in /system folder and just need to run the apps in glibc environment.
UPDATE
after I did as per Yuri mentioned in his answer (I created glibc folder and copied everything into it), when I compile the code I get below output.
build/core/main.mk:490: * Some files have been added to ALL_PREBUILT.
build/core/main.mk:491: *
build/core/main.mk:492: * ALL_PREBUILT is a deprecated mechanism that
build/core/main.mk:493: * should not be used for new files.
build/core/main.mk:494: * As an alternative, use PRODUCT_COPY_FILES in
build/core/main.mk:495: * the appropriate product definition.
build/core/main.mk:496: * build/target/product/core.mk is the product
build/core/main.mk:497: * definition used in all products.
build/core/main.mk:498: *
build/core/main.mk:499: * unexpected glibc in ALL_PREBUILT
build/core/main.mk:500: *
build/core/main.mk:501: * ALL_PREBUILT contains unexpected files. Stop.
So I added glibc in build/core/legacy_prebuilts.mk
But then I get
make: * No rule to make target mkdir', needed byout/target/product/generic/root/glibc'. Stop.
Finally I did it in a very unusual way.
I had 3 options:
Use BUILD_PREBUILT variable, but drawback it you can do it for a
single file, but I had multiple files and in a particular forlder
structure
Use PRODUCT_COPY_FILES. But somehow it was not working for me
PRODUCT_COPY_FILES is for a device, and it was not a new device for
me. I was working on emulator.
Using the solution given by Yuri, using ALL_PREBUILT +=, but as Yuri
mentioned it was for GB and I am using JB and ICS and hence was not
working for me.
The approach i took is to use shell script within the Android.mk file.
I used some like this:
Assume you have a folder named my_folder containing entire prebuilt folder structure which needs to be copied to anddroid out folder as is, inside my_folder, I created Android.mk and entered below text:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
$(shell mkdir -p $(TARGET_OUT)/my_folder/)
$(shell cp -rf $(LOCAL_PATH)/* `pwd`/$(TARGET_OUT)/my_folder/)
This way all my prebuilt set of files and folders in my_folder directory were copied as is to system folder in android out.
I hope this helps someone.
PRODUCT_COPY_FILES must be placed in product mk files (device/mydevice/..), not module files (Android.mk). This is mentioned here.
This format is used for copying dirs:
PRODUCT_COPY_FILES += $(call find-copy-subdir-files,*,vendor/mydir,system/app)
This command is not working for apk files though, giving error:
build/core/Makefile: *** Prebuilt apk found in PRODUCT_COPY_FILES: vendor/mydir/ray-system-ui-release.apk:system/app/ui-release.apk, use BUILD_PREBUILT instead!. Stop.
Here is an example from the book "Embedded Android" that will help you. Create a folder in the root of your aosp project called rootfs-glibc, put there the code that you want to copy, and create there Android.mk file with the following content:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
# This part is a hack, we're doing "addprefix" because if we don't,
# this dependency will be stripped out by the build system
GLIBC_ROOTFS := $(addprefix $(TARGET_ROOT_OUT)/, rootfs-glibc)
$(GLIBC_ROOTFS): mkdir -p $(TARGET_ROOT_OUT) cp -af $(TOPDIR)rootfs-glibc/* $(TARGET_ROOT_OUT) rm
# The last command just gets rid of this very .mk since it's copied as-is
ALL_PREBUILT += $(GLIBC_ROOTFS)
There is a note that this is true for Gingerbread. Maybe in newer versions of Android the make system has been changed.
Consider using a PHONY_PACKAGE with a custom installation step.
Unlike the $(shell cp whatever) answer above, this will only run during the installation step, rather than on every Make step (which is certainly not what you want).
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := some_module
LOCAL_ADDITIONAL_DEPENDENCIES := FORCE # Decide if you need this
LOCAL_POST_INSTALL_CMD = cd $(LOCAL_PATH) && cp -a mystuff $(TARGET_OUT_WHATEVER)
include $(BUILD_PHONY_PACKAGE)
I was thinking if I could do this way
1. I have both android and glibc compiled separetely.
2. Once both are compiled, I manually copy the glibc entire folder to /out/target/product/generic/system/glibc/ folder
3. Then I run "make snod"
Would that work?
I'm trying to edit an Android Makefile in the hopes of getting it to print out the directory (path) location of one the ZIP files it creates. Ideally, since the build process is long and does many things, I would like for it print out the pathway to the ZIP file to a text file in a different directory I can access later:
Pseudo-code idea:
# print the desired pathway to output file
print(getDirectoryOf(variable-name.zip)) > ~/Desktop/location_of_file.txt
The Makefile snippet where I would like to insert this new bit of code is shown below. I am interested in finding the directory of $(name).zip (that is specific file I want to locate):
# -----------------------------------------------------------------
# A zip of the directories that map to the target filesystem.
# This zip can be used to create an OTA package or filesystem image
# as a post-build step.
#
name := $(TARGET_PRODUCT)
ifeq ($(TARGET_BUILD_TYPE),debug)
name := $(name)_debug
endif
name := $(name)-target_files-$(FILE_NAME_TAG)
intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
BUILT_TARGET_FILES_PACKAGE := $(intermediates)/$(name).zip
$(BUILT_TARGET_FILES_PACKAGE): intermediates := $(intermediates)
$(BUILT_TARGET_FILES_PACKAGE): \
zip_root := $(intermediates)/$(name)
# $(1): Directory to copy
# $(2): Location to copy it to
# The "ls -A" is to prevent "acp s/* d" from failing if s is empty.
define package_files-copy-root
if [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \
mkdir -p $(2) && \
$(ACP) -rd $(strip $(1))/* $(2); \
fi
endef
As part of your rule's action (that is, as one of the lines indented by a tab, or as a command that follows a semicolon):
#echo $(dir $(variable-name).zip)
If output to a file is desired,
#echo $(dir $(variable-name).zip) >~/Desktop/location_of_file.txt
and you can make the > a >> if you prefer to append to the file rather than to overwrite.
UPDATE
What does it mean, "As part of your rule's action (that is, as one of the lines indented by a tab, or as a command that follows a semicolon)"?
Answer: It means that you can #echo like this:
file-to-be-built: dependencies
some-command
#echo foo
another-command
Or like this:
file-to-be-built: dependencies
#some-command; \
echo foo; \
another-command
(note the placement of the #). Or like this:
file-to-be-built: dependencies; #some-command; echo foo; another-command
But not like this:
#echo foo
file-to-be-built: dependencies
some-command
another-command
(Here is yet another parenthetical statement, which you can ignore if you like: The #, as you may know, suppresses Make's copying of the command itself to standard output. You can omit it, of course, but if you include it then you must put it before the specific command you don't want Make to copy. Formally, the versions without semicolons issue multiple, separate commands in their own, separate environments, using separate invocations of the shell; whereas the versions with semicolons only invoke the shell once, with a single environment, and leave it to the shell to separate and execute the commands. Does this make sense? Maybe not, if you just read it -- I can't make much sense of such tangled verbiage, either, even though I wrote it, myself -- but do try it with the # in the various spots indicated and it should soon start to make sense to you. The # is no big deal in any case, but it's there to use to keep Make's output clean if you understand how to use it.)