android源码编译 坑

2023-05-16

-bash: lunch: command not found

先调用

. build/envsetup.sh

再执行

lunch 

Can not find SDK

Can not find SDK 10.6 at /Developer/SDKs/MacOSX10.6.sdk

网上说法: 把 ==build/core/combo/mac_version.mk== 中的 ==mac_sdk_versions_supported== 版本问题, 只要修改一下, 对应你的 ==/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs== 下面 MacOSX 版本就行了.
但是我这边试了并不行, 还是得屁颠屁颠跑去下载了低版本 SDKs.

然而下载 10.6 版本会出现下面这个问题

DVTSDK: Skipped SDK xxxx; its version (10.6) is below required minimum (10.11) for the macosx platform.

说最少得用 10.11 版本... 好吧, 下载 10.11 版本

DVTSDK: Skipped SDK /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk; its version (10.9) is below required minimum (10.11) for the macosx platform.

如果你 SDKs 里面有 10.6 还是会提示一大堆东西 ( 是默认优先去加载 10.6 了??? ), 这个时候, 只要把10.6 移除就行了.

JDK

Unable to find any JVMs

该问题是找不到java版本

Unable to find any JVMs matching version "1.7". 

可以先 open /Library/Java/JavaVirtualMachines/
看一下你本机是否有JDK了, 如果没有或者版本比Android源码要求的高, 都去下载, 然后把该 openjdk/Contents/Home 放到环境内 ~/.bash_profile

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
export ANDROID_JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home

tools.jar

找不到 tools.jar, 因为一开始我用的是 12.0.1 版本, 在 JDK9 的时候, 官方就移除了 tools.jar
所以我们要下载 JDK8, 然后把相对应的 tools.jar 移过来就行 然而经自己测试了一下, 还是有问题, 所以不要搞啥花里胡哨的, 直接下载 JDK 7 (源码对应JDK)

Error: could not find jdk tools.jar

The required version is: "1.7.x"

JDK 还是报错说不要用 12.0.1 版本, 这个下载 JDK 7 就行了

You are attempting to build with the incorrect version
of java.
 
Your version is: openjdk version "12.0.1" 2019-04-16 OpenJDK Runtime Environment (build 12.0.1+12) OpenJDK 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing).
The required version is: "1.7.x"
 
Please follow the machine setup instructions at
    https://source.android.com/source/initializing.html

下载之后, 设置 ~/.bash_profile

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
export ANDROID_JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home

但是我碰到了, 设置还是不行
然后先查询现在的版本

/usr/libexec/java_home -V

设置版本
其实就是直接在当前命令窗口导入环境变量, 这个指标不治本, 后来自己再测了一下, 源码自己修改了 .bash_profile 文件, 但是没去导入它 (或者重新打开窗口), 这样环境变量就没有改变 =_=

export JAVA_HOME=`/usr/libexec/java_home -v 1.7.0_80`

再次, 查询, 很好, 当前环境变量已经调过来了, 然后继续执行 make -j4

java -version

bison

解决一

bison 有问题, 出现 Abort trap: 6
https://blog.csdn.net/camlot_/article/details/86540502
网站说的路径不太对, 最终自己找到的路径是 ==/opt/local/bin/bison== , 就是一开始配置环境 Macports 下载的时候, 会下到这个路径下
然而如果自己用 brew install Bison 就是在这个路径下 /usr/local/Cellar/bison/版本/bin/bison

prebuilts/misc/darwin-x86/bison/bison -d  -o out/host/darwin-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp frameworks/base/tools/aidl/aidl_language_y.y
make: *** [out/host/darwin-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] Abort trap: 6
make: *** Waiting for unfinished jobs....
注: 某些输入文件使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
注: 某些输入文件使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。

把 bison 创建一个快捷方式到某个路径下

ln -s 源文件路径 目标路径

解决二

编译 8.0 的时候查出来的

