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

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

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

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

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

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

make clean-

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

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

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

make clean-	

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

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

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

然后再编译就可以了。

总结下,模块编译时,

make clean-

make -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//data/nativetest
out/target/product//data/nativetest64
out/target/product//apusys.img
out/target/product//cam_vpu1-verified.img
out/target/product//cam_vpu1.img
out/target/product//cam_vpu2-verified.img
out/target/product//cam_vpu2.img
out/target/product//cam_vpu3-verified.img
out/target/product//cam_vpu3.img
out/target/product//dpm-verified.img
out/target/product//dpm.img
out/target/product//mcupm.img
out/target/product//spmfw-verified.img
out/target/product//spmfw.img
out/target/product//sspm.img
out/target/product//tee-verified.img
out/target/product//tee.img
out/target/product//data
out/target/product//obj/PACKAGING
out/target/product//ramdisk
out/target/product//debug_ramdisk
out/target/product//vendor_ramdisk
out/target/product//recovery
out/target/product//root
out/target/product//system
out/target/product//system_dlkm
out/target/product//vendor
out/target/product//vendor_dlkm
out/target/product//obj/FAKE
out/target/product//odm_dlkm
out/target/product//testcases
out/target/product//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")
 }

你可能感兴趣的:(Android,编译,android)