Fix apex to follow deps of modules with stubs.

In case that an apex module depends on a module with stubs directly
*and* indirectly, the build system should follow the deps graph further.

Note that WalkDeps() visits deps in DFS and it won't visit again visited
modules.

Bug: n/a
Test: m (apex_test.go amended)
Change-Id: I1a6f135dbda6d1eb641575a3fbbc9bbee0622076
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 4f0ab3a..aa70b50 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -92,6 +92,7 @@
 }
 
 func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
+	android.ClearApexDependency()
 	config := android.TestArchConfig(buildDir, nil)
 	config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
 	config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
@@ -683,6 +684,12 @@
 
 	// Ensure that genstub is invoked with --apex
 	ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3_myapex").Rule("genStubSrc").Args["flags"])
+
+	ensureExactContents(t, ctx, "myapex", []string{
+		"lib64/mylib.so",
+		"lib64/mylib3.so",
+		"lib64/mylib4.so",
+	})
 }
 
 func TestApexWithExplicitStubsDependency(t *testing.T) {