FAILED: out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.cpp out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.h 
BISON_PKGDATADIR=external/bison/data prebuilts/misc/darwin-x86/bison/bison -d  --defines=out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.h -o out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.cpp system/tools/aidl/aidl_language_y.yy
[  1% 971/59651] cc out/soong/.intermediates/system/...armv7-a_static_core/obj/system/core/adf/libadf/adf.
ninja: build stopped: subcommand failed.
11:00:22 ninja failed with: exit status 1
make: *** [run_soong_ui] Error 1

网上说到这个目录下, 然后更新指定 git 版本, 但是我这边根本更不了... .git 文件夹就是坏的

cd external/bison
git cherry-pick c0c852bd6fe462b148475476d9124fd740eba160

上面说的copy一个bison到这个文件夹, 也是不行的....
后面找到了这个, 自己去编译一个 bison 出来 (上面的 git cherry-pick 就是打补丁, 而这个是手动打补丁)
https://blog.csdn.net/h649305597/article/details/80322488

  1. 到该文件夹下

cd external/bison
  1. 创建 patch-high-sierra.patch

touch patch-high-sierra.patch
  1. 并把下面代码复制进去

With format string strictness, High Sierra also enforces that %n isn't used
in dynamic format strings, but we should just disable its use on darwin in
general.

--- lib/vasnprintf.c.orig   2017-06-22 15:19:15.000000000 -0700
+++ lib/vasnprintf.c    2017-06-22 15:20:20.000000000 -0700
@@ -4869,7 +4869,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *
 #endif
                   *fbp = dp->conversion;
 #if USE_SNPRINTF
-# if !(((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
+# if !defined(__APPLE__) && !(((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
                 fbp[1] = '%';
                 fbp[2] = 'n';
                 fbp[3] = '\0';
  1. 在控制台(保证当前目录是external/bison)执行 (这个是打补丁的意思??)

patch -p0 < patch-high-sierra.patch
  1. 返回源码根目录

cd ../..
  1. 编译 bison

make bison
  1. 复制编译好的 bison 到执行位置

cp ./out/host/darwin-x86/obj/EXECUTABLES/bison_intermediates/bison ./prebuilts/misc/darwin-x86/bison/bison 

XcodeDefault.xctoolchain

external/libcxx/include/cstdlib:159:44: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) _NOEXCEPT {return  labs(__x);}
                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h:111:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) _NOEXCEPT {return  labs(__x);}
                                           ^
external/libcxx/include/cstdlib:134:9: note: using declaration
using ::abs;
        ^
external/libcxx/include/cstdlib:161:44: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h:113:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
                                           ^
external/libcxx/include/cstdlib:134:9: note: using declaration
using ::abs;
        ^
external/libcxx/include/cstdlib:164:42: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) _NOEXCEPT {return  ldiv(__x, __y);}
                                         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h:116:42: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) _NOEXCEPT {return  ldiv(__x, __y);}
                                         ^
external/libcxx/include/cstdlib:139:9: note: using declaration
using ::div;
        ^
external/libcxx/include/cstdlib:166:42: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}
                                         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h:118:42: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}

20 errors generated.
make: *** [out/host/darwin-x86/obj/STATIC_LIBRARIES/libc++_static_intermediates/src/algorithm.o] Error 1
4 errors generated.
make: *** [out/host/darwin-x86/obj/STATIC_LIBRARIES/libc++_static_intermediates/src/ios.o] Error 1

查了一下, 说需要换低版本XCode
下载 XCode 8.3.3, 好吧, 又是一阵等待
下载好之后, 选中 Xcode_8.3.3 为默认

sudo xcode-select -switch /Applications/Xcode_8.3.3.app/Contents/Developer

再次 make -j4

dyld: Symbol not found: _OBJC_IVAR_$_NSTextViewIvars.sharedData
  Referenced from: /Applications/Xcode_8_3_3.app/Contents/SharedFrameworks/DVTDocumentation.framework/Versions/A/../../../../SharedFrameworks/DVTKit.framework/Versions/A/DVTKit
  Expected in: /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
 in /Applications/Xcode_8_3_3.app/Contents/SharedFrameworks/DVTDocumentation.framework/Versions/A/../../../../SharedFrameworks/DVTKit.framework/Versions/A/DVTKit
