安装gradle:
1.下载gradle包
去这里下载需要的tar.gz包:https://services.gradle.org/distributions/
2.解压
tar zxvf gradle.tar.gz
3.移动到/usr/local/
mv gradle /usr/local/gradle
4.配置/etc/profile环境变量
vim /etc/profile 添加以下内容
export GRADLE_HOME=/usr/local/gradle
export PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin:${GRADLE_HOME}/bin
安装jdk:
1.下载jdk包
去这里下载需要的tar.gz包:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2.解压
tar zxvf jdk.tar.gz
3.移动到/usr/local/java
mv jkd /usr/local/java
4.配置/etc/profile环境变量
export JAVA_HOME=/usr/local/java/jdk1.8.0_111
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin
安装android sdk:
1.下载android sdk
下载SDK,下载地址:http://developer.android.com/sdk/index.html
2.因为SDK只有32位的,如果装的是64位系统,则要安装ia32-libs,运行32位程序
yum install glibc.i686
3.下载完成后解压,在终端进入到SDK的根目录,然后执行:tools/android update sdk --no-ui即可
4.配置/etc/profile环境变量
export ANDROID_HOME=/usr/local/android-sdk-linux
export PATH=${ANDROID_HOME}/tools:${PATH}:${ANDROID_HOME}/platform-tools:$PATH
5.在终端输入:android,如果Android SDK Manager窗口出来了,就证明环境配置成功
6.进入$SDK_HOME/toos目录,命令窗口运行:./android avd(可选操作)
2016-12-05添加自动构建脚本
代码思想:
1.记录错误日志,并发送错误信息给相关人员
2.每天定时检测有更新就打包,没有更新就记录日志
3.将打好的apk压缩移动到指定位置
#!/usr/bin/env python
#coding:utf8
import os
import time
import smtplib
from email.mime.text import MIMEText
mailto_list = ['xxoo.qin@fantasee.cn','xx@fantasee.cn','oo@fantasee.cn']
mail_host = "smtp.163.com" # 设置服务器
mail_user = "xianyin0@163.com" # 用户名
mail_pass = "5213344" # 口令
def send_mail(to_list, sub, content):#有错误发送邮件
me='xianyin0@163.com'
msg = MIMEText(content, format, 'utf-8')
msg["Accept-Language"] = "zh-CN"
msg["Accept-Charset"] = "ISO-8859-1,utf-8"
msg = MIMEText(content)
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ",".join(to_list)
try:
server = smtplib.SMTP()
server.connect(mail_host)
server.login(mail_user, mail_pass)
server.sendmail(me, to_list, msg.as_string())
server.close()
except Exception as e:
print(str(e))
def logger(content):#记录日志
date = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
with open('/root/log.txt','a') as f:
f.write('[%s]:%s\n'%(date,content))
def yunpos2():#yunpos2打包apk代码
os.chdir(r'/usr/local/yunpos2/pos/yunpos')
content=os.popen('svn up')
data = content.read()
if len(data)>50:
try:
data0=os.popen(r'gradle aR')
os.chdir(r'/usr/local/yunpos2/pos/yunpos/app/build/outputs/apk/')
data2 = os.popen('ls')
for i in data2.readlines():
pass
date2 = i.split('_',4)[0] + '_' + i.split('_',4)[1] + '_' + i.split('_',4)[2] + '_' + i.split('_',4)[3]
os.system(r'zip -r /var/ftp/apk/%s.zip yunpos2*.apk'%date2)
os.system('rm -rf yunpos2*.apk')
except:
logger('yunpos2打包失败')
send_mail(mailto_list, "yunpos2 packaging failure",data)
else:
logger('yunpos2代码没有更新')
def possdk():#possdk打包apk代码
os.chdir(r'/usr/local/yunpos2/pos/possdk')
content=os.popen('svn up')
data = content.read()
if len(data)>50:
try:
os.system(r'gradle aR')
os.chdir(r'/usr/local/yunpos2/pos/possdk/app/build/outputs/apk')
data2 = os.popen('ls')
for i in data2.readlines():
date2 = i.split('_',4)[0] + '_' + i.split('_',4)[1] + '_' + i.split('_',4)[2] + '_' + i.split('_',4)[3]
break
os.system(r'zip -r /var/ftp/apk/%s.zip yunpos*.apk'%date2)
os.system('rm -rf yunpos*.apk')
except:
logger('possdk打包失败')
send_mail(mailto_list, "possdk packaging failure",data)
else:
logger('possdk代码没有更新')
def yunpos():#yunpos打包apk代码
os.chdir(r'/usr/local/yunpos/android/yunpos')
content=os.popen('svn up')
data = content.read()
if len(data)>50:
try:
os.system(r'gradle aR')
os.chdir(r'/usr/local/yunpos/android/yunpos/build/outputs/apk')
data2 = os.popen('ls')
for i in data2.readlines():
date2 = i.split('_',4)[0] + '_' + i.split('_',4)[1] + '_' + i.split('_',4)[2] + '_' + i.split('_',4)[3]
break
os.system(r'zip -r /var/ftp/apk/%s.zip yunpos*.apk'%date2)
os.system('rm -rf yunpos*.apk')
except:
logger('yunpos打包失败')
send_mail(mailto_list, "yunpos packaging failure",data)
else:
logger('yunpos代码没有更新')
if __name__=='__main__':
yunpos2()
possdk()
yunpos()