Create unstripped executable for android with .bp - android

I want to build aosp native test and debug it on emulator. Is it possible to build executable with debugging symbols?
I have tried to add -g and -ggdb to Android .bp:
cflags: [
"-Werror",
"-Wall",
"-g",
],
but it didn't help, I still getting stripped executable.

In the module declaration, add:
strip: {
keep_symbols: true,
},
Reference: link.

You can find the unstripped binaries in $ANDROID_PRODUCT_OUT/symbols.

Related

ANDROIDMK TRANSLATION ERROR: unsupported include in Android.bp

Am trying to add the include fwk/base/pkgs/SettingsLib/common.mk onto Settings App, But am unsure how to use it on Android.bp file.
I used the androidmk conversion tool which comes with the AOSP build system to convert Android.mk to Android.bp
What I DID :
1. On AOSPSource code, check build/soong/androidmk and make full build.
2. After compiling the source code, the androidmk generation tool located :
# out/soong/host/linux-x86/bin/androidmk
3. Using the androidmk command try converting my Android.mk to Android.bp
# androidmk Android.mk > Android.bp
Error inside Android.bp
20 // **ANDROIDMK TRANSLATION ERROR: unsupported include**
21 // include frameworks/base/packages/SettingsLib/search/common.mk$
Any suggestions ? Thanks in advance.
Found way to convert Android.mk to Android.bp and import on App.
Core AOSP androidmk tool does NOT help, We need to manually create a SettingsLibDefaults on SettingsLibs ( create a Defaults on any libs) . Referred AOSP SettingsLib Android.bp file.
// NOTE: Keep this module in sync with ./common.mk
java_defaults {
name: "SettingsLibDefaults",
static_libs: [
"androidx.annotation_annotation",
"androidx.lifecycle_lifecycle-common",
"androidx.legacy_legacy-support-v4",
"androidx.lifecycle_lifecycle-runtime",
"androidx.recyclerview_recyclerview",
"androidx.preference_preference",
"androidx.appcompat_appcompat",
"androidx.legacy_legacy-preference-v14",
"SettingsLib",
],
}
Usage of SettingsLibDefaults on Settings App Android.bp file
android_library {
name: "Settings-core",
platform_apis: true,
defaults: [
"SettingsLibDefaults",
"SettingsLib-search-defaults",
],
Same way we need to create a Defaults on any libs Android.bp file and import on Apps.

How to build a specific Android cli executable (service.cpp)

In android, when you open a terminal emulator or connect an adb shell, there is a command service that you can execute which allows you to interact with system services to some degree. For my purposes the functionality is too limited though and I would like to expand it a little.
Unfortunately this executable is not documented.
I have located the source code here: service.cpp
There is also a file called Android.bp in the same directory with the following content:
cc_binary {
name: "service",
srcs: ["service.cpp"],
shared_libs: [
"libcutils",
"libutils",
"libbinder",
],
cflags: [
"-DXP_UNIX",
"-Wall",
"-Werror",
],
}
cc_binary {
name: "vndservice",
proprietary: true,
srcs: ["service.cpp"],
shared_libs: [
"libcutils",
"libutils",
"libbinder",
],
cflags: [
"-DXP_UNIX",
"-DVENDORSERVICES",
"-Wall",
"-Werror",
],
}
Those cflags look like g++ flags to me. I don't really know g++, but after a lot of trial and error I ended up with this:
# Download required source code
git clone https://android.googlesource.com/platform/superproject
cd superproject
git submodule init
git submodule update frameworks/native
git submodule update system/libbase
git submodule update system/core
git submodule update system/logging
# Set required include directories in CPATH
export CPATH="./frameworks/native/include:./system/libbase/include:./system/core/libcutils/include:./system/core/libutils/include:./system/logging/liblog/include:./system/core/libsystem/include:./frameworks/native/libs/binder/include"
# Build
g++ -DXP_UNIX -Wall -Werror -o service ./frameworks/native/cmds/service/service.cpp
Unfortunately I get a massive amount of errors:
https://pastebin.com/fnu7LJLU
My G++ version is:
g++ (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
Any ideas why this is failing?

Compiling the tensorflow lite minimal example

I'm trying to use tensorflow lite on android. I'm getting an error during compilation with android studio:
undefined reference to 'tflite::InterpreterBuilder::operator()(std::__ndk1::unique_ptr<tflite::Interpreter, std::__ndk1::default_delete<tflite::Interpreter> >*)'
I've managed to get a reproducible example while trying to compile this minimal example from the tf repo.
Steps to get the error
Download the android ndk (I've tried both 15c and 16b and they both failed) . Call build/tools/make_standalone_toolchain.py --arch arm --api 21 --stl=libc++ --install-dir android-toolchain
Build libtensorflow, this is in my build file.
tensorflow/lite/BUILD
cc_binary(
name = "libtensorflowlite.so",
linkopts=[
"-shared",
"-Wl,-soname=libtensorflowlite.so",
],
linkshared = 1,
copts = tflite_copts(),
deps = [
":framework",
"//tensorflow/lite/kernels:builtin_ops",
],
)
I call it like:
bazel build //tensorflow/lite:libtensorflowlite.so --crosstool_top=//external:android/crosstool --cpu=armeabi-v7a --host_crosstool_top=#bazel_tools//tools/cpp:toolchain --cxxopt="-std=c++11"
I clone the flatbuffer repo (a dependency) and compile it.
Then I try and compile minimal.cc.
I call it like:
android-toolchain/bin/clang++ -std=c++11 -Igit/tensorflow-android -Igit/flatbuffers/include -Lgit/tensorflow-android -Lgit/flatbuffers/build minimal.cc -ltensorflowlite -lflatbuffers
(libtensorflow.so is in git/tensorflow-android, libflatbuffers.a in git/flatbuffers/build)
What's going on? I have no idea why this method is being called, I'm not calling the object with two arguments.
The error was me not being on ndk 18. I hadn't switched to it because when compiling bazel was specifically telling me to use <=16!

Android.bp and ninja: error: unknown target

I have an application in packages/apps under my vendor dir in Android O.
The application relies on a HIDL interface, which is added as a java library.
If I build the app with Android.mk file, it builds just fine.
If I build the app with Android.bp file, hiding the Android.mk, it doesn't build and fails with an error:
ninja: error: unknown target 'MODULES-IN-vendor-${vendor_name}-apps-${app_name}', did you mean 'MODULES-IN-vendor-${vendor_name}-apps-${another_app_name}'?
Or it can be just
ninja: error: unknown target 'MODULES-IN-vendor-${vendor_name}-apps-${app_name}'
My Android.bp looks like:
android_app {
java_libs: ["some.hidl.lib-V1.0-java"],
java_static_libs: ["android.hidl.base-V1.0-java-static"],
srcs: ["**/*.java"],
android_resource_dirs: ["res/**"],
name: "MyApplication",
module_name: "MyApplication",
package_name: "me.myself.MyApplication", // also tried just the name as it is done in Android.mk
enabled: true,
proguard_enabled: disabled
}
Any ideas?
Not sure if you have resolved this issue, I also met such issue. This is caused by Android only tries to include the "Android.bp" file from the level 3 folder which is defined in "Android.bp" under root folder:
optional_subdirs = [
....
"vendor/*/*",
]
So you need to add one "Android.bp" into vendor/vendor_name/packages with specified optional_subdirs or just wildcard as above.
In my case, I was using Android.mk file only but by mistake I used arm64 in
LOCAL_MODULE_TARGET_ARCH := arm64
But I was building for x86_64 target. So I changed to
LOCAL_MODULE_TARGET_ARCH := x86_64
And I worked. Might be this answer is not directly related to it but If someone would have done same mistake then it would help.

Same android cmake git project compiles well on one Ubuntu machine but does not compile on another Ubuntu machine even the entire project is the same

I'm developing an android cmake project that compiles succesfully on my 32-bit Ubuntu 12.04 machine at work (I will call it WorkMachine). When I want to compile it at home, I installed a 32-bit Ubuntu 12.04 virtual machine (I will call it HomeMachine), I git cloned the project on it, and when I start the compilation, it will block with an error.
CMAKE_CFLAGS are:
CMAKE_CXXFLAGS are:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/raa/Dropbox/Demo/android_build
[ 0%] Built target bitstream
[ 0%] Built target distrat
[ 1%] Built target fisher
[ 1%] Built target gtest
[ 7%] Built target jpeg-8c
[ 7%] Built target map
[ 8%] Built target resampler
[ 9%] Built target timer
[ 92%] Built target fftw3f-3
[ 96%] Built target vlfeat
[ 96%] Built target extract_shared
[ 97%] Built target shared
[ 97%] Built target cssc_train
Linking CXX executable ../../bin/extract
/home/raa/Dropbox/Demo/libraries/fftw-3.3.3/api/configure.c:28: error: undefined reference to 'fftwf_dft_conf_standard'
collect2: error: ld returned 1 exit status
make[2]: *** [../bin/extract] Error 1
make[1]: *** [src/CMakeFiles/extract.dir/all] Error 2
make: *** [all] Error 2
Here I am reporting gcc version (the same on both computers)
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
But how is that possible?
It seems the problem is not due to some cmake cache or similar chaches, because if I git clone the project on another directory on the WorkMachine, the code compiles well too.
What can I check in order to resolve the problem? If you need additional details, please ask me.
Thank you for your time.
Riccardo
the solution to Riccardos problem is to change the commandline parameter of ar from r to q (see man page for difference, basically q does not check for duplicats)
do this via
SET(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
you probably want to check if CMAKE_AR is "ar" (might be different on other systems)
whoa! Solved! It was really a weird behaviour from cmake: I had three files conf.c that must be merged into a static library. When cmake run the AR program to create the library, it executed a command that was like:
ar cr dir1/source1.c dir1/source2.c ... dft/conf.c rdft/conf.c
ar r reodft/conf.c dir2/source3.c
so, maybe due to the huge number of object files that were to be linked, cmake splitted ar commands in two command, BUT second command overwrited one of the two file conf.c that were added with the first command, so symbols defined with the first ar command were lost! This is clearly a bug in ar because even if the source file is the same, maybe the content may vary, thus symbols are not to be deleted. Thanks to all! Your suggestions brought me to the right solution!

Categories

Resources