AOSP building application with jni libs - android

I am trying to build an Android application inside of AOSP.
I have defined the Android.bp file as follows
cc_prebuilt_library_shared {
name: "libPrintString",
target: {
android_arm: {
srcs: ["lib/libPrintString.so"],
},
android_arm64: {
srcs: ["lib64/libPrintString.so"],
},
},
strip: { none:true, },
}
java_import {
name: "stringutils",
jars: ["libs/stringutils.jar"],
}
android_app {
name: "HelloWorld",
srcs: ["src/**/*.java",],
platform_apis: true,
product_specific: true,
certificate: "platform",
privileged: true,
static_libs: [
"com.google.android.material_material",
"androidx-constraintlayout_constraintlayout",
"stringutils",
],
jni_libs: ["libPrintString"]
}
I have put my application in the /packages/apps folder, the project has the following structure
+ HelloWorld
- Android.bp
- AndroidManifest.xml
+ lib
- libPrintString.so
+ lib64
- libPrintString.so
+ libs
- stringutils.jar
+ res
+ src
When I am calling make I am getting an error
FAILED: ninja: 'out/target/product/mydroid/product/lib64/libPrintString.so', needed by 'out/target/product/mydroid/product.img', missing and no known rule to make it
Can someone please help me to find a solution?

Your app HelloWorld definition has this property product_specific: true which means the app will go to /product partition and will search for the libraries in /product/lib*/.
But your library libPrintString definition don't have product_specific: true which means the library goes to system/lib*/.
So error makes sense.
To solve your problem, You have to add this property product_specific: true to your library definition.
cc_prebuilt_library_shared {
name: "libPrintString",
target: {
android_arm: {
srcs: ["lib/libPrintString.so"],
},
android_arm64: {
srcs: ["lib64/libPrintString.so"],
},
},
strip: { none:true, },
product_specific: true
}

After long fights with the build system, I finally found a solution and wrote a small article to describe in details how to build an application with system privileges
How to Build an Android Application with System Privilegies
I still did not fully understand why it was not working in the beginning, most probably because somehow my build system was not cleaning old libraries, but now everything is working correctly.

Related

How to add NET_RAW capability to the android app prebuilt in aosp?

I'm working on the custom AOSP build. And MyApp is a prebuilt application of it. So I'm having full control of the security policies of it. MyApp is using native library via jni. This library is using socket of NET_RAW type under the hood. The problem right now is that I'm not able to create such socket due the lack of CAP_NET_RAW capability.
And I don't really know how to properly set this capability for the android app. The docs on the source.android.com describes adding of it to services, not prebuilt .apk.
I suppose I have to use sepolicies files.
The android.bp of the module below.
cc_library_shared {
name: "libMyLib",
...
cpp_std: "c++17",
sdk_version: "current"
}
android_app {
name: "MyApp",
vendor: true,
use_embedded_native_libs: true,
required: [
"privapp_whitelist.myapp",
],
jni_libs: [
"libMyLib",
...
],
optimize: {
enabled: false,
},
...
}
I tried to add config.fs file and request capabilities as shown here https://source.android.com/docs/core/permissions/filesystem#using-file-system-capabilities
but it didn't work.
[path/to/apk] #also tried the [path/to/lib]
mode: 0755
user: AID_MY_AID
group: AID_MY_AID
caps: NET_RAW
As I said before, the docs are saying it is applying for the services, not the ready apps, so I'm not sure if its really working.
Also I've added INTERNET permission to the app manifest & privapp_whitelist.myapp.xml file, just to make sure the things are set up.

Android ASOP build error while adding third party plugin of Firebase in Android.bp

I'm trying to build an ASOP build which uses some external libs like Firebase. (In ASOP source code)
While adding Firebase plugin in Android.bp getting error like "depends on undefined module "com.google.gms.google-services"
Is there any alternative to use "apply plugin: 'com.google.gms.google-services'" in Andorid.mk or Android.bp other build system?
android_app {
name: "FirebaseService",
vendor: true,
certificate: "platform",
privileged: true,
srcs: ["java/**/*.java",],
resource_dirs: ["res"],
manifest: "AndroidManifest.xml",
static_libs: [
"firebase-analytics",
"androidx.appcompat_appcompat",
],
plugins: ["com.google.gms.google-services"],
optimize: {
enabled: false,
},
sdk_version: "system_current",
dex_preopt: {
enabled: false,
}, }
This plugin is to use refer google-sevices.json file which we get while integrate application with Firebase.
error: vendor/frameworks/FirebaseService/Android.bp:20:1:"FirebaseService" depends on undefined module "com.google.gms.google-services"

Android rebuilds static library when the binary is compiled

