Mac环境: MacOS 10.13.2
Xcode9.2 (这里是个大坑, xcode 9 有bug, 后来换成了Xcode 8.3.3)
Android 源码版本: 6.0.1
JDK: 1.7
下载用的清华镜像https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/?utm_source=tuicool&utm_medium=referral
编译参考:http://blog.csdn.net/loften_93663469/article/details/51503293
1. 编译阶段大坑
n file included from external/libcxx/src/any.cpp:10: In file included from external/libcxx/include/experimental/any:84:
external/libcxx/include/cstdlib:167: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:115:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT
{return labs(__x);} ^
解决方案, 换低版本的Xcode 8.3.3 , 原始链接:https://stackoverflow.com/questions/47060910/error-declaration-conflicts-with-target-of-using-declaration-already-in-scope
2. xt_DSCP.h 居然找不到了. 参考:http://www.bijishequ.com/detail/366928
报错信息
In file included from out/target/product/generic/obj/STATIC_LIBRARIES/libext4_intermediates/libipt_ECN.c:11:0:
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.
make: *** [out/target/product/generic/obj/STATIC_LIBRARIES/libext4_intermediates/libipt_ECN.o] Error 1
make: *** Waiting for unfinished jobs....
解决方案:新建文件xt_DSCP.h把以下代码放到
external/iptables/include/linux/xt_DSCP.h
/* based on ipt_FTOS.c (C) 2000 by Matthew G. Marsh <mgm@paktronix.com> * 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.7 2002/03/14 12:03:13 laforge Exp */
#ifndef _XT_DSCP_TARGET_H
#define _XT_DSCP_TARGET_H
#include <linux/netfilter/xt_dscp.h>
#include <linux/types.h>
/* target info */
struct xt_DSCP_info {
__u8 dscp;
};
struct xt_tos_target_info {
__u8 tos_value;
__u8 tos_mask;
};
#endif /* _XT_DSCP_TARGET_H */
3. 导入Android Studio 参见:http://blog.csdn.net/zhbpd/article/details/48008601
跟目录运行下面三行命令就好了
source build/envsetup.sh
mmm development/tools/idegen
development/tools/idegen/idegen.sh
最后附上修改的环境变量~/.bash_profile 如果没有这个文件要新建一个
# 如果有REPO_URL环境变量 ,会替换repo原始的google地址
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
# export PATH=/opt/local/bin:$PATH
export PATH=/opt/local/bin:$PATH
#如果编译Android 7.0 以上版本, 要使用java1.8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
# export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
export JAVA_HOME
CLASS_PATH="$JAVA_HOME/lib"
PATH=".$PATH:$JAVA_HOME/bin"
#set the number of open files to be 1024
ulimit -S -n 1024
参考:
repo 强制回退
https://blog.csdn.net/zhonglunshun/article/details/75332809