Android studio Android源码开发环境搭建

1 起因

android studio工具对java代码自动提示和搜索等功能,把服务的代码全部导入整个工程,在加载的过程特别耗时,只需要我们自己开发的一部分代码,通过grade脚本用scp命令在windows和linux之间复制文件,将android studio中的修改同步到服务器

如果需要将整个代码导入到Android studio中,可以参考下面这篇博客:

AndroidStudio源码开发环境搭建 - Gityuan博客 | 袁辉辉的技术博客

2 环境搭建

1 安装git工具, 将git 和git自带的bash全部加到windows环境变量中

2 scp免密在windows和Linux服务器之间复制文件

  • ssh-copy-id命令把本地的ssh公钥文件添加到远程主机对应的账户下
cd ~/.ssh/// remote_username = 远程Linux服务器用户名
// remote_ip = 远程linux服务器IP地址
ssh-copy-id -i ~/.ssh/id_rsa.pub remote_username@remote_ip
  • 用scp命令测试看看是否配置OK
// remote_username = 远程Linux服务器用户名
// remote_ip = 远程linux服务器IP地址
scp local_file remote_username@remote_ip:remote_file
scp remote_username@remote_ip:remote_file .

3 项目配置

1 将android studio工程克隆或者下载到本地

https://github.com/980725866/android_frameworks

2 Android Studio 配置

// project config start
ext {// 服务器用户名userName = "ubuntu"// 服务器IPserverIp = "1.1.1.1"// 服务器项目代码根目录路径projectPath = "/home/ubuntu/Android/"// 对应的board名tartgetBoard = "t982_ar301"SCP_PROJECT_PATH = "scp -p ${rootProject.ext.userName}@${rootProject.ext.serverIp}:${rootProject.ext.projectPath}/"PROJECT_PATH = "${rootProject.ext.userName}@${rootProject.ext.serverIp}:${rootProject.ext.projectPath}/"
}
// project config end

4 拉取代码

FRAMEWORK_CODE

拉取服务器代码的路径定义在FRAMEWORK_CODE中,如果需要添加其它路径的代码,在FRAMEWORK_CODE 列表中修改既可。

def FRAMEWORK_CODE = ["frameworks/base/core/","frameworks/base/services/"
]

点击运行pullFrameworkCode task,拉取服务器代码

pullFrameworkCode

pullFrameworkCode脚本根据FRAMEWORK_CODE中指定的路径从服务器copy到本地对应的路径下

task pullFrameworkCode() {doLast {println("pullFrameworkCode")def out = new ByteArrayOutputStream()def cmd = ""for (filePath in FRAMEWORK_CODE) {def scpCmd = "scp -rp " + PROJECT_PATH + filePath + "* " + filePath + ";"def directoryPath = filePath.substring(0, filePath.lastIndexOf("/"))def windowsDirectoryPath = directoryPath.replace("/", "\\")def file = new File(rootProject.rootDir, windowsDirectoryPath)if (!file.exists()) {cmd += "mkdir -p " + directoryPath + ";"}cmd += scpCmd}cmd += "cd frameworks;git init;"exec {ExecSpec execSpec ->executable 'bash'args '-c', cmdstandardOutput = out}println(out.toString())}
}

5 提交代码

1 拉取代码的脚步会创建git创库,用来add修改的差异文件,查看vesrsion control 确保创库配置对了。出错会显示红色

2 修改代码后,通过git add 添加到git仓库(*add显示为灰色或者git选项不能出来,说明version control配置不对 *)

3 点击 pushFrameworkCode 将git add的修改复制到服务器

pushFrameworkCode

通过git创库,获取已经add到创库的文件, 再用scp命令将add到创库的文件复制到服务器

