• 背景

  有一堆工程NativeAndroid程序,要一一编译部署编译测试,手头只有AndroidManifest和Makefile,需要一个个Update,Ndk-build,和发包安装测试,很是头疼,也没搜到和我类似需求的,用batch各种问题,只好换路,Python花了一上午临时抱佛脚的,如有建议欢迎指教。

  • 使用环境

-- Python3.x

-- AndroidNDK

-- AndroidSDK

-- Ant

  并确保配置好在Path中

  • 说明

看注释

  • Code
    • #!/usr/bin/python
      # -*- coding: utf-8 -*-
      #用于批量编译NativeAndroid程序
      #AutoBuild all sub native android projects
      #Zephyr 20141203
      import os
      import sys #指定编译目录名
      targetBuildDir = 'jni' #'Android'
      #指定目标Android版本
      targetVersion = 'android-18'
      #Build Configuration调试模式 debug/release
      Configuration= 'debug'
      #是否输出详细编译信息
      VerbosBuildInfo = 1
      #黑名单,如果遇到以下目录,就不再予以遍历
      blackList = ['obj','res','libs','bin','iOS','src'] #全局变量
      curRootDir = os.getcwd()
      dirVec=[] def GetProcessorCount():
      try:
      platform = sys.platform
      if platform == 'win32':
      if 'NUMBER_OF_PROCESSORS' in os.environ:
      return int(os.environ['NUMBER_OF_PROCESSORS'])
      else:
      return 8
      else:
      from numpy.distutils import cpuinfo
      return cpuinfo.cpu._getNCPUs()
      except Exception:
      print('Cannot know cpuinfo, use default 4 cpu')
      return 8 def WalkDir(rootDir, level=1):
      if level==1: print rootDir
      for lists in os.listdir(rootDir):
      path = os.path.join(rootDir, lists)
      if os.path.isdir(path):
      print '│ '*(level-1)+'│--'+lists
      if not lists in blackList:
      if lists == targetBuildDir:
      #print('-----path: '+path)
      #取得父级目录
      parentDir = os.path.dirname(path)
      #print('-----parentDir: '+parentDir)
      dirVec.append(parentDir)
      print('-----添加编译目录:'+parentDir)
      else:
      WalkDir(path, level+1) def DoBuild():
      print('---------开始DoBuild---------')
      numProcessor = GetProcessorCount()
      UpdateCMD = 'android update project -p . -s -t %s' % (targetVersion)
      print('UpdateCMD: '+UpdateCMD)
      isDebug = ( Configuration == 'debug' )
      NDKBuildCMD = 'ndk-build V=%d -j%d NDK_DEBUG=%d' % (VerbosBuildInfo, numProcessor, isDebug)
      print('NDKBuildCMD: '+NDKBuildCMD)
      AntCMD = 'ant %s install' % (Configuration)
      print('AntCMD: '+AntCMD)
      projectCount = 0
      if 1:
      for dir in dirVec:
      androidDir = dir
      print('---------开始Update---------')
      print('所在目录:'+androidDir)
      projectCount += 1
      if 1:
      os.chdir(androidDir)
      os.system(UpdateCMD)
      #依据mk文件相对路径决定是否要进入jni目录
      os.chdir('jni')
      print('==========开始编译')
      os.system(NDKBuildCMD)
      os.chdir('../')
      print('==========装包APK')
      os.system(AntCMD)
      print('==========当前处理完成:'+androidDir)
      #os.chdir(curRootDir)
      #print('---------切回主目录---------')
      projectCount += 1
      print('---------恭喜,完成%d个工程编译,已安装到设备---------' %(projectCount)) #MAIN
      WalkDir(curRootDir)
      DoBuild()
  • Code EN

    •  

      #!/usr/bin/python
      # -*- coding: utf-8 -*-
      #Batch compileNativeAndroid
      #AutoBuild all sub native android projects
      #Zephyr 20141203
      import os
      import sys #Target compile directory
      targetBuildDir = 'jni'
      #Target Android version
      targetVersion = 'android-19'
      #Build Configuration: debug/release
      Configuration= 'debug'
      #Will output detail compile info
      VerbosBuildInfo = 0
      #Blacklist for skip-directory
      blackList = ['obj','res','libs','bin','iOS','src'] #Global
      curRootDir = os.getcwd()
      dirVec=[] def GetProcessorCount():
      try:
      platform = sys.platform
      if platform == 'win32':
      if 'NUMBER_OF_PROCESSORS' in os.environ:
      return int(os.environ['NUMBER_OF_PROCESSORS'])
      else:
      return 8
      else:
      from numpy.distutils import cpuinfo
      return cpuinfo.cpu._getNCPUs()
      except Exception:
      print('Cannot know cpuinfo, use default 4 cpu')
      return 8 def WalkDir(rootDir, level=1):
      if level==1: print rootDir
      for lists in os.listdir(rootDir):
      path = os.path.join(rootDir, lists)
      if os.path.isdir(path):
      print '│ '*(level-1)+'│--'+lists
      if not lists in blackList:
      if lists == targetBuildDir:
      #Get parent directory
      parentDir = os.path.dirname(path)
      dirVec.append(parentDir)
      print('-----add compile directory:'+parentDir)
      else:
      WalkDir(path, level+1) def DoBuild():
      print('---------Begin DoBuild---------')
      numProcessor = GetProcessorCount()
      UpdateCMD = 'android update project -p . -s -t %s' % (targetVersion)
      print('UpdateCMD: '+UpdateCMD)
      isDebug = ( Configuration == 'debug' )
      NDKBuildCMD = 'ndk-build V=%d -j%d NDK_DEBUG=%d' % (VerbosBuildInfo, numProcessor, isDebug)
      print('NDKBuildCMD: '+NDKBuildCMD)
      AntCMD = 'ant %s install' % (Configuration)
      print('AntCMD: '+AntCMD)
      projectCount = 0
      if 1:
      for dir in dirVec:
      androidDir = dir
      print('---------Begin Update---------')
      print('Current directory:'+androidDir)
      projectCount += 1
      if 1:
      os.chdir(androidDir)
      os.system(UpdateCMD)
      #Rely on make file to decide whether cd into jni directory
      #os.chdir('jni')
      print('==========Begin compile')
      os.system(NDKBuildCMD)
      #os.chdir('../')
      print('==========building APK')
      os.system(AntCMD)
      print('==========work done on:'+androidDir)
      #os.chdir(curRootDir)
      #print('---------go back directory---------')
      projectCount += 1
      print('---------Congratulation,%d projects compiled,and deployed on device---------' %(projectCount)) #MAIN
      WalkDir(curRootDir)
      DoBuild()