make: error: unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly!
make: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch

然而....又报错, 说不支持, 查了一下, 说 Mojave 不支持 10.0 以下的 XCode... oh my god! 很崩溃! 退版本这个是不存在的...
好吧, 有点绝望, 各种踩坑, 这个是弄了最久的, 网上各种资料, 都无法解决.

后来再自己仔细研究了一下, 其实这些报错, 是指向 XcodeDefault.xctoolchain

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h:118:42

那么是否能通过不替换XCode, 而是替换XCode下面的这个来作为一个中转方法呢???
测试了一下, 是可以了!! (≧▽≦)/

大致就是做两步

  1. 下载 8.3.3 XCode
  2. 把 8.3.3 XCode 的 XcodeDefault.xctoolchain, 放到现在的 XCode 中, 记得, 不要删除原有的, 以后还要继续用XCode呢, 备份一下. 然后替换掉就行.

在这里插入图片描述

目前使用下来, 是没发现有什么问题
这段时间没有打开XCode过, 不知道会影响 XCode 什么问题, 建议打开XCode 之前, 先把这个改回来.

xt_DSCP.h

找不到 xt_DSCP.h 文件

external/iptables/extensions/../include/linux/netfilter_ipv4/ipt_ECN.h:13:37: fatal error: linux/netfilter/xt_DSCP.h: No such file or directory
 #include <linux/netfilter/xt_DSCP.h>
                                     ^
compilation terminated.

修改 external/iptables/include/linux/netfilter_ipv4/ipt_ECN.h 文件

#include <linux/netfilter/xt_DSCP.h>

改成

#include <linux/netfilter/xt_dscp.h>

如果你 linux/netfilter 没有 xt_dscp.h 文件, 那么可以直接创建 xt_DSCP.h

/* x_tables module for matching the IPv4/IPv6 DSCP field
 *
 * (C) 2002 Harald Welte <laforge@gnumonks.org>
 * This software is distributed under GNU GPL v2, 1991
 *
 * See RFC2474 for a description of the DSCP field within the IP Header.
 *
 * xt_dscp.h,v 1.3 2002/08/05 19:00:21 laforge Exp
*/
#ifndef _XT_DSCP_H
#define _XT_DSCP_H

#include <linux/types.h>

#define XT_DSCP_MASK    0xfc    /* 11111100 */
#define XT_DSCP_SHIFT   2
#define XT_DSCP_MAX 0x3f    /* 00111111 */

/* match info */
struct xt_dscp_info {
    __u8 dscp;
    __u8 invert;
};

struct xt_tos_match_info {
    __u8 tos_mask;
    __u8 tos_value;
    __u8 invert;
};

#endif /* _XT_DSCP_H */

make update-api

******************************
You have tried to change the API from what has been previously approved.

To make these errors go away, you have two choices:
   1) You can add "@hide" javadoc comments to the methods, etc. listed in the
      errors above.

   2) You can update current.txt by executing the following command:
         make update-api

      To submit the revised current.txt to the main Android repository,
      you will need approval.
******************************



make: *** [out/target/common/obj/PACKAGING/checksystemapi-current-timestamp] Error 38

******************************
You have tried to change the API from what has been previously released in
an SDK.  Please fix the errors listed above.
******************************


make: *** [out/target/common/obj/PACKAGING/checksystemapi-last-timestamp] Error 38

根据提示, 执行

make update-api

其他

bash_profile 配置

bash_profile配置, 这里就列一下我的配置吧

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

# wxq Android NDK
#export NDK_HOME=~/android-ndk-r11c
export NDK_HOME=~/Library/Android/sdk/ndk-bundle
export NDK_PROJECT_PATH='/Applications/Android\ Studio.app'
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export PATH=$PATH:$NDK_HOME/
export PATH=$PATH:$ANDROID_SDK_ROOT

