AOSP building application with jni libs

Viewed 1514

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?

2 Answers

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