Android 源码编译技巧--模块清理

15 篇文章 1 订阅

参考之前的文章 南国樗里疾-Android 源码编译技巧–模块编译

既然有模块编译,应该也有模块清理。

Android 源码编译之后,如果有代码更新,一般都是 make installclean 之后再 make

支持模块编译的话可以模块编译后在线替换,

不支持模块编译的话需要重新生成 rom 。

make clean-<local_module>

make installclean 会清理 app 生成目录 out/target/product/<product_name>/obj/APPS/
(也会清理其他的一些文件,不展开说明了)

但不会清理中间件生成目录(非官方说法,我自己这样称呼的) out/target/common/obj/APPS/ ,如果不清理这个目录,可能出现编译未生效的情况。

可以手动删除这个目录,也可以使用如下命令清除。

make clean-<local_module>	

这句意思是单独清理某个模块,
<local_module> 是对应目标模块的 Android.mk 文件里的 LOCAL_PACKAGE_NAME 或者 LOCAL_MODULE 。

make clean-SystemUI ,就是删除 SystemUI 模块的编译产物和中间件,其实就是删除以下目录,

out/target/product/<product_name>/system/priv-app/SystemUI/
out/target/product/<product_name>/obj/APPS/SystemUI_intermediates/
out/target/common/obj/APPS/SystemUI_intermediates/

然后再编译就可以了。

总结下,模块编译时,

make clean-<local_module>

make <local_module> -j8

installclean 清理的目录

再探究下 installclean 清理了哪些东西,搜索 installclean 找到 build/soong/ui/build/cleanbuild.go

// installClean deletes all of the installed files -- the intent is to remove
// files that may no longer be installed, either because the user previously
// installed them, or they were previously installed by default but no longer
// are.
//
// This is faster than a full clean, since we're not deleting the
// intermediates.  Instead of recompiling, we can just copy the results.
func installClean(ctx Context, config Config) {
	dataClean(ctx, config)

	if hostCrossOutPath := config.hostCrossOut(); hostCrossOutPath != "" {
		hostCrossOut := func(path string) string {
			return filepath.Join(hostCrossOutPath, path)
		}
		removeGlobs(ctx,
			hostCrossOut("bin"),
			hostCrossOut("coverage"),
			hostCrossOut("lib*"),
			hostCrossOut("nativetest*"))
	}

	hostOutPath := config.HostOut()
	hostOut := func(path string) string {
		return filepath.Join(hostOutPath, path)
	}

	hostCommonOut := func(path string) string {
		return filepath.Join(config.hostOutRoot(), "common", path)
	}

	productOutPath := config.ProductOut()
	productOut := func(path string) string {
		return filepath.Join(productOutPath, path)
	}

	// Host bin, frameworks, and lib* are intentionally omitted, since
	// otherwise we'd have to rebuild any generated files created with
	// those tools.
	removeGlobs(ctx,
		hostOut("apex"),
		hostOut("obj/NOTICE_FILES"),
		hostOut("obj/PACKAGING"),
		hostOut("coverage"),
		hostOut("cts"),
		hostOut("nativetest*"),
		hostOut("sdk"),
		hostOut("sdk_addon"),
		hostOut("testcases"),
		hostOut("vts"),
		hostOut("vts10"),
		hostOut("vts-core"),
		hostCommonOut("obj/PACKAGING"),
		productOut("*.img"),
		productOut("*.zip"),
		productOut("android-info.txt"),
		productOut("misc_info.txt"),
		productOut("apex"),
		productOut("kernel"),
		productOut("kernel-*"),
		productOut("data"),
		productOut("skin"),
		productOut("obj/NOTICE_FILES"),
		productOut("obj/PACKAGING"),
		productOut("ramdisk"),
		productOut("debug_ramdisk"),
		productOut("vendor_ramdisk"),
		productOut("vendor_debug_ramdisk"),
		productOut("test_harness_ramdisk"),
		productOut("recovery"),
		productOut("root"),
		productOut("system"),
		productOut("system_dlkm"),
		productOut("system_other"),
		productOut("vendor"),
		productOut("vendor_dlkm"),
		productOut("product"),
		productOut("system_ext"),
		productOut("oem"),
		productOut("obj/FAKE"),
		productOut("breakpad"),
		productOut("cache"),
		productOut("coverage"),
		productOut("installer"),
		productOut("odm"),
		productOut("odm_dlkm"),
		productOut("sysloader"),
		productOut("testcases"),
		productOut("symbols"))
}

// Remove everything in the data directory.
func dataClean(ctx Context, config Config) {
	removeGlobs(ctx, filepath.Join(config.ProductOut(), "data", "*"))
	ctx.Println("Entire data directory removed.")
}

