Android studio Android源码开发环境搭建

Android studio Android源码开发环境搭建

1 起因

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

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

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


2 环境搭建

1 安装git工具, 将git 和git自带的bash全部加到windows环境变量中
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-g7MSHOO9-1641187263589)(D:\app\android_frameworks\markdown\image-20220102104147218.png)]

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"
    // 服务器IP
    serverIp = "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', cmd
                standardOutput = out
        }
        println(out.toString())
    }
}

5 提交代码

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

在这里插入图片描述

2 修改代码后,通过git add 添加到git仓库(*add显示为灰色或者git选项不能出来,说明version control配置不对 *)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eiQ0sOV3-1641187263591)(D:\app\android_frameworks\markdown\image-20220102225050812.png)]

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

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tOk0I8sj-1641187263591)(D:\app\android_frameworks\markdown\image-20220102124710547.png)]

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', gitCmd
            standardOutput = 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', cmd
                standardOutput = out
        }
        println(out.toString())
    }
}

6 adb push到设备

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

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OvCffN5y-1641187263592)(D:\app\android_frameworks\markdown\image-20220102225346011.png)]

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', cmd
                standardOutput = 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', cmd
                standardOutput = 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', cmd
                standardOutput = out
        }
        println(out.toString())
    }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: Android Studio是一个非常流行的集成开发环境,用于开发Android应用程序。聊天软件源码是指开发聊天功能的应用程序的代码。 对于编写一个聊天软件,需要用到一些核心的功能和库。首先,需要使用网络通信库来实现用户之间的实时通信。通常使用的是Socket或者WebSocket技术来传输数据。其次,需要实现用户的登录和注册功能,以及好友列表的管理和展示。这可以通过数据库来实现,例如使用SQLite或者Firebase等。另外,还需要实现消息的发送和接收功能,可以使用消息队列或者推送通知技术来实现。最后,还需要考虑到安全性和用户体验,例如添加加密功能、消息展示样式等。 在Android Studio中,可以通过创建一个新的项目来开始编写聊天软件。在项目中需要创建不同的Activity、Fragment等界面来展示聊天界面、好友列表界面、登录界面等。同时,还需要编写逻辑代码来实现相关的功能,例如处理用户输入、发送消息、接收消息等。可以使用Java或者Kotlin语言来进行开发,并利用Android Studio提供的各种工具和插件来提高开发效率。 总结来说,Android Studio提供了一个完善的开发环境,可以帮助开发者编写聊天软件源码。需要关注网络通信、用户管理、消息传输、安全性等方面的功能。通过创建项目、编写界面和逻辑代码来实现聊天软件的功能。 ### 回答2: Android Studio聊天软件源码是指使用Android Studio开发的一款聊天软件的源代码。该源码主要包括了聊天软件的各个功能模块的实现代码,包括用户登录注册、好友管理、聊天界面等。 在源码中,用户登录注册模块主要涉及用户的账号密码验证、用户信息存储等操作,通过与服务器进行交互完成用户的登录和注册。 好友管理模块包括好友列表的显示、添加好友、删除好友、好友资料查询等功能。在源码中通过数据库进行好友信息的存储和管理,并提供了相应的接口和方法供其他模块调用。 聊天界面模块是聊天软件的核心功能模块,其中包括了聊天窗口的布局、发送消息和接收消息的逻辑实现。通过使用Android Studio提供的UI组件和网络通信库,可以实现用户之间的实时聊天。 在聊天软件源码中还包含了一些辅助模块,例如消息列表的显示、消息的存储与加载、消息的加密等。 使用Android Studio聊天软件源码可以帮助开发者了解聊天软件的架构和实现原理,快速搭建起自己的聊天应用。开发者可以根据自己的需求来定制和扩展功能,添加更多的个性化设计和特色功能,以满足用户的需求。同时,也可以从源码中学习到编写优雅、高效的Android应用程序的开发技巧和经验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值