opengapps/aosp_build

find-apk-for-pkg not working

supergps1 opened this issue · 3 comments

I am trying to build Android-tv with opengapps::tvstock for hikey960
AOSP is master branch latest on 19May2019.
I have copied opengapps/aosp_build to vendor/opengapps/build
I have copied nezor/all, nezor/arm and nezor/arm64 to vendor/opengapps/sources
(copying through manifest+repo sync didn't work, but that's another issue)

When I build, it fails with error: ActionsServices: No source files specified


I initially thought these issues were caused by including PR158 into aosp_build.
So I retried without PR158 and nano instead of tvstock and still encountered same issue.

I did some debugging (with nano) and following are my findings:

prebuilt_apk.mk is unable to find APK files saved under sources folder.
I modified to add some logs to see how find-apk-for-pkg is called as follows:

LOCAL_SRC_FILES := $(call find-apk-for-pkg,all,$(LOCAL_PACKAGE_NAME))
$(warning "find-apk-for-pkg all $(LOCAL_PACKAGE_NAME) = $(LOCAL_SRC_FILES)")
ifdef LOCAL_SRC_FILES
  LOCAL_PREBUILT_JNI_LIBS := $(call find-libs-in-apk,$(TARGET_ARCH),$(LOCAL_SRC_FILES))
else
  LOCAL_SRC_FILES := $(call find-apk-for-pkg,$(TARGET_ARCH),$(LOCAL_PACKAGE_NAME))
  $(warning "find-apk-for-pkg $(TARGET_ARCH) $(LOCAL_PACKAGE_NAME) = $(LOCAL_SRC_FILES)")
  ifdef LOCAL_SRC_FILES
    ifeq ($(filter 21,$(call get-allowed-api-levels)),)
      # only kitkat
      ifneq ($(call find-libs-in-apk,$(TARGET_ARCH),$(LOCAL_SRC_FILES)),)
        LOCAL_SHARED_LIBRARIES := $(notdir $(basename $(shell zipinfo -1 "$(LOCAL_SRC_FILES)" "$(call get-lib-search-path, $(TARGET_ARCH))" -x lib/*/crazy/* 2>/dev/null)))
      endif
    else
      LOCAL_PREBUILT_JNI_LIBS_$(TARGET_ARCH) := $(call find-libs-in-apk,$(TARGET_ARCH),$(LOCAL_SRC_FILES))
    endif
  else
    ifdef TARGET_2ND_ARCH
      LOCAL_SRC_FILES := $(call find-apk-for-pkg,$(TARGET_2ND_ARCH),$(LOCAL_PACKAGE_NAME))
      $(warning "find-apk-for-pkg $(TARGET_2ND_ARCH) $(LOCAL_PACKAGE_NAME) = $(LOCAL_SRC_FILES)")
      ifdef LOCAL_SRC_FILES
        LOCAL_MODULE_TARGET_ARCH := $(TARGET_2ND_ARCH)
        LOCAL_PREBUILT_JNI_LIBS_$(TARGET_2ND_ARCH) := $(call find-libs-in-apk,$(TARGET_2ND_ARCH),$(LOCAL_SRC_FILES))
      endif
    endif
  endif
endif

This results in following log:

gps@gps-HP-280-G3-MT:~/andsrc/android-master$ make -j32
============================================
PLATFORM_VERSION_CODENAME=R
PLATFORM_VERSION=R
TARGET_PRODUCT=hikey960_tv
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=cortex-a73
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=cortex-a73
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.13.0-26-generic-x86_64-Ubuntu-16.04.3-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=PI
OUT_DIR=out
============================================
vendor/opengapps/build/core/definitions.mk was modified, regenerating...
18:54:03 Disallowed PATH tool "locale" used: []string{"locale", "-a"}
18:54:03 See https://android.googlesource.com/platform/build/+/master/Changes.md#PATH_Tools for more information.
build/make/core/config.mk was modified, regenerating...
18:54:08 Disallowed PATH tool "locale" used: []string{"locale", "-a"}
18:54:08 See https://android.googlesource.com/platform/build/+/master/Changes.md#PATH_Tools for more information.
[ 82% 361/437] including vendor/opengapps/build/modules/ActionsServices/Android.mk ...
FAILED: 
getappapidir vendor/opengapps/sources all com.google.android.as 28 failed
vendor/opengapps/build/core/prebuilt_apk.mk:25: warning: "find-apk-for-pkg all com.google.android.as = "
ls: Unknown option vr (see "ls --help")
WARNING: No APK found compatible with API level 28 for package com.google.android.as on arm64
getappapidir vendor/opengapps/sources arm64 com.google.android.as 28 failed
vendor/opengapps/build/core/prebuilt_apk.mk:30: warning: "find-apk-for-pkg arm64 com.google.android.as = "
ls: Unknown option vr (see "ls --help")
WARNING: No APK found compatible with API level 28 for package com.google.android.as on arm
getappapidir vendor/opengapps/sources arm com.google.android.as 28 failed
vendor/opengapps/build/core/prebuilt_apk.mk:43: warning: "find-apk-for-pkg arm com.google.android.as = "
tools/tradefederation/core/util-apps/WifiUtil/Android.mk: error: ActionsServices: No source files specified 
build/make/core/prebuilt_internal.mk:37: error: done.
18:54:50 ckati failed with: exit status 1

#### failed to build some targets (50 seconds) ####

However, when I try calling find_apk.sh directly, it works:

ps@gps-HP-280-G3-MT:~/andsrc/android-master$ vendor/opengapps/build/core/find_apk.sh vendor/opengapps/sources 28 tvdpi com.google.android.as all false prebuilts/sdk/tools/linux/bin/aapt
gps@gps-HP-280-G3-MT:~/andsrc/android-master$ vendor/opengapps/build/core/find_apk.sh vendor/opengapps/sources 28 tvdpi com.google.android.as arm64 false prebuilts/sdk/tools/linux/bin/aapt
vendor/opengapps/sources/arm64/priv-app/com.google.android.as/28/nodpi/71020.apk
gps@gps-HP-280-G3-MT:~/andsrc/android-master$ vendor/opengapps/build/core/find_apk.sh vendor/opengapps/sources 28 tvdpi com.google.android.as arm false prebuilts/sdk/tools/linux/bin/aapt
vendor/opengapps/sources/arm/priv-app/com.google.android.as/28/nodpi/8875.apk

I found the issue. Its with ls as visible in error log:

ls: Unknown option vr (see "ls --help")

I couldn't get my head around the issue because my system's ls work fine, and so calling find_apk.sh script directly works fine.

But when this script is called by aosp build system, ls is pointing to prebuilts/build-tools/path/linux-x86/ls which doesn't support -v option.

I removed v option from ls in script as follows:

  for apidir in $(ls -r "$1/$2/"*"app/$3"); do

and now the build proceeds. Not sure if it will finish yet.

I am not sure what is reason for adding -v option in opengapps aosp build scripts, but if it is required, I am sure script needs to be modified to use local ls command instead of one supplied prebuilt by AOSP build system.

Thanks for opening this issue and, especially, for coming back with a solution :-)

This will likely effect a number of users when Q is released and they upgrade.

In the gnu version of ls, here is what -v does:

natural sort of (version) numbers within text

The -v might be important for selecting the correct apk (version numbers are used to name the directories where the apks reside).

For a fix, it might be better to just call /bin/ls explicitly inside find_apk.sh.

I also found that /usr/bin/lzip needs to be used instead of lzip in that script, else it throws an error.