本机库不是从golang条件实现加载到apex_defaults吗? [英] native library is not getting loaded to apex_defaults from golang conditional implementation?

查看:71
本文介绍了本机库不是从golang条件实现加载到apex_defaults吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我写了一个go文件,它将一个库动态地附加到apex_defaults-> multilib-> first-> native_shared_libs;可以检查Android.bp的完整代码

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.

详细说明:

我想将名为"libabcxtractor"的库添加到数组

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)
}

要在构建时启用上述条件,我已更新了Android.bp文件,如下所示:

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: {

执行make命令时,我可以看到它进入了条件语句;日志正在打印.我通过检查路径out/soong/.bootstrap/soong-my_apex/pkg/frameworks/av/apex/build.a验证我的.go文件是否得到编译来进一步调查.在那.但是,不会生成libabcextractor".so"文件.在这方面的任何帮助将是巨大的.

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.

libabcextractor是位于预构建路径中的供应商库.如果我尝试使用属于AOSP代码一部分并且已经存在于现有native_static_libs数组中的任何其他库,则它们也不适用于它们.从这里开始,由于没有适当的文档,我无法进一步调试.

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.

推荐答案

Go中的反射只能访问导出的struct字段,这些字段以大写字母开头.在您的First结构中,native_shared_libs未导出,因此无法使用反射进行访问.

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.

由于构建过程使用反射来访问props结构,因此无法从中找到信息.您可以像这样更改它:

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
        }
    }
}

这篇关于本机库不是从golang条件实现加载到apex_defaults吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