Compile Android Source Code
Compile Command
In android source code path
source build/envsetup.sh
lunch
make -j4
Error Message when system compile.
#swap memory too small
Example
make: *** [out/host/linux-x86/obj32/SHARED_LIBRARIES/libjavacore_intermediates/luni/src/main/native/android_system_OsConstants.o] Error 254
or
make: ** [out/target/product/generic/obj/SHARED_LIBRARIES/libwebviewchromium_intermediates/LINKED/libwebviewchromium.so] Error 1
solution
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
and modify "/etc/fstab" and inset new line "/swapfile none swap defaults 0 0", we can see this article
#Compiler Error: Permission denied.
Solution: In android source code path
sudo chmod -R 777 *
#emulator: command not found
source build/envsetup.sh
lunch full-eng
emulator &
#Miss Some packages
example A
Error Message: Can't locate Switch.pm in @INC (you may need to install the Switch module)
Solution A: Install Perl
sudo apt-get install libswitch-perl
example B
/bin/bash: flex: command not found
Solution B
sudo apt-get install flex
#jar: command not found
情境:電腦有安裝jar, 但是執行jar 指令的時候, 發生 jar: command not find
Solution: 建立symbolic link
首先先找出電腦jar檔案的路徑
#find /usr/lib -name jar
然後可能會收到類似以下的回傳訊息
/usr/lib/jvm/jdk1.6.0_37/bin/jar
代表電腦有jar, 再來是建立symbolic link, 指令如下
#sudo ln -sf /usr/lib/jvm/jdk1.6.0_37/bin/jar jar
檢測有無成功, 測試指令如下
#ll jar
若有收到以下的訊息, 代表成功
lrwxrwxrwx 1 root root 32 8月 3 18:14 jar -> /usr/lib/jvm/jdk1.6.0_37/bin/jar*
# You are using version $(MAKE_VERSION) of make.
Android can only be built by versions 3.81 and 3.82.)
see https://source.android.com/source/download.html\
修正 AOSP 路徑底下的 ./build/core/main.mk 此份檔案, 修正部份內容
ifeq (,$(findstring CYGWIN,$(shell uname -sm)))
ifeq (0,$(shell expr $$(echo $(MAKE_VERSION) | sed "s/[^0-9\.].*//") = 3.81))
ifeq (0,$(shell expr $$(echo $(MAKE_VERSION) | sed "s/[^0-9\.].*//") = 3.82))
ifeq (0,$(shell expr $$(echo $(MAKE_VERSION) | sed "s/[^0-9\.].*//") = 4.1)) #補上這行
$(warning ********************************************************************************)
$(warning * You are using version $(MAKE_VERSION) of make.)
$(warning * Android can only be built by versions 3.81 and 3.82.)
$(warning * see https://source.android.com/source/download.html)
$(warning ********************************************************************************)
$(error stopping)
endif #補上這行
endif
endif
endif
#Traceback (most recent call last):
File "../../base/android/jni_generator/jni_generator.py", line 1073, in <module>
sys.exit(main(sys.argv))
File "../../base/android/jni_generator/jni_generator.py", line 1069, in main
options.optimize_generation)
File "../../base/android/jni_generator/jni_generator.py", line 1004, in GenerateJNIHeader
jni_from_javap = JNIFromJavaP.CreateFromClass(input_file, namespace)
File "../../base/android/jni_generator/jni_generator.py", line 507, in CreateFromClass
stderr=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
external/chromium_org/ui/gl/surface_jni_headers.target.linux-arm.mk:22: recipe for target 'out/target/product/m201/obj/GYP/shared_intermediates/ui/gl/jni/Surface_jni.h' failed
原因:依照 https://groups.google.com/forum/#!topic/android-building/HOTDDDsXLmM 的解釋以及同事的說明, 應該是少設定 JAVA_HOME
解法:
export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_37/
#arm-linux-gnueabihf-gcc: not found
原因:如文字所示,電腦找不到 arm-linux-gnueabihf-gcc 這個交叉編譯器工具, 輸入以下即可
參考文章:http://tech-tacolin.blogspot.com/2013/05/x86ubuntuarmgcc-toolchain.html
解法:
sudo apt-get install gcc-arm-linux-gnueabihf
#linux/compiler-gcc5.h: No such file or directory
原因:可能是電腦交叉編譯器的版本與aosp所需要的版本不同所造成的。
參考文章:https://blog.csdn.net/haosouwj/article/details/77096936
解法:降低當前電腦交叉編譯器的版本
sudo apt install gcc-4.7-arm-linux-gnueabi