I have a binary in Android that links to a static library A. Static library libA depends on multiple shared libraries.
The binary does not do anything except it imports a class from the static library and executes a simple function.
However, the binary fails to build except I link against the same shared libraries to which the static library A is linked because the compiler tries to recompile libA with the build config of the binary.
Here is my Android.bp of the static library:
cc_library_static {
name: "libA",
relative_install_path: "hw",
vendor: true,
rtti: true,
cflags: [
"-Wall",
"-Wextra",
"-g",
"-DUNIT_TEST",
"-fexceptions"
],
srcs: [
"libA.cpp",
],
shared_libs: [
"libhidlbase",
"libhidltransport",
"libutils",
"liblog"
],
header_libs: [
"lib_a_stub_headers",
],
whole_static_libs: [
"lib_a_stub",
],
export_include_dirs: ["."]
}
Here is my Android.bp for the binary:
cc_binary{
name: "simplebinary",
relative_install_path: "hw",
vendor: true,
cflags: [
"-fexceptions"
],
whole_static_libs: [
"libA"
],
shared_libs: [
"vendor.test.hal#1.0",
],
srcs: [
"simplebinary.cpp",
],
}
The build of the binary fails with:
libA.hpp:4:10: fatal error: 'lib/lib.hpp' file not found
I'm building using the command mm
According to the error message, the compiler cannot find a header file in its header search path. Header includes are resolved during the preprocessor stage, therefore this is not a linking problem. The preprocessor runs at the beginning of compilation, the linking is done at the end.
From your description, I understand that the code for simplebinary includes the header libA.hpp, provided by libA. I understand that libA.hpp is contained in the same directory as the Android.bp that defines the libA module. Because of the export_include_dirs: ["."], this directory is added to the header search path for the compilation of simplebinary. Therefore, the compiler can find libA.hpp when compiling simplebinary.
Now libA.hpp includes CommonAPI/CommonAPI.hpp. I do not know to which library this header belongs. I assume the header belongs to some library libB, and libA links against libB. I further assume that libB has export_include_dirs set to point to the folder containing CommonAPI/CommonAPI.hpp. You can then make libA re-export this header by adding export_shared_lib_headers: ["libB"] to the module declaration of libA. If libB is not a shared library, you would have to use export_static_lib_headers or export_header_lib_headers instead (reference).

tensorflow android with react-native can't work normally

I put react-native.jar to tensorflow android's directory and add configuration to tensorflow/examples/android/BUILD file like this:
java_import(
name = "react-native",
jars = [
"react-native-0.39.2-sources.jar",
],
)
Now run bazel build //tensorflow/examples/android:tensorflow_demo work well. But then use import com.facebook.react.*; in java file and run bazel build ... again, it throws a nonexistent error, can't find com.facebook.react.* package.
In order to expose the classes in the JAR to the Java code in the Android build, you need to add a dependency in the android_binary that you are building on the java_import you have created.
For example:
# tensorflow/examples/android/BUILD
java_import(
name = "react-native",
jars = [
"react-native-0.39.2-sources.jar",
],
)
android_binary(
name = "tensorflow_demo",
srcs = glob(["src/**/*.java"]),
deps = [
":tensorflow_native_libs",
"//tensorflow/contrib/android:android_tensorflow_inference_java",
":react-native",
],
)

Typescript sourcemaps not displayed in Ionic 2 on an Android device

I face a weird Ionic2 behaviour.
When i deploy my app to a simulator, i can see the .ts file sourceMap in the chrome inspect debugger.
On both case, i use :
ionic run android
On the other side, when i deploy my apk on a real device, the tab "Sources" is completely different with an other groups of directories and, with no reference to my .ts files.
My environment is:
OS X 10.11
Ionic 2 2.0.0-beta.35
cordova 6.3.0
The project has been initially generated by:
ionic start biblio tutorial --v2
ionic.config.json
{
"name": "biblio",
"app_id": "",
"v2": true,
"typescript": true
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"filesGlob": [
"**/*.ts",
"!node_modules/**/*"
],
"exclude": [
"node_modules",
"typings/global",
"typings/global.d.ts"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
Any ideas?
For me the problem was that when you're remote debugging on an android device, Chrome debugger cannot access the source map file on the device. The solution/fix is to include the source map inline. To do this I:
added the below to package.json in the root project directory
"config": {
"ionic_bundler": "webpack",
"ionic_source_map_type": "#inline-source-map"
},
This is to make the webpack to add source maps inline changed tsconfig.js line
"sourceMap": true,
to
"sourceMap": false
This is to disable typescript to create source map file since this is done by webpack.
After this change everything seems to be working fine. Note that this applies to ionic 2 RC_04

Categories

Resources