title: How to use my prebuilt c++ static/shared library in AOSP project
body: <p>I want use my static or shared prebuilt library <code>libmylib.so or libmylib.a</code>. My build target is Hikey960 device. I success building pure aosp project and flashing to Hikey960 device. Next I want modify <code>/frameworks/av/media/libaudioclient/AudioTrack.cpp</code> using my <code>libmylib.so</code>.</p>
  
  <h3>Setp 1</h3>
  
  <p>I made <code>mylib</code> directory to <code>/system</code> and copied prebuilt libraries.</p>
  
  <pre><code>|-- Andoird.mk
  |-- arm64-v8a
  |   |-- shared
  |   |   `-- Release
  |   |       `-- libmylib.so
  |   `-- static
  |       `-- Release
  |           `-- libmylib.a
  |-- armeabi
  |   |-- shared
  |   |   `-- Release
  |   |       `-- libmylib.so
  |   `-- static
  |       `-- Release
  |           `-- libmylib.a
  |-- armeabi-v7a
  |   |-- shared
  |   |   `-- Release
  |   |       `-- libmylib.so
  |   `-- static
  |       `-- Release
  |           `-- libmylib.a
  |-- include
  |   `-- mylib.h
  |-- x86
  |   |-- shared
  |   |   `-- Release
  |   |       `-- libmylib.so
  |   `-- static
  |       `-- Release
  |           `-- libmylib.a
  `-- x86_64
      |-- shared
      |   `-- Release
      |       `-- libmylib.so
      `-- static
          `-- Release
              `-- libmylib.a
  </code></pre>
  
  <h3>Step 2</h3>
  
  <p>I created <code>Android.mk</code> file in <code>/system/mylib</code> as follow</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
  LOCAL_MODULE := mylib
  LOCAL_SRC_FILES := system/mylib/$(TARGET_ARCH_ABI)/shared/Release/libmylib.so
  LOCAL_EXPORT_C_INCLUDES:= include
  include $(PREBUILT_SHARED_LIBRARY)
  </code></pre>
  
  <h3>Step 3</h3>
  
  <p>I inserted <code>libmylib</code> line to <code>shared_libs: [</code> in <code>frameworks/av/media/libaudioclient/Android.bp</code> as follow</p>
  
  <pre><code>cc_library_shared {
      name: "libaudioclient",
  
      aidl: {
          export_aidl_headers: true,
          local_include_dirs: ["aidl"],
          include_dirs: [
              "frameworks/av/media/libaudioclient/aidl",
          ],
      },
  
      srcs: [
          // AIDL files for audioclient interfaces
          // The headers for these interfaces will be available to any modules that
          // include libaudioclient, at the path "aidl/package/path/BnFoo.h"
          ":libaudioclient_aidl_private",
          ":libaudioclient_aidl",
  
          "AudioEffect.cpp",
          "AudioRecord.cpp",
          "AudioSystem.cpp",
          "AudioTrack.cpp",
          "AudioTrackShared.cpp",
          "IAudioFlinger.cpp",
          "IAudioFlingerClient.cpp",
          "IAudioPolicyService.cpp",
          "IAudioPolicyServiceClient.cpp",
          "IAudioTrack.cpp",
          "IEffect.cpp",
          "IEffectClient.cpp",
          "ToneGenerator.cpp",
          "PlayerBase.cpp",
          "RecordingActivityTracker.cpp",
          "TrackPlayerBase.cpp",
      ],
      shared_libs: [
          "libaudiofoundation",
          "libaudioutils",
          "libaudiopolicy",
          "libaudiomanager",
          "libbinder",
          "libcutils",
          "libdl",
          "liblog",
          "libmedia_helper",
          "libmediametrics",
          "libmediautils",
          "libnblog",
          "libprocessgroup",
          "libutils",
          "libvibrator",
          "libmylib",
      ],
      export_shared_lib_headers: ["libbinder"],
  
      local_include_dirs: ["include/media", "aidl"],
      header_libs: [
          "libaudioclient_headers",
          "libbase_headers",
          "libmedia_headers",
      ],
      export_header_lib_headers: ["libaudioclient_headers"],
  
      // for memory heap analysis
      static_libs: [
          "libc_malloc_debug_backtrace",
      ],
      cflags: [
          "-Wall",
          "-Werror",
          "-Wno-error=deprecated-declarations",
      ],
      sanitize: {
          misc_undefined : [
              "unsigned-integer-overflow",
              "signed-integer-overflow",
          ],
      },
  }
  </code></pre>
  
  <h3>Output</h3>
  
  <p>Unfortunatelly, the build failed:</p>
  
  <pre><code>error: frameworks/av/media/libaudioclient/Android.bp:39:1: "libaudioclient" depends on undefined module "libmylib"
  06:32:39 soong bootstrap failed with: exit status 1
  </code></pre>
  
  <p>I think does not include my prebuilt library files when aosp built. how to include my libraries to aosp build. where should I specify mylib?</p>
  
  <p>And I think now use soong as built tool instead of nkd-build in aosp so Should I change my Android.mk file in above I created to Android.bp?</p>
  
  <p>If you know my wrong step, please let me know how to do. thanks.</p>