Building Android Source Code…Error

Which system do you use? Android, Ubuntu, OOWOW or others?

Android 11

Which version of system do you use? Khadas official images, self built images, or others?

Self built images

Please describe your issue below:

I’m trying to build Android according to the instructions
https://docs.khadas.com/products/sbc/vim4/development/android/build-android
but its failed:

evgen@acer:/media/evgen/khadas/android11$ lunch kvim4-userdebug
device/khadas/common/tuner/tuner.mk:25: warning: TUNER_MODULE is cxd2856
device/khadas/common/video_algorithm/hdr10_tmo/hdr10_tmo.mk:22: warning: HDR10_TMO_MODULE is true
device/khadas/common/video_algorithm/dnlp/dnlp.mk:22: warning: DNLP_MODULE is true
device/khadas/common/ldim/ldim.mk:22: warning: LDIM_FW_MODULE is true
device/khadas/common/speech/speech.mk:23: warning: because speech does not support kernel 5.4, So set SPEECH_MODULE to false here
vendor/amlogic/common/wifi_bt/bluetooth/configs/bluetooth.mk:26: warning: BLUETOOTH_MODULE is multibt
vendor/amlogic/common/wifi_bt/bluetooth/configs/bluetooth.mk:30: warning: BLUETOOTH_INF is not set
In file included from build/make/core/config.mk:291:
In file included from build/make/core/envsetup.mk:266:
In file included from build/make/core/product_config.mk:160:
device/khadas/kvim4/kvim4.mk:462: error: Params: is_reference_project=[false],need_tv_feature=[true], is_android_tv=[false];  Error : Failed to patch [/media/evgen/khadas/android11/vendor/amlogic/common/pre_submit_for_google//WaitGoogleMerge/frameworks#av#0001_media_ext.patch], Need check it.exit.
12:17:42 dumpvars failed with: exit status 1

I found a similar topic, but it did not help me (Building Android Source Code...Error)

Status of my repo:

➜  pre_submit_for_google git:(khadas-vim4-r-64bit) git log 
commit 6d117419f8e411e9c0731a8f75913d5d5bad3cc4 (HEAD -> khadas-vim4-r-64bit, origin/khadas-vim4-r-64bit)
Author: sipang.luo <sipang.luo@amlogic.com>
Date:   Tue Sep 27 19:19:15 2022 +0800

    TvAudio: Adjust the device priority when setting the volume [1/1]
    
    PD#SWPL-92443
    
    Problem:
    HDMI in input BT/USBspeaker output,the ARC is silent after
    BT/USBspeaker is disconnected,frequency :3/3 comparison: 0629 OK.
    
    Solution:
    When adjusting the volume, ARC should take precedence over SPK.
    
    Verify:
    Android R
    
    Change-Id: Ib224a60546ab5e8e46b528bd60f70c9274da0858
    Signed-off-by: sipang.luo <sipang.luo@amlogic.com>

➜  pre_submit_for_google git:(khadas-vim4-r-64bit) ls WaitGoogleMerge               
bootable#recovery#0001-recovery-add-amlogic-connector-matching-strategy-1-1.patch  frameworks#base#0005_audio.patch        frameworks#base#0010_globalactions.patch   frameworks#base#0019_earc.patch
external#e2fsprogs#0001_chinese_character.patch                                    frameworks#base#0005_passthrough.patch  frameworks#base#0011_cec.patch             frameworks#base#0020_earc.patch
frameworks#av#0001_media_ext.patch                                                 frameworks#base#0005_soundbar.patch     frameworks#base#0012_cec.patch             frameworks#base#0022_ad.patch
frameworks#av#0002_media_ext.patch                                                 frameworks#base#0006_cec.patch          frameworks#base#0012_earc.patch            hardware#interfaces#0001_ad.patch
frameworks#av#0003_audio_camera.patch                                              frameworks#base#0006_passthrough.patch  frameworks#base#0013_earc.patch            hardware#libhardware#0001_ad.patch
frameworks#av#0004_media_ext.patch                                                 frameworks#base#0006_soundbar.patch     frameworks#base#0013_earctx_cds.patch      system#media#0001_ad.patch
frameworks#av#0006_ad.patch                                                        frameworks#base#0007_cec.patch          frameworks#base#0014_cec.patch             system#vold#0001_udisk.patch
frameworks#base#0001_stability.patch                                               frameworks#base#0007_passthrough.patch  frameworks#base#0014_earc.patch            system#vold#0002_ntfs_exfat.patch
frameworks#base#0001_tvinput_audio_patch.patch                                     frameworks#base#0008_cec.patch          frameworks#base#0015_cec.patch             system#vold#0003_format.patch
frameworks#base#0001_tvinput.patch                                                 frameworks#base#0008_passthrough.patch  frameworks#base#0015_earc.patch            system#vold#0005_ntfs3.patch
frameworks#base#0002_mtp.patch                                                     frameworks#base#0009_cec.patch          frameworks#base#0016_earc.patch            system#vold#0006_ntfs3.patch
frameworks#base#0002_stability.patch                                               frameworks#base#0009_passthrough.patch  frameworks#base#0016_fix_earc_crash.patch
frameworks#base#0003_bt.patch                                                      frameworks#base#0010_audio.patch        frameworks#base#0017_earc.patch
frameworks#base#0004_cec.patch                                                     frameworks#base#0010_cec.patch          frameworks#base#0018_earc.patch
➜  pre_submit_for_google git:(khadas-vim4-r-64bit) 

Trying to apply the patch manually

➜  av git:(test) git am -q /media/evgen/khadas/android11/vendor/amlogic/common/pre_submit_for_google//WaitGoogleMerge/frameworks#av#0001_media_ext.patch
error: patch failed: media/extractors/tests/Android.bp:49
error: media/extractors/tests/Android.bp: patch does not apply
error: patch failed: media/libmediaplayerservice/MetadataRetrieverClient.cpp:42
error: media/libmediaplayerservice/MetadataRetrieverClient.cpp: patch does not apply
error: patch failed: media/libstagefright/ACodec.cpp:63
error: media/libstagefright/ACodec.cpp: patch does not apply
error: patch failed: media/libstagefright/Android.bp:285
error: media/libstagefright/Android.bp: patch does not apply
error: patch failed: media/libstagefright/Utils.cpp:46
error: media/libstagefright/Utils.cpp: patch does not apply
error: patch failed: media/libstagefright/rtsp/Android.bp:28
error: media/libstagefright/rtsp/Android.bp: patch does not apply
error: patch failed: media/libstagefright/tests/extractorFactory/Android.bp:32
error: media/libstagefright/tests/extractorFactory/Android.bp: patch does not apply
error: patch failed: media/libstagefright/tests/writer/Android.bp:28
error: media/libstagefright/tests/writer/Android.bp: patch does not apply
error: patch failed: media/libstagefright/webm/tests/Android.bp:31
error: media/libstagefright/webm/tests/Android.bp: patch does not apply
error: patch failed: media/libstagefright/xmlparser/Android.bp:1
error: media/libstagefright/xmlparser/Android.bp: patch does not apply
error: patch failed: media/libstagefright/xmlparser/MediaCodecsXmlParser.cpp:138
error: media/libstagefright/xmlparser/MediaCodecsXmlParser.cpp: patch does not apply
error: media/libstagefright/xmlparser/XmlParser.go: already exists in index
error: patch failed: media/mediaserver/Android.bp:26
error: media/mediaserver/Android.bp: patch does not apply
Patch failed at 0001 frameworks: add codec ext and load amnuplayer for R. [1/1]
hint: Use 'git am --show-current-patch' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

This patch duplicate commit https://github.com/khadas/android_frameworks_av/commit/ead669b43f46820b81897643ef40fa35dea10671. I already have it in my repository. I commented out patches applying and try to build

@EvgenSen Those patches don’t need to be manually applied. Please restore them back.
Please execute the following command and paste the corresponding information to view it.

vim4/build$ ls -l envsetup.sh 
lrwxrwxrwx 1 hlm hlm 16 Jan 12 16:32 envsetup.sh -> make/envsetup.sh
vim4/build$
vim4/build$
vim4/build$  git diff
diff --git a/envsetup.sh b/envsetup.sh
deleted file mode 100644
index 09ab724..0000000
--- a/envsetup.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright (C) 2019 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# This is an implementation detail of build.sh and friends. Do not source
-# directly as it will spoil your shell and make build.sh unusable. You have
-# been warned! If you have a good reason to source the result of this file into
-# a shell, please let kernel-team@android.com know and we are happy to help
-# with your use case.
-
-
-# This is a dummy to not break people that have a workflow that includes
-# sourcing build/envsetup.sh into a shell when working with Android repo.
-# The actual functionality of this script has been moved to _setup_env.sh.
-#
-# It turns out that build/envsetup.sh was sourced into the shell by a lot of
-# people. Mostly due to the fact that old documentation asked people to do so
-# (including this script itself). Unfortunately, this causes more harm than it
-# does any good. Mostly it spoils the shell with environment variables that are
-# only valid in the context of a very specific build configuration. To overcome
-# this, the content of this file has been moved to _setup_env.sh and callers
-# within this project have been adjusted. This script serves as a dummy to not
-# break people sourcing it, but it will from now on emit a deprecation warning.
-# That script might be removed at a later time.
-#
-# For further information on the Android Kernel build process with the tooling
-# of this project, please refer to
-# https://source.android.com/setup/build/building-kernels.
-#
-# For any questions or concerns, please contact kernel-team@android.com.
-
-echo "Sourcing 'build/envsetup.sh' for Android Kernels is deprecated and no longer valid!"
-echo "Please refer to the documentation in said script for details."
diff --git a/envsetup.sh b/envsetup.sh
new file mode 120000
index 0000000..479006f
--- /dev/null
+++ b/envsetup.sh
@@ -0,0 +1 @@
+make/envsetup.sh
\ No newline at end of file

Thank you for answer.

I tried to apply the patch manually to see the error output. Im aborted it.

My command output is the same:

evgen@evgwork:/media/evgen/khadas/android11$ cd build/
evgen@evgwork:/media/evgen/khadas/android11/build$ ls -l envsetup.sh 
lrwxrwxrwx 1 evgen evgen 16 апр 14 18:33 envsetup.sh -> make/envsetup.sh
evgen@evgwork:/media/evgen/khadas/android11/build$ git diff
diff --git a/envsetup.sh b/envsetup.sh
deleted file mode 100644
index 09ab724..0000000
--- a/envsetup.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright (C) 2019 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# This is an implementation detail of build.sh and friends. Do not source
-# directly as it will spoil your shell and make build.sh unusable. You have
-# been warned! If you have a good reason to source the result of this file into
-# a shell, please let kernel-team@android.com know and we are happy to help
-# with your use case.
-
-
-# This is a dummy to not break people that have a workflow that includes
-# sourcing build/envsetup.sh into a shell when working with Android repo.
-# The actual functionality of this script has been moved to _setup_env.sh.
-#
-# It turns out that build/envsetup.sh was sourced into the shell by a lot of
-# people. Mostly due to the fact that old documentation asked people to do so
-# (including this script itself). Unfortunately, this causes more harm than it
-# does any good. Mostly it spoils the shell with environment variables that are
-# only valid in the context of a very specific build configuration. To overcome
-# this, the content of this file has been moved to _setup_env.sh and callers
-# within this project have been adjusted. This script serves as a dummy to not
-# break people sourcing it, but it will from now on emit a deprecation warning.
-# That script might be removed at a later time.
-#
-# For further information on the Android Kernel build process with the tooling
-# of this project, please refer to
-# https://source.android.com/setup/build/building-kernels.
-#
-# For any questions or concerns, please contact kernel-team@android.com.
-
-echo "Sourcing 'build/envsetup.sh' for Android Kernels is deprecated and no longer valid!"
-echo "Please refer to the documentation in said script for details."
diff --git a/envsetup.sh b/envsetup.sh
new file mode 120000
index 0000000..479006f
--- /dev/null
+++ b/envsetup.sh
@@ -0,0 +1 @@
+make/envsetup.sh
\ No newline at end of file

The problem was that after the repo sync and git lfs pull the repository already contained the commits from the patches, so patching was failed

@EvgenSen First, confirm that the downloaded code is normal. Execute the following command and paste the corresponding information.

vim4$ repo status

Confirm that the required tool links are installed.
https://docs.khadas.com/products/sbc/vim4/development/android/install-toolchains

Thanks for the help. I followed all steps from VIM4 Android [Khadas Docs]. Now the firmware build successfully.


#### build completed successfully (10:26:59 (hh:mm:ss)) ####

evgen@evgwork:/media/evgen/khadas/android11$ ls -la out/target/product/kvim4/update.img 
-rw-rw-r-- 1 evgen evgen 1922742920 апр 17 23:22 out/target/product/kvim4/update.img

@EvgenSen What is the root cause?

diff --git a/auto_patch.sh b/auto_patch.sh
index 9ac42dc..7636cdb 100755
--- a/auto_patch.sh
+++ b/auto_patch.sh
@@ -32,13 +32,13 @@ function auto_patch()
                 cd $dir; git log -n 100 | grep $change_id 1>/dev/null 2>&1;
                 if [ $? -ne 0 ]; then
                     #echo "###patch ${file##*/}###      "
-                    cd $dir; git am -q $file 1>/dev/null 2>&1;
-                    if [ $? != 0 ]
-                    then
-                        git am --abort
-                        echo " Error : Failed to patch [$file], Need check it.exit"
-                        exit
-                    fi
+                    # cd $dir; git am -q $file 1>/dev/null 2>&1;
+                    # if [ $? != 0 ]
+                    # then
+                    #     git am --abort
+                    #     echo " Error : Failed to patch [$file], Need check it.exit"
+                    #     exit
+                    # fi
                 fi
             fi
         fi

I commented out patches applying, because submodules already have this commits.

➜  tests git:(test) pwd
/media/evgen/khadas/android11/frameworks/av/media/extractors/tests
➜  tests git:(test) head '/media/evgen/khadas/android11/vendor/amlogic/common/pre_submit_for_google/WaitGoogleMerge/frameworks#av#0001_media_ext.patch' 
From b53da898b461f6af54ec903ddc2fcf8342154839 Mon Sep 17 00:00:00 2001
From: "shilong.yang" <shilong.yang@amlogic.com>
Date: Fri, 13 Nov 2020 14:33:15 +0800
Subject: [PATCH] frameworks: add codec ext and load amnuplayer for R. [1/1]

➜  tests git:(test) git log | grep "frameworks: add codec ext and load amnuplayer for R."
    frameworks: add codec ext and load amnuplayer for R. [1/1]
➜  tests git:(test)  
➜  tests git:(test) git log --oneline
627b22ec9a (HEAD -> test, m/khadas-vim4-r-64bit, github/khadas-vim4-r-64bit) TvAudio:Adjust the device priority when setting the volume [1/1]
48baed0e69 audio: add implementation for TV related API
48b651bea2 xmlparser: modify dts mime type. [1/1]
fa4a36c802 TvAudio: headphone have a higher priority than ARC [3/3]
41fe7f9c73 audio: bringup headphone on AM301 [4/4]
8801b04ea2 TvAudio: Merger code from google to fix recordthread abort isuue [1/1]
acb29e1cff APM: modify the istv prop name [1/1]
9b6a312181 TimeCheck: native mediaserver always OK [1/1]
25e42a2d4c AudioPolicy: change max audio effect cpu load size for armA53 cts [1/1]
2981d9a2e8 TvAudio: Merge from P and Q to R autopatchs [1/1]
d9589a0019 pre_submit_for_google: Camera app adapts to Android R [1/3]
1e663a667a audio: fix camera record no audio issue [1/1]
2f67359fc3 frameworks: fix set profile error [1/1]
ead669b43f frameworks: add codec ext and load amnuplayer for R. [1/1]

Why did it happen so? Unfortunately, I do not know