随手写的自动批量编译部署NativeAndroid程序Python脚本的更多相关文章

  1. Saltstack批量编译部署nginx(多模块)

    最近一直在研究saltstack的同步文件和批量执行命令,随着架构的变大,批量部署的需求也变得明显起来了,我需要用一条命令就部署好nginx和tomcat,并且符合我所有的环境需求,可以直接投入生产环 ...

  2. 随手写的一个检测php连接mysql的小脚本

    最近偶然接触到一点点的php开发,要用到mysql数据库,由于mysql和php版本的关系,php5里面连接函数有mysql_connect(),mysqli_connect()两种,php7中又使用 ...

  3. ansible批量分发免密钥登陆python脚本

    最近看了看强大的号称自动化运维的三大利器之一的--ansible,ok,亲测之后,确实感觉,对于我们这种DBA工作者来说,确实很受益. 值得注意的是ansible要求被管理服务器python版本不低于 ...

  4. [python] 1、python鼠标点击、移动事件应用——写一个自动下载百度音乐的程序

    1.问题描述: 最近百度总爱做一些破坏用户信任度的事——文库金币变券.网盘限速,吓得我赶紧想办法把存在百度云音乐中的歌曲下载到本地. http://yinyueyun.baidu.com/ 可问题是云 ...

  5. python 3 - 写一个自动生成密码文件的程序

    1.你输入几,文件里面就给你产生多少条密码 2.密码必须包括,大写字母.小写字母.数字.特殊字符 3.密码不能重复 4.密码都是随机产生的 5.密码长度6-11 import string,rando ...

  6. windows中实现python,redis服务自动重启(任务计划程序+bat脚本)

    需求:银行电脑无法自动开机,只能 通过 应用相关服务每天自动重启的方式实现 服务更新并且防止服务假死,内存过大 等情况 相关工具:win10系统中,使用windows自带的任务计划程序 和 bat脚本 ...

  7. 项目上使用的每月1日自动导出Zabbix性能数据的python脚本

    基于zabbix-manager python2.7 #!/usr/bin/env python # -*- coding: utf-8 -*- # __author__ = "life&q ...

  8. 分享一个批量修改文件编码的python脚本

    分享一个自己编写的递归查找子目录,将所有cpp文件编码修改为utf-8编码格式的小脚本 #i!/usr/bin/env python3 # -*- coding:utf-8 -*- import os ...

  9. 用Ant实现Java项目的自动构建和部署

    原文地址:http://tech.it168.com/j/2007-11-09/200711091344781.shtml         本文请勿转载! Ant是一个Apache基金会下的跨平台的构 ...