# wxq Android 6
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
export ANDROID_JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home


# wxq Android源码编译, 在 Mac OS 中,可同时打开的文件描述符的默认数量上限太低,在高度并行的编译流程中,可能会超出此上限。要提高此上限
# set the number of open files to be 1024
ulimit -S -n 1024

# 这个是下载 MacPorts 自动配置上去的
##
# Your previous /Users/wangxingqian/.bash_profile file was backed up as /Users/wangxingqian/.bash_profile.macports-saved_2019-05-20_at_11:34:23
##

# MacPorts Installer addition on 2019-05-20_at_11:34:23: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.

FAILED: /bin/bash -c “(prebuilts/sdk/tools/jack-admin install-server prebuilts/sdk/tools/jack-launcher.jar prebuilts/sdk/tools/jack-server-4.8.ALPHA.jar 2>&1 || (exit 0) ) && (JACK_SERVER_VM_ARGUMENTS=\”-Dfile.encoding=UTF-8 -XX:+TieredCompilation\” prebuilts/sdk/tools/jack-admin start-server 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update server prebuilts/sdk/tools/jack-server-4.8.ALPHA.jar 4.8.ALPHA 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-2.28.RELEASE.jar 2.28.RELEASE || exit 47; prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-3.36.CANDIDATE.jar 3.36.CANDIDATE || exit 47; prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-4.7.BETA.jar 4.7.BETA || exit 47 )”
Unsupported curl, please use a curl not based on SecureTransport
Jack server installation not found
Unsupported curl, please use a curl not based on SecureTransport
Unsupported curl, please use a curl not based on SecureTransport

这个问题是因为本地的curl和Jack编译工具链不兼容。

  • 解决方法:可以
    brew install curl --with-openssl
    
    来安装一个基于OpenSSL的curl,
  • (如果上面的命令错误,使用brew install curl-openssl)。接着修改环境变量以使用新的curl:
  • export PATH=$(brew --prefix curl)/bin:$PATH
  • brew –prefix curl返回通过brew安装的curl的路径信息。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android源码编译 坑 的相关文章