他主要做了两件事:
1.调用 dataClean ,删除 ProductOut 目录也就是 out/target/product/mpanel/data/ 。

2.通过 removeGlobs 删除如下目录的文件

  • hostOut :out/host/
  • hostCommonOut :out/target/common/< product>
  • productOut :out/target/product/< product >

make installclean 运行 log 如下,不同安卓版本、不同厂商的编译规则、分区打包规则等可能不一样,编译 log 不尽相同,参考看看就好,

out/target/product/<product_name>/data/nativetest
out/target/product/<product_name>/data/nativetest64
out/target/product/<product_name>/apusys.img
out/target/product/<product_name>/cam_vpu1-verified.img
out/target/product/<product_name>/cam_vpu1.img
out/target/product/<product_name>/cam_vpu2-verified.img
out/target/product/<product_name>/cam_vpu2.img
out/target/product/<product_name>/cam_vpu3-verified.img
out/target/product/<product_name>/cam_vpu3.img
out/target/product/<product_name>/dpm-verified.img
out/target/product/<product_name>/dpm.img
out/target/product/<product_name>/mcupm.img
out/target/product/<product_name>/spmfw-verified.img
out/target/product/<product_name>/spmfw.img
out/target/product/<product_name>/sspm.img
out/target/product/<product_name>/tee-verified.img
out/target/product/<product_name>/tee.img
out/target/product/<product_name>/data
out/target/product/<product_name>/obj/PACKAGING
out/target/product/<product_name>/ramdisk
out/target/product/<product_name>/debug_ramdisk
out/target/product/<product_name>/vendor_ramdisk
out/target/product/<product_name>/recovery
out/target/product/<product_name>/root
out/target/product/<product_name>/system
out/target/product/<product_name>/system_dlkm
out/target/product/<product_name>/vendor
out/target/product/<product_name>/vendor_dlkm
out/target/product/<product_name>/obj/FAKE
out/target/product/<product_name>/odm_dlkm
out/target/product/<product_name>/testcases
out/target/product/<product_name>/symbols

添加 installclean 清理目录

前文提到 installclean 命令不会清理 out/target/common/obj/APPS/ 目录。

想要清理这个目录,修改如下,把它加入清理列表即可,

diff --git a/build/soong/ui/build/cleanbuild.go b/build/soong/ui/build/cleanbuild.go
old mode 100644
new mode 100755
index c47f614d64b..dcc226e3b35
--- a/build/soong/ui/build/cleanbuild.go
+++ b/build/soong/ui/build/cleanbuild.go
@@ -34,6 +34,7 @@ func removeGlobs(ctx Context, globs ...string) {
 
                for _, file := range files {
                        err = os.RemoveAll(file)
+                       ctx.Println("[cleanbuild.go] , remove :",file)
                        if err != nil {
                                ctx.Fatalf("Failed to remove file %q: %v", file, err)
                        }
@@ -83,6 +84,11 @@ func installClean(ctx Context, config Config, what int) {
                return filepath.Join(productOutPath, path)
        }
 
+       commonOutPath := config.CommonOut()
+       commonOut := func(path string) string {
+               return filepath.Join(commonOutPath, path)
+       }
+
        // Host bin, frameworks, and lib* are intentionally omitted, since
        // otherwise we'd have to rebuild any generated files created with
        // those tools.
@@ -96,12 +102,14 @@ func installClean(ctx Context, config Config, what int) {
                hostOut("sdk_addon"),
                hostOut("testcases"),
                hostOut("vts"),
+               commonOut("obj/APPS"),
                productOut("*.img"),
                productOut("*.zip"),
                productOut("android-info.txt"),
                productOut("kernel"),
                productOut("data"),
                productOut("skin"),
                productOut("obj/NOTICE_FILES"),
                productOut("obj/PACKAGING"),
                productOut("ramdisk"),
diff --git a/build/soong/ui/build/config.go b/build/soong/ui/build/config.go
old mode 100644
new mode 100755
index 7eb3a7252f2..1b126f03891
--- a/build/soong/ui/build/config.go
+++ b/build/soong/ui/build/config.go
@@ -560,6 +560,10 @@ func (c *configImpl) ProductOut() string {
        return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice())
 }
 
+func (c *configImpl) CommonOut() string {
+       return filepath.Join(c.OutDir(), "target", "common")
+}
+
 func (c *configImpl) DevicePreviousProductConfig() string {
        return filepath.Join(c.ProductOut(), "previous_build_config.mk")
 }
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值