---
title: "LayoutCast"
author: "notebook"
date: "2015-11-20T17:42:36Z"
tags: []
categories: ["移动开发"]
slug: "layoutcast"
draft: false
lastmod: "2015-11-20T17:44:02Z"
id: 2258177
url: "https://notebook.iteye.com/blog/2258177"
---

LayoutCast ：大神作品，我等楷模。

把代码和资源文件的改动直接同步到手机上，应用不需要重启。省去了编译运行漫长的等待，比较适合真机调试的时候使用，支持5.0以上。  
git：[https://github.com/mmin18/LayoutCast](https://github.com/mmin18/LayoutCast)  
简单理解一下实现原理：  
1.通过as插件调用Python脚本来进行把有改动的代码和资源进行编译和打包，在bulid/lcast下，classes.dex和res.zip。  
2.用adb来实现手机端和pc的通信，把.dex和.zip 发到手机上。  
3.替换.dex和res

一.入口:

![](http://dl2.iteye.com/upload/attachment/0113/2143/ed99a4a6-70b3-36b5-89b3-5120bb9f3be3.png)  
   
二.替换.dex，这里的思想和动态加载差不到，但不明白为什么把改动的dex（并不是app全部的dex）更新就可以做到代码更新，可能是5.0以上art的新特性吧。

![](http://dl2.iteye.com/upload/attachment/0113/2147/62937ca0-700e-326e-a782-eb114663f818.png)  
   
三.替换res，看来可以动态换肤啊

![](http://dl2.iteye.com/upload/attachment/0113/2145/b39a3c12-a03c-3913-b8ae-0bf86a5a1e88.png)