centos编译android源码,在centos7上编译android app

简介

拷贝进入源码,直接可以在断网环境下编译

注意:当源码的工具链升级的时候,需要重新升级该环境

搭建虚拟机环境

安装virtual box,然后在里面装入centos7的虚拟机

http://centos.org/

https://www.virtualbox.org/

配置虚拟机网络

cd  /etc/sysconfig/network-scripts/

vi  ifcfg-e...

把ONBOOT改为yes

重启网络

准备一个本地目录作为共享文件夹

vi ~/.bashrc

最下面加入

mount -t vboxsf shareName /shareDir

其中shareName是你共享文件夹的名字

/shareDir是虚拟机中共享文件夹的位置

安装virtualbox增强功能

yum update

yum install gcc

yum install gcc-c++

yum install make

yum install kernel-headers

yum install kernel-devel

yum groupinstall "Development Tools"

在虚拟机的菜单-设备-安装增强功能,在虚拟机中执行

mkdir /mnt

mount /dev/cdrom /mnt //有的操作系统可能是cdrom1

cd /mnt

./VBoxLinuxAddtions.run

如果提示Please install the build and header files for your current Linux kernel,就执行

yum install kernel-devel

ln -s /usr/src/kernels/2.6.18-194.32.1.el5-i686/ /usr/src/linux

安装个java

yum -y list java*

yum -y install java-1.8.0-openjdk*

##搭建Android编译环境

下载一个android的命令行工具

从https://developer.android.google.cn/studio/index.html

下载一个sdk-tools-linux-3859397.zip

放入共享文件夹中

使用android命令行工具下载相应的support工具

进入虚拟机的android-sdk-linux/tools目录

执行./android list sdk

根据项目所需的工具下载

./android update sdk -u -t build-tools-25.3.0

./android update sdk -u -t platform,platform-tool

也可以根据.android list sdk提示用序号下载

例如:./android update sdk  -u -t 35

这一步很关键,之后的编译中,如果发现什么包没找到,都可以在这里下载相应的工具

配置环境变量

vi ~/.bashrc

最下面加入

export ANDROID_HOME={之前配置的共享位置路径shareDir}/android-sdk-linux

export PATH=${ANDROID_HOME}/tools:${PATH}

export PATH=${ANDROID_HOME}/platform-tools:${PATH}

export PATH=${ANDROID_HOME}/ndk-bundle:${PATH}

编译android

编辑local.properties,修改

ndk.dir= {android-sdk-linux里的ndk路径}

sdk.dir= {android-sdk-linux路径}

执行./gradlew assembleRelease

这个时候会下载许多东西,稍安勿躁

如果失败请自行根据log去百度查询解决方法

之前碰到的是在centos6上libc工具链版本不对

升级libc又遇到其他工具的依赖问题

所以采用centos7进行编译

如果编译结束显示Information:BUILD SUCCESSFUL,恭喜,你已经成功了99.99%

将用户根目录下的.android和.gradle拷贝到共享目录

为了验证是否成功,我们再装一个新虚拟机测试一下

搭建完新虚拟机环境后

把共享目录mount进来,将.android和.gradle拷贝到新虚拟机的用户根目录下

配置好Android的环境变量,参见本节第三小节

然后把源码拷贝到新虚拟机,断网,然后在源码根目录下执行./gradlew assembleRelease

如果显示Information:BUILD SUCCESSFUL,就成功了。

共享文件夹中的.android .gradle android-sdk-linux就是我们的所有的编译工具了

//如果提示./android命令废弃不能用了,就用sdkmanager

Thesdkmanageris a command line tool that allows you to view, install, update, and uninstall packages for the Android SDK. If you're using Android Studio, then you do not need to use this tool and you can insteadmanage your SDK packages from the IDE.

Thesdkmanagertool is provided in the Android SDK Tools package (25.2.3 and higher) and is located inandroid_sdk/tools/bin/.

Usage

You can use thesdkmanagerto perform the following tasks.

List installed and available packages

sdkmanager --list [options]

Install packages

sdkmanager packages [options]

Thepackagesargument is an SDK-style path as shown with the--listcommand, wrapped in quotes (for example,"build-tools;26.0.2"or"platforms;android-26"). You can pass multiple package paths, separated with a space, but they must each be wrapped in their own set of quotes.

For example, here's how to install the latest platform tools (which includesadbandfastboot)andthe SDK tools for API level 26:

sdkmanager "platform-tools" "platforms;android-26"

Alternatively, you can pass a text file that specifies all packages:

sdkmanager --package_file=package_file [options]

Thepackage_fileargument is the location of a text file in which each line is an SDK-style path of a package to install (without quotes).

To uninstall, simply add the--uninstallflag:

sdkmanager --uninstall packages [options]sdkmanager --uninstall --package_file=package_file [options]

Update all installed packages

sdkmanager --update [options]

Options

The following table lists the available options for the above commands.

OptionDescription

--sdk_root=pathUse the specified SDK path instead of the SDK containing this tool

--channel=channel_idInclude packages in channels up to channel_id. Available channels are:

0(Stable),1(Beta),2(Dev), and3(Canary).

--include_obsoleteInclude obsolete packages in the package listing or package updates. For use with--listand--updateonly.

--no_httpsForce all connections to use HTTP rather than HTTPS.

--verboseVerbose output mode. Errors, warnings and informational messages are printed.

--proxy={http | socks}Connect via a proxy of the given type: eitherhttpfor high level protocols such as HTTP or FTP, orsocksfor a SOCKS (V4 or V5) proxy.

--proxy_host={IP_address|DNS_address}IP or DNS address of the proxy to use.

--proxy_port=port_numberProxy port number to connect to.

Note: If you want to install packages for an operating system different from the current machine, set the REPO_OS_OVERRIDE environment variable to either "windows", "macosx", or "linux".

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值