task pushFrameworkCode() {doLast {println("pushFrameworkCode")def dir = "frameworks/";def out = new ByteArrayOutputStream()// 通过git创库,获取已经add的文件同步到服务器, 只用scp修改的代码def gitCmd = "git status -suno ."exec {workingDir '.\\frameworks'commandLine 'cmd', '/c', gitCmdstandardOutput = out}if (out == null || out.equals("")) {return}def cmd = ""def filePaths = out.toString().split("\n")for (tmpFilePath in filePaths) {def filePath = tmpFilePath.substring(tmpFilePath.indexOf(' ') + 1).trim()if (filePath == null || !filePath.endsWith(".java")) {continue}def scpString = "scp -p ${dir}" + filePath + " " + PROJECT_PATH + "${dir}" + filePath + ";"println("pushFrameworkCode " + scpString)cmd += scpString}if (cmd.length() < 10) {return}exec {ExecSpec execSpec ->executable 'bash'args '-c', cmdstandardOutput = out}println(out.toString())}
}

6 adb push到设备

服务器编译好后,通过pushFrameworkJar先从服务器下载jar等文件到本地,然后会自动通过adb push命令推送到对应的开发版上,重启

FRAMEWORK_JARS

FRAMEWORK_JARS中定义需要push的文件路径

def FRAMEWORK_JARS = ["out/target/product/${rootProject.ext.tartgetBoard}/system/framework/framework.jar","out/target/product/${rootProject.ext.tartgetBoard}/system/framework/arm/boot-framework.art","out/target/product/${rootProject.ext.tartgetBoard}/system/framework/arm/boot-framework.oat","out/target/product/${rootProject.ext.tartgetBoard}/system/framework/arm/boot-framework.vdex",
//    "out/target/product/${rootProject.ext.tartgetBoard}/system/framework/arm64/boot-framework.art",
//    "out/target/product/${rootProject.ext.tartgetBoard}/system/framework/arm64/boot-framework.oat",
//    "out/target/product/${rootProject.ext.tartgetBoard}/system/framework/arm64/boot-framework.vdex",
]

pullFrameworkJar

pullFrameworkJar将FRAMEWORK_JARS中定义的文件复制到本地;再通过pushFrameworkJar中的脚本用adb push到开发版或者手机上

task pullFrameworkJar() {doLast {println("pullFrameworkJar")def out = new ByteArrayOutputStream()def cmd = ""for (filePath in FRAMEWORK_JARS) {def scpCmd = SCP_PROJECT_PATH + filePath + " " + filePath + ";"def directoryPath = filePath.substring(0, filePath.lastIndexOf("/"))def windowsDirectoryPath = directoryPath.replace("/", "\\")def file = new File(rootProject.rootDir, windowsDirectoryPath)if (!file.exists()) {cmd += "mkdir -p " + directoryPath + ";"}println(file.getPath())cmd += scpCmd}println(cmd)exec {ExecSpec execSpec ->executable 'bash'args '-c', cmdstandardOutput = out}println(out.toString())}
}

pushFrameworkJar

pushFrameworkJar依赖pullFrameworkJar任务

task pushFrameworkJar() {dependsOn(pullFrameworkJar)doLast {println("pushFrameworkJar")def tartgetBoard = "${rootProject.ext.tartgetBoard}"def out = new ByteArrayOutputStream()def cmd = "adb root;adb remount;"for (filePath in FRAMEWORK_JARS) {def windowsFilePath = filePath.replace("/", "\\")def devicePath = filePath.substring(filePath.indexOf(tartgetBoard) + tartgetBoard.length() + 1)println(windowsFilePath + " " + devicePath)cmd += "adb push ${windowsFilePath} ${devicePath};"}cmd += "adb reboot"println(cmd)exec {ExecSpec execSpec ->executable 'bash'args '-c', cmdstandardOutput = out}}
}

7 删除

如果开发完了这个项目,服务器上拉取下来的代码不再需要,需要下载其它的代码,可以执行cleanFramework task删除本地code和 git仓库

task cleanFramework() {doLast {println("cleanFramework")def cmd = "rm out -rf;rm frameworks/* -rf;rm frameworks/.git -rf"exec {ExecSpec execSpec ->executable 'bash'args '-c', cmdstandardOutput = out}println(out.toString())}
}

Android studio Android源码开发环境搭建相关推荐

  1. Android之ubuntu源码开发环境搭建笔记

    为什么80%的码农都做不了架构师?>>>    昨天,把电脑主机全换了,因此之前的工作环境得重新搭建,我是既开心又纠结,开心的是可以用高配置的电脑,纠结的是搭环境比较麻烦,稍有不慎, ...

  2. 【Android】MTK Android 源码开发环境搭建

    硬件环境: VMware 虚拟机环境:VMware 虚拟机版本 VMware-workstation-9.0.0-812388 内存:2.1G 处理器:双核双线程 硬盘:60G 系统环境:Ubuntu ...

  3. 开源arduino可视化编辑器Ardublockly源码开发环境搭建

    linux环境下开源arduino可视化编辑器Ardublockly二次开发搭建 1 安装 1.1 系统环境搭建 在Ubuntu上安装Python 2的Tkinter: sudo apt-get in ...

  4. 从零开始搭建Ubuntu 环境下的Android 源码开发环境

    本文从一个干净的Ubuntu 10.04 操作系统出发,一步一步引导你搭建自己的基于eclipse IDE 的Android源码开发环境. 正文会包含一下这些内容: 获得源码 编译源码准备工作 编译工 ...

  5. Android源码编译环境搭建教程 (一) - Ubuntu系统构建

    Android源码编译环境搭建教程 (一) - Ubuntu系统构建 本教程为感兴趣的同学提供Android源码编译的环境搭建,当然这里都是基于windows系统,mac系统也差不多,将相应的软件替换 ...

  6. Android视频直播源码开发直播平台、点播播放器哪家强?

    Android视频直播源码开发直播平台.点播播放器哪家强? 最近在项目中要加入视频直播和点播功能,那么问题来了,我需要一个播放器来播放视频流,那该如何选择呢?除了原生的VideoView(VideoV ...

  7. Ubuntu12.10-amd64系统上搭建Android4.2(JellyBean)源码开发环境

    注意:1) 从android4.1开始,编译Android源码必须使用ubuntu 64位系统,所以请预装Ubuntu64位操作系统! 建议去ubuntu官网下载 ubuntu-desktop-### ...

  8. Gitolite + repo 搭建安卓源码开发环境

    Gitolite + repo 搭建安卓源码开发环境 转载请注明出处:http://blog.csdn.net/u011479494/article/details/50629669 相比gitosi ...

  9. Android笔记 - android studio导入源码

    前提 安装好android studio 拉好代码并并编译OK 编译源码idegen模块及生成AS配置文件(*.ipr) 在开始编译idegen模块前,需要先全局编译出out目录及相关文件吧,我们通过 ...

  10. android studio查看源码

    android studio 查看源码,搜索类,切换到 All,勾选 include non-project items 选项,输入类名就可以打开了.

最新文章

  1. [置顶] mkdir函数-linux
  2. Cli4.5.x 中使用axios请求数据
  3. 程序员面试金典——2.4链表分割
  4. 力扣-剑指Offer-57 和为s的连续正数序列
  5. 《工业设计史》第七章:艺术变革与现代设计
  6. 雅虎助手是如何自杀式攻击360安全卫士的?雅虎助手,3721是什么恶心人的--(部份转贴)...
  7. 百鸡问题的四种(层)解法
  8. 金蝶k3wise 核算项目、辅助资料
  9. mysql 3306_允许远程链接mysql,开放3306端口
  10. MATLAB注意事项
  11. Android GPRS上网过程中数据图标的变化过程
  12. 怎样将语音转换成文字
  13. 【07月16日】A股滚动市净率PB历史新低排名
  14. Java并发编程 - 共享模型之管程
  15. 解决电脑桌面图标显示为空白图片
  16. 计算机配件及其参数,型号后缀看不懂 电脑核心硬件参数解读
  17. 在win10上安装Anaconda并运行python程序
  18. BJOI2018简要题解
  19. 前后端分离学习笔记(5) ---[表单的增删改操作;以及为管理员上传头像]
  20. iOS系统中应用程序间通信的方法及装置

热门文章

  1. MAALA3.9_初等矩阵和等价 (Elementary Matrices and Equivalence)
  2. java中stringBuilder的用法(转)
  3. 2021西湖论剑misc——Yusa的小秘密
  4. Linux网页版操作
  5. [转]Cookie详解
  6. Tomcat修行之路-7.Tomcat-Mapper组件机制以及请求处理机制
  7. 如何使用KALI攻击“恶意网站“实验
  8. c语言中row是什么意思中文,row是什么意思
  9. 交叉电缆与以太网电缆有哪些区别之处,弱电工程师必知!
  10. chrome浏览器打开网页排版错乱