随机推荐

  • CMake 使用

    1 前言 当在做 Android NDK 开发时 xff0c 如果不熟悉用 CMake 来构建 xff0c 读不懂 CMakeLists txt 的配置脚本 xff0c 很容易就会踩坑 xff0c 遇到编译失败 xff0c 一个很小的配置问
  • Android 存储优化 —— MMKV 集成与原理

    前言 APP 的性能优化之路是永无止境的 这里学习一个腾讯开源用于提升本地存储效率的轻量级存储框架 MMKV 目前项目中在轻量级存储上使用的是 SharedPreferences 虽然 SP 兼容性极好 但 SP 的低性能一直被诟病 线上也
  • Android JNI(一)——NDK与JNI基础

    本片文章大纲如下 xff1a 1 导读2 什么是NDK3 为什么使用NDK4 NDK到SO5 JNI 一 导读 在Android OS上开发应用程序 xff0c Google提供了两种开发包 xff1a SDK和NDK 你可以从Google
  • Android JNI学习(四)——JNI的常用方法的中文API

    一 Interface Function Table 接口函数表 每个函数都可以通过JNIEnv参数访问 xff0c JNIEnv类型是指向一个存放所有JNI接口指针的指针 xff0c 其定义如下 xff1a typedef const s
  • 详解android项目配置签名文件的完整流程

    1 背景 接手的项目近期需要上线 xff0c 于是复习了一下项目签名文件配置流程 xff0c 这里做个系统性总结 2 最终目标 根据需求为debug包与release包配置签名文件 xff0c 快速满足中小型项目的需要 3 创建签名文件 要
  • ArrayList循环删除陷阱及迭代器介绍

    一 ArrayList循环删除陷阱 模板测试代码如下 xff1a public class ArrayListRemove public static void main String args ArrayList lt String gt
  • 启动加载器BootLoader

    启动加载器 使用u boot在qemu上模拟执行u boot命令 在嵌入式操作系统中 xff0c BootLoader是在操作系统内核运行之前运行 可以初始化硬件设备 建立内存空间映射图 xff0c 从而将系统的软硬件环境带到一个合适状态
  • EventBus3.0详细分析

    在进入主题之前 xff0c 我们先保持着这样几个疑问 xff0c EventBus的使用三要素里 xff0c 我们为什么要去定义事件方法 xff0c 并且用到了 64 subscribe 注解 xff1f EventBus getDefau
  • git 拉取远程分支到本地

    步骤 xff1a 1 新建一个空文件 xff0c 文件名为file 2 初始化 git init 3 自己要与origin master建立连接 xff08 下划线为远程仓库链接 xff09 git remote add origin gi
  • module中依赖arr

    在高版本的AndroidStudio并且使用了版本的gradle出现了上述问题可以按着如下引用 在你工程根目录下新建一个文件夹YouLib xff0c 将你的aar文件放入 xff0c 然后在该目录下新建一个build gradle文件 在
  • Android Studio aar包引用方式

    主工程 第一种方式 1 将aar包复制到app libs目录下 2 在app的build gradle文件中配置如下 xff1a android repositories flatDir dirs 39 libs 39 implementa
  • MacOs “无法打开***,因为无法验证开发者...”

    在终端执行如下指令 sudo spctl master disable 执行完上面指令后 xff0c 在 安全性与隐私 设置的 允许从以下位置下载的App 中会新增一个任何来源 xff0c 如下面的对比图 xff0c 然后应用在运行中就不会
  • mac编译android源码-创建磁盘映像

    因为mac默认的磁盘环境是不区分大小的 xff0c 而git并不支持此类文件系统 xff0c 所以我们需要创建我们所需要的磁盘映像用来存放下载的源码 首先你需要找在mac上的磁盘工具 xff0c 一般是在应用程序列表 其他文件夹里面 2 如
  • android源码编译-如何在Mac中卸载openjdk15

    说明 之前在mac上使用intellij idea时 xff0c 由于没有在Mac上安装过jdk xff0c 所以就在intellij idea中下载了openjdk15版本 后来觉得想要换一个旧点的版本 xff0c 就想卸载了openjd
  • Mac OS查看和设置JAVA_HOME

    下载java https www java com zh CN download 1 查看JAVA版本 打开Mac电脑 xff0c 查看JAVA版本 xff0c 打开终端Terminal xff0c 通过命令行查看笔者的java版本 xff
  • Android源码编译–jdk版本查询

    2 1 Android源码所需JDK版本 根参考资料 1 的说明 xff0c 在android src build core main mk中对jdk的版本进行查询 xff0c 以确定当前系统是否安装了特定版本的jdk xff0c 因此可以
  • android源码编译 ninja: build stopped: subcommand failed.

    接着编译 make j8 线程加多少个具体看机器配置 xff0c 问题也最可能是这一步骤引起的 xff0c 如果是虚拟机的话 xff0c 建议不要加线程 xff0c 直接使用make执行
  • Ubuntu环境下完美安装python模块numpy,scipy,matplotlib

    不同的ubuntu版本安装过这三个模块几次了 xff0c 然而总是出现各种问题 xff0c 最近一次是在ubuntu 16 04 LTS server版本安装的 xff0c 总的来说安装的比较顺利 先把pip安装好 sudo apt get
  • prebuilts/misc/darwin-x86/bison/bison: Bad CPU type in executable

    方案一 cd external bison touch patch high sierra patch vim patch high sierra patch With format string strictness High Sierr
  • android源码编译 坑

    bash lunch command not found 先调用 build envsetup sh 再执行 lunch Can not find SDK Can not find SDK 10 6 at Developer SDKs Ma