ANDROIDMK TRANSLATION ERROR: unsupported include in Android.bp - android

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.

Related

Android ndk file not found on github actions

I am trying to implement CI on app which contains native code in C++ using github actions
When i am running workflow it's says that there is no headers near the .cpp, but it is here and i have setted include directories in build.gradle and Android.mk file, the build is fine on local PC(windows)
[armeabi-v7a] Compile++ thumb: samp <= CAuthentication.cpp In file
included from
/home/runner/work/client/client/app/src/main/cpp/CAuthentication.cpp:3:
/home/runner/work/client/client/app/src/main/cpp/main.h:23:10: fatal
error: 'vendor\RakNet\SAMP\samp_netencr.h' file not found
#include "vendor\RakNet\SAMP\samp_netencr.h"
file CAuthentication.cpp is in the same directory as directory "vendor"
I also tried to set environment variable in github job but it does not help
If you're using backslashes in your include directives as the error seems to suggest, try to change them into forward slashes:
#include "vendor/RakNet/SAMP/samp_netencr.h"
Also check the path for case correctness. Windows has a case-insensitive filesystem, while the CI might be running some form of Linux.

How to generate armeabi-v7a of libassimp.so.4.1.0 for Assimp

I am using Assimp source code to generate Android ARM binary. After CMake it provide me x86_64 libassimp.so every time.
I am using Assimp Source code 4.1.0 and compile it using following steps -
1. Set up android toolchain
export NDK_PATH=/path/to/your/android/ndk/
not go to android-ndk-r8c\build\tools
run the command:
sh make-standalone-toolchain.sh –platform=android-8 –ndk-dir=$NDK_PATH –install-dir=/Android/sdk/android-toolchain –toolchain=arm-linux-androideabi-4.4.3
which will build file scripts of the toolchain
now run the command
export ANDROID_NDK_TOOLCHAIN=$HOME/Android/sdk/android-toolchain
and also
export ANDTOOLCHAIN=$HOME/Android/android-cmake/toolchain/android.toolchain.cmake
to the path need to add :
export PATH=$PATH:$HOME/Android/sdk/tools
export PATH=$PATH:$HOME/Android/sdk/platform-tools
export PATH=$PATH:$HOME/Android/sdk/android-toolchain/bin
so lets begin, download the last source of assimp library from http://assimp.sourceforge.net and open terminal(cygwin or mac terminal) , go to assimp directory and type :
mkdir buildandroid
cd buildandroid
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDTOOLCHAIN -DENABLE_BOOST_WORKAROUND=ON -DCMAKE_INSTALL_PREFIX=/assimp-2.0 -DANDROID_ABI=armeabi-v7a _DANDROID_NATIVE_API_LEVEL=android-8 -DANDROID_FORCE_ARM_BUILD=TRUE ..
this will create files and folders in the build directory, now go to the file link.txt inside : buildandroid => code => cMakeFiles => assimp.dir => link.txt
search for the string -soname, libassimp.so.3 and remove the .3 from the extension of the library (if not it will make problems in loading later from the android)
do the same thing with file name relink.txt
now go back to the root directory of buildandroid and run :
make
process of building will begin, the shared library will be in parent lib folder and wll consist from symbolic links and so library which will called libassimp.so.version_number. remove the version number makeing the file name only be libassimp.so
In the end, I am getting x86_64 libassimp.so instead armeabi-v7a. Please let me know if anybody now, how to generate armeabi-v7a libassimp.so. Any help will be appreciated.

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.

Include headers directories for gradle generation with JNI interaction

