native library is not getting loaded to apex_defaults from golang conditional implementation?

别说谁变了你拦得住时间么 提交于 2020-04-06 02:56:08

问题


So I wrote a go file which will dynamically append one library to apex_defaults-> multilib -> first -> native_shared_libs; full code of Android.bp can be checked here. However I can not see the compiled .so file in my out directory like other lib .so files generated.

Long Explanation:

I want to add a library named "libabcxtractor" to the array native_shared_libs; for that matter I wrote a .go file(as recommended by Google) with some condition which looks like this:

package my_apex

import (
    "android/soong/android"
    "android/soong/apex"
    "fmt"
    "strings"
)



func globalFlags(ctx android.BaseContext) []string {
        var native_shared_libs []string
        if(strings.Contains(ctx.AConfig().DeviceName(), "my_apex_device")){
                fmt.Println("Some log to verify condition is getting executed......")
                native_shared_libs = append(native_shared_libs, "libabcextractor")
        }

        return native_shared_libs
}

func myApexFlagsDefaults(ctx android.LoadHookContext) {
    type props struct {
                Multilib struct {
                        First struct {
                                native_shared_libs  []string
                        }
                }
        }
        p := &props{}
        p.Multilib.First.native_shared_libs = globalFlags(ctx)
        ctx.AppendProperties(p)
}

func myApexFlagsDefaultsFactory() android.Module {
        module := apex.DefaultsFactory()
        android.AddLoadHook(module, myApexFlagsDefaults)
        return module
}

func init() {
        fmt.Println("Registering module type....")
        android.RegisterModuleType("my_apex_defaults", myApexFlagsDefaultsFactory)
}

To enable above go condition to get picked at build time, I have updated my Android.bp file as below:

bootstrap_go_package {
   name: "soong-my_apex",
   pkgPath: "frameworks/av/apex/build",
   deps: [ "soong-apex" ],
   srcs: [ "my_apex.go", ],
   pluginFor: ["soong_build"],
}

my_apex_defaults {
   name: "my_apex",
}

apex_defaults {
    name: "com.android.media-defaults",
    java_libs: ["updatable-media"],
    defaults: ["my_apex",] //THIS IS TO INCLUDE GO IMPLEMENTATION 
    multilib: {

When executing make command I can see it enters the conditional statement; the logs are getting printed. I further investigated by verifying whether my .go file gets compiled by checking the path out/soong/.bootstrap/soong-my_apex/pkg/frameworks/av/apex/build.a. It's there. However ".so" file for libabcextractor is not being generated. Any help on this would be great.

Edit: libabcextractor is a vendor library which resides in Prebuilts path. If I try with any other library which is part of AOSP code and is in the existing native_static_libs array already, it is not working for them as well. From here on I am unable to debug further because of unavailability of proper documentations.


回答1:


Reflection in Go can only access exported struct fields, which are the ones that start with an uppercase letter. In your First struct, native_shared_libs is unexported and cannot be accessed using reflection.

Since the build process uses reflection to access the props struct, it cannot find information from it. You can change it like this:

type props struct {
    Multilib struct {
        First struct {
           Native_shared_libs  []string
        }
    }
}


来源:https://stackoverflow.com/questions/59467685/native-library-is-not-getting-loaded-to-apex-defaults-from-golang-conditional-im

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!