随机推荐

  1. jenkins插件 查看job修改历史

    文章来自:http://www.ciandcd.com文中的代码来自可以从github下载: https://github.com/ciandcd 插件jobConfigHistory(https:/ ...

  2. linxu ffmpeg 编译安装

    1.下载ffmpeg. 下载网址:http://www.ffmpeg.org/download.html 2.解压缩 tar -zxvf ffmpeg-2.0.1.tar.gz 3.配置,生成Make ...

  3. js勾选时显示相应内容

    使用环境,一.比如用户勾选时显示一些安全方面提示“你真的要自动登录吗?这将使你下次不需要密码即可进入你的个人中心.”二.显示其他预设选项,以方便用户选择输入,比如密保问题设置,当用户不想使用自定义设置 ...

  4. iOS开发-UIScrollView原理

    UIScrollView在开发中是不可避免,关于UIScrollView都有自己一定的理解.滚动视图有两个需要理解的属性,frame和bounds,frame是定义了视图在窗口的大小和位置,bound ...

  5. 让delphi解析chrome扩展的native应用

    chrome浏览器自从去年以来逐步去掉了对浏览器插件的支持,npapi的方案马上不可用. 当务之急要选择一个替代方案,最常用的就是扩展了.扩展程序提供了一套和本地程序交互的方案——“原生消息通信” 写 ...

  6. android: Android Notification

    Notification即通知,用于在通知栏显示提示信息. 在较新的版本中(API level  > 11),Notification类中的一些方法被Android声明deprecated(弃用 ...

  7. 删除配置文件解决OS X各种WiFi无法连接的顽固问题,解决MAC无法连接wif的情况 Preferences

    删除配置文件解决OS X各种WiFi无法连接的顽固问题 删除配置文件解决OS X各种WiFi无法连接的顽固问题1 记住现在wifi的密码并将wifi关闭2 前往文件夹/Library/Preferen ...

  8. Android——BitMap(位图)相关知识总结贴

    Android中文API(136) —— Bitmap http://www.apkbus.com/android-54644-1-1.html Android 4.0 r1 API—Bitmap(S ...

  9. 流媒体选择Nginx是福还是祸?

    CDN,视频云,已经“僧多粥少” 视频直播的持续升温,无意间也让带宽生意的争夺变得异常残酷.一时间,各种云计算.CDN.视频云提供商都在视频尤其是直播上投入重兵,揭竿而起的新生起义军们也正马不停蹄的赶 ...

  10. 如何判断平台工具集去做条件编译(VC++目录、预处理器定义、$(PlatformToolsetVersion))

    作者:zyl910 从VS2010开始,提供了一个平台工作集(Platform ToolSet)选项用于配制vc编译版本.到了VS2012,更是因为默认平台工具集不支持WindowsXP,导致经常需要 ...