I'm trying to get C++ code to work with react-native (see this for the general steps).
I've generated my project with react-native init, generated the JNI bindings by using Djinni. I'm now trying to build the application and test it on my android emulator (cd $PROJECT_ROOT/android && ./gradlew installDebug). It seems like the header files aren't found, their directories aren't included :
> ./gradlew installDebug
(...)
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk
Warning: Deprecated NDK integration enabled by useDeprecatedNdk flag in gradle.properties will be removed from Android Gradle plugin soon.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.cpp:4:
$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.hpp:6:10: fatal error: 'cpp_bridge_text.hpp' file not found
#include "cpp_bridge_text.hpp"
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [$PROJECT_ROOT/android/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/app/$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.o] Error 1
:app:compileDebugNdk FAILED
FAILURE: Build failed with an exception.
I managed to get past this small issue by creating hard links to the headers causing issues. Which leads me to this :
> ./gradlew installDebug
(...)
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk
Warning: Deprecated NDK integration enabled by useDeprecatedNdk flag in gradle.properties will be removed from Android Gradle plugin soon.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.cpp:4:
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.hpp:7:
$PROJECT_ROOT/app/src/main/jni/djinni_support.hpp:20:10: fatal error: 'exception' file not found
#include <exception>
^~~~~~~~~~~
1 error generated.
make: *** [$PROJECT_ROOT/android/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/app/$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.o] Error 1
:app:compileDebugNdk FAILED
FAILURE: Build failed with an exception.
In this case, it seems like even standard libraries aren't included.
My question is : how do I explicitly specify gradle to add directories to its search/indlude path?
In regular Android projects, it seems that you can edit Android.mk/Application.mk files. There aren't such files in my folders ; I think that gradle actually generates an Android.mk file (in $PROJECT_ROOT/android/app/build/intermediates/ndk/debug/Android.mk), I tried editing it (LOCAL_C_INCLUDES field) to add my directories, but it gets overwritten when I try another build.
Thanks in advance.
You can edit this in $PROJECTROOT/android/app/build.gradle :
android {
defaultConfig {
(...)
ndk {
(...)
cFlags = "-Ipath/to/directory/"
}
}
}
However, you will most likely encounter other issues (I know that for a fact, because I did). I'd recommend you to use the modern and user-friendly CMake integration.
I'm gonna write down the general steps so that I can find it again sometime in the future :
Add your files to the android project (under android studio or another IDE). There should be files in your java/ folder, files in your jni/ folder (JNI bridge files), and files in your cpp/ folder (the native C++).
Add a CMakeLists.txt file to your module (usually named app if you're using react-native).
In this file, respect the following structure :
cmake_minimum_required(VERSION 3.4.1)
add_library( # Name of the library
$(YOUR_LIBRARY_NAME)
# Sets it as a shared library
SHARED
# Relative path to the source file(s)
path/to/your/file.cpp path/to/other/file.cpp )
# Allows you to add folders to the search path : similar to -Ipath/to/your/headerfolder/
include_directories(path/to/your/headerfolder/)
# Allows you to have special compilation flags for the specified library's compilation
target_compile_options( $(YOUR_LIBRARY_NAME)
PRIVATE # You can also use PUBLIC/INTERFACE
-std=gnu++11 ) # Your option ; I needed this in my case
Once it's done, you need to link gradle to your native library :
If you're using android studio, just use the information available in this guide as it's very well explained.
If you aren't, I also advise you to check out this guide, because it's really well explained.
After that, you can either build the project in android studio, or cd $(PROJECTROOT)/android && ./gradlew installDebug. It should work.
Good luck!

Compile OpenSSL for Android with Bazel

I'm building a native library for my Android application with bazel.
I'd like to use some OpenSSL functions on it like this:
#include <jni.h>
#include <openssl/aes.h>
...
AES_encrypt(in, out, key);
How to add the openssl library to bazel build ?
Subsidiary question: which archive I should use ?
openssl-1.1.0c.tar.gz
openssl-1.0.2j.tar.gz
openssl-1.0.1u.tar.gz
openssl-fips-2.0.13.tar.gz
openssl-fips-ecp-2.0.13.tar.gz
What I've tried
I've downloaded the openssl-1.0.2j archive. and added a cc_library entry to my BUILD file.
cc_library(
name = "openssl",
srcs = glob([
"openssl-1.0.2j/crypto/**/*.h",
"openssl-1.0.2j/crypto/**/*.c"
]),
includes = [
"openssl-1.0.2j",
"openssl-1.0.2j/crypto/",
],
visibility = ["//visibility:public"],
)
I've this error:
openssl-1.0.2j/crypto/dh/p512.c:60:24: fatal error: openssl/bn.h: No such file or directory
#include <openssl/bn.h>
But I don't understand why this code is trying to include a file from openssl while it's in openssl-1.0.2j/crypto/
With openssl-1.1.0c
openssl-1.1.0c/include/openssl/e_os2.h:13:34: fatal error: openssl/opensslconf.h: No such file or directory
# include <openssl/opensslconf.h>
Even if I run the Configure command, no opensslconf.h file is generated.
Based on #Ulf Adams' answer, I gave up trying to compile OpenSSL with bazel. I used BoringSSL instead.
BoringSSLis a fork of OpenSSL, and can easily be incorporated to a bazel project by doing:
git_repository(
name = "boringssl",
commit = "_some commit_",
remote = "https://boringssl.googlesource.com/boringssl",
)

Categories

Resources