安装Module-Build-0.36_11报错:license_creation..disabled requires:!Software::License is not

本文详细记录了Module-Build模块在Linux环境下的安装过程,包括解压、配置、测试及安装步骤,并解决了测试中出现的编译检测不通过的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装

[root@localhost svnsoft]# tar xvf Module-Build-0.36_11.tar.gz

[root@localhost svnsoft]# cd Module-Build-0.36_11

[root@localhost Module-Build-0.36_11]# perl Build.PL 



Checking optional features...
license_creation........disabled
  requires:
    ! Software::License is not installed


ERRORS/WARNINGS FOUND IN PREREQUISITES.  You may wish to install the versions
of the modules indicated above before proceeding with this installation


Creating new 'MYMETA.yml' with configuration results

Creating new 'Build' script for 'Module-Build' version '0.36_11'


执行步骤如下:

[root@localhost Module-Build-0.36_11]# perl Build --makefile_env_macros 1 test
t/00-compile.t ................. ok     
t/PL_files.t ................... ok   
t/actions/installdeps.t ........ ok   
t/actions/manifest_skip.t ...... ok   
t/add_property.t ............... ok     
t/basic.t ...................... ok     
t/bundle_inc.t ................. skipped: $ENV{MB_TEST_EXPERIMENTAL} is not set
t/compat.t ..................... ok     
t/compat/exit.t ................ ok   
t/debug.t ...................... ok   
t/destinations.t ............... ok       
t/ext.t ........................ ok       
t/extend.t ..................... ok     
t/files.t ...................... ok   
t/help.t ....................... ok     
t/install.t .................... ok     
t/install_extra_target.t ....... ok   
t/manifypods.t ................. ok     
t/metadata.t ................... ok     
t/metadata2.t .................. ok     
t/moduleinfo.t ................. ok     
t/mymeta.t ..................... ok     
t/new_from_context.t ........... ok   
t/notes.t ...................... ok     
t/par.t ........................ ok   
t/parents.t .................... ok     
t/perl_mb_opt.t ................ ok   
t/pod_parser.t ................. ok   
t/ppm.t ........................ ok    
t/properties/module_name.t ..... ok   
t/properties/needs_compiler.t .. ok     
t/properties/share_dir.t ....... ok     
t/resume.t ..................... ok   
t/runthrough.t ................. ok     
t/sample.t ..................... ok   
t/script_dist.t ................ ok   
t/signature.t .................. skipped: $ENV{TEST_SIGNATURE} is not set
t/test_file_exts.t ............. ok   
t/test_type.t .................. ok   
t/test_types.t ................. ok     
t/tilde.t ...................... ok     
t/use_tap_harness.t ............ ok   
t/versions.t ................... ok   
t/write_default_maniskip.t ..... ok   
t/xs.t ......................... ok    
All tests successful.
Files=45, Tests=1171, 79 wallclock secs ( 0.43 usr  0.13 sys + 54.02 cusr 11.87 csys = 66.45 CPU)
Result: PASS

结果是PASS,表示没有问题,我们之前产生的错误可能就是少执行了这一步。

然后:

[root@localhost Module-Build-0.36_11]# ./Build test
t/00-compile.t ................. ok     
t/PL_files.t ................... ok   
t/actions/installdeps.t ........ ok   
t/actions/manifest_skip.t ...... ok   
t/add_property.t ............... ok     
t/basic.t ...................... ok     
t/bundle_inc.t ................. skipped: $ENV{MB_TEST_EXPERIMENTAL} is not set
t/compat.t ..................... ok     
t/compat/exit.t ................ ok   
t/debug.t ...................... ok   
t/destinations.t ............... ok       
t/ext.t ........................ ok       
t/extend.t ..................... ok     
t/files.t ...................... ok   
t/help.t ....................... ok     
t/install.t .................... ok     
t/install_extra_target.t ....... ok   
t/manifypods.t ................. ok     
t/metadata.t ................... ok     
t/metadata2.t .................. ok     
t/moduleinfo.t ................. ok     
t/mymeta.t ..................... ok     
t/new_from_context.t ........... ok   
t/notes.t ...................... ok     
t/par.t ........................ ok   
t/parents.t .................... ok     
t/perl_mb_opt.t ................ ok   
t/pod_parser.t ................. ok   
t/ppm.t ........................ ok    
t/properties/module_name.t ..... ok   
t/properties/needs_compiler.t .. ok     
t/properties/share_dir.t ....... ok     
t/resume.t ..................... ok   
t/runthrough.t ................. ok     
t/sample.t ..................... ok   
t/script_dist.t ................ ok   
t/signature.t .................. skipped: $ENV{TEST_SIGNATURE} is not set
t/test_file_exts.t ............. ok   
t/test_type.t .................. ok   
t/test_types.t ................. ok     
t/tilde.t ...................... ok     
t/use_tap_harness.t ............ ok   
t/versions.t ................... ok   
t/write_default_maniskip.t ..... ok   
t/xs.t ......................... ok    
All tests successful.
Files=45, Tests=1171, 67 wallclock secs ( 0.44 usr  0.14 sys + 54.03 cusr 11.69 csys = 66.30 CPU)
Result: PASS

接着执行安装:

[root@localhost Module-Build-0.36_11]# ./Build install
Building Module-Build
Installing /usr/share/man/man1/config_data.1
Installing /usr/share/perl5/Module/Build.pm
Installing /usr/share/perl5/Module/Build/Cookbook.pm
Installing /usr/share/perl5/Module/Build/YAML.pm
Installing /usr/share/perl5/Module/Build/ModuleInfo.pm
Installing /usr/share/perl5/Module/Build/Compat.pm
Installing /usr/share/perl5/Module/Build/PPMMaker.pm
Installing /usr/share/perl5/Module/Build/ConfigData.pm
Installing /usr/share/perl5/Module/Build/Config.pm
Installing /usr/share/perl5/Module/Build/Dumper.pm
Installing /usr/share/perl5/Module/Build/Base.pm
Installing /usr/share/perl5/Module/Build/PodParser.pm
Installing /usr/share/perl5/Module/Build/Notes.pm
Installing /usr/share/perl5/Module/Build/API.pod
Installing /usr/share/perl5/Module/Build/Version.pm
Installing /usr/share/perl5/Module/Build/Bundling.pod
Installing /usr/share/perl5/Module/Build/Platform/aix.pm
Installing /usr/share/perl5/Module/Build/Platform/cygwin.pm
Installing /usr/share/perl5/Module/Build/Platform/os2.pm
Installing /usr/share/perl5/Module/Build/Platform/darwin.pm
Installing /usr/share/perl5/Module/Build/Platform/Windows.pm
Installing /usr/share/perl5/Module/Build/Platform/VOS.pm
Installing /usr/share/perl5/Module/Build/Platform/Amiga.pm
Installing /usr/share/perl5/Module/Build/Platform/MacOS.pm
Installing /usr/share/perl5/Module/Build/Platform/VMS.pm
Installing /usr/share/perl5/Module/Build/Platform/Default.pm
Installing /usr/share/perl5/Module/Build/Platform/MPEiX.pm
Installing /usr/share/perl5/Module/Build/Platform/RiscOS.pm
Installing /usr/share/perl5/Module/Build/Platform/EBCDIC.pm
Installing /usr/share/perl5/Module/Build/Platform/Unix.pm
Installing /usr/share/perl5/inc/latest.pm
Installing /usr/share/perl5/inc/latest/private.pm
Installing /usr/share/man/man3/Module::Build::Platform::RiscOS.3pm
Installing /usr/share/man/man3/Module::Build::ModuleInfo.3pm
Installing /usr/share/man/man3/Module::Build::Compat.3pm
Installing /usr/share/man/man3/Module::Build::Platform::VOS.3pm
Installing /usr/share/man/man3/Module::Build::Platform::os2.3pm
Installing /usr/share/man/man3/Module::Build::Notes.3pm
Installing /usr/share/man/man3/Module::Build::Platform::cygwin.3pm
Installing /usr/share/man/man3/Module::Build::ConfigData.3pm
Installing /usr/share/man/man3/Module::Build::Platform::Amiga.3pm
Installing /usr/share/man/man3/Module::Build::PPMMaker.3pm
Installing /usr/share/man/man3/Module::Build::Platform::EBCDIC.3pm
Installing /usr/share/man/man3/Module::Build::Platform::Unix.3pm
Installing /usr/share/man/man3/Module::Build::Platform::Windows.3pm
Installing /usr/share/man/man3/Module::Build::API.3pm
Installing /usr/share/man/man3/Module::Build::Platform::Default.3pm
Installing /usr/share/man/man3/Module::Build::Platform::VMS.3pm
Installing /usr/share/man/man3/Module::Build::Platform::MPEiX.3pm
Installing /usr/share/man/man3/Module::Build::Platform::darwin.3pm
Installing /usr/share/man/man3/Module::Build::Authoring.3pm
Installing /usr/share/man/man3/Module::Build::Base.3pm
Installing /usr/share/man/man3/Module::Build::Platform::aix.3pm
Installing /usr/share/man/man3/Module::Build::Platform::MacOS.3pm
Installing /usr/share/man/man3/Module::Build::Bundling.3pm
Installing /usr/share/man/man3/Module::Build.3pm
Installing /usr/share/man/man3/inc::latest.3pm
Installing /usr/share/man/man3/Module::Build::Cookbook.3pm
Installing /usr/bin/config_data

这样就安装成功了,但是我在查找相关文献时,发现了这样一个编译检测不通过的的案例,可以参考一下,我并没有遇到这个问题:


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
华丽分割线
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

First, about me:

==> perl -v <==
This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi

Copyright 1987-2009, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

==> cat /etc/lsb-release <==
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04.1 LTS"

==> getent passwd foo <==
foo:x:1025:1025:Foo Bar:/u/foo:/bin/zsh

==> getent passwd zooble || echo $? <==
2




Now... while using local::lib and trying to install Module::Build, the
t/tilde.t test fails, as seen below:

Running [/usr/bin/perl /usr/bin/cpanp-run-perl
/u/username/.cpanplus/5.10.1/build/Module-Build-0.3607/Makefile.PL
INSTALLDIRS=site]...
# running Build.PL --installdirs site

Checking optional features...
license_creation........disabled
  requires:
    ! Software::License is not installed

ERRORS/WARNINGS FOUND IN PREREQUISITES.  You may wish to install the versions
of the modules indicated above before proceeding with this installation

Creating new 'MYMETA.yml' with configuration results
Creating new 'Build' script for 'Module-Build' version '0.3607'
Running [/usr/bin/make test]...
make[1]: Entering directory
`/u/username/.cpanplus/5.10.1/build/Module-Build-0.3607'
/usr/bin/perl Build --makefile_env_macros 1 test
t/00-compile.t ................. ok
t/PL_files.t ................... ok
t/actions/installdeps.t ........ ok
t/add_property.t ............... ok
t/basic.t ...................... ok
t/bundle_inc.t ................. skipped: $ENV{MB_TEST_EXPERIMENTAL} is
not set
t/compat.t ..................... ok
t/compat/exit.t ................ ok
t/debug.t ...................... ok
t/destinations.t ............... ok
t/ext.t ........................ ok
t/extend.t ..................... ok
t/files.t ...................... ok
t/help.t ....................... ok
t/install.t .................... ok
t/install_extra_target.t ....... ok
t/manifypods.t ................. ok
t/metadata.t ................... ok
t/metadata2.t .................. ok
t/moduleinfo.t ................. ok
t/mymeta.t ..................... ok
t/new_from_context.t ........... ok
t/notes.t ...................... ok
t/par.t ........................ ok
t/parents.t .................... ok
t/perl_mb_opt.t ................ ok
t/pod_parser.t ................. ok
t/ppm.t ........................ ok
t/properties/module_name.t ..... ok
t/properties/needs_compiler.t .. ok
t/properties/share_dir.t ....... ok
t/resume.t ..................... ok
t/runthrough.t ................. ok
t/sample.t ..................... ok
t/script_dist.t ................ ok
t/signature.t .................. skipped: $ENV{TEST_SIGNATURE} is not set
t/test_file_exts.t ............. ok
t/test_type.t .................. ok
t/test_types.t ................. ok

#   Failed test at t/tilde.t line 92.
#          got: '/u/foo'
#     expected: '~ foo'
# Looks like you failed 1 test of 16.
t/tilde.t ......................
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/16 subtests
t/use_tap_harness.t ............ ok
t/versions.t ................... ok
t/write_default_maniskip.t ..... ok
t/xs.t ......................... ok

Test Summary Report
-------------------
t/tilde.t                    (Wstat: 256 Tests: 16 Failed: 1)
  Failed test:  15
  Non-zero exit status: 1
Files=44, Tests=1164, 63 wallclock secs ( 0.36 usr  0.06 sys + 44.79 cusr
12.66 csys = 57.87 CPU)
Result: FAIL
Failed 1/44 test programs. 1/1164 subtests failed.
make[1]: Leaving directory
`/u/username/.cpanplus/5.10.1/build/Module-Build-0.3607'
make[1]: *** [test] Error 255
[ERROR] MAKE TEST failed: Bad file descriptor make[1]: Entering directory
`/u/username/.cpanplus/5.10.1/build/Module-Build-0.3607'




I tweaked t/tilde.t a little bit, to replace 'foo' with a non-existant user:

==> diff -u tilde.t.orig tilde.t <==
--- tilde.t.orig        2010-09-30 02:53:28.630397909 -0000
+++ tilde.t     2010-09-30 02:53:42.660469441 -0000
@@ -89,7 +89,7 @@

     skip "On OS/2 EMX all users are equal", 2 if $^O eq 'os2';
     is( run_sample( $p => '~~'    )->$p(),  '~~' );
-    is( run_sample( $p => '~ foo' )->$p(),  '~ foo' );
+    is( run_sample( $p => '~ zooble' )->$p(),  '~ zooble' );
 }

 # Again, with named users




And now Module::Build installs just fine:

Restored the state of none (in 0.0031 secs)
Running install for module 'Module::Build'
Running Build for D/DA/DAGOLDEN/Module-Build-0.3607.tar.gz
  Has already been unwrapped into directory
/u/username/path/to/cpan-cache/build/Module-Build-0.3607-K86OwJ
  Has already been made
Running Build test
t/00-compile.t ................. ok
t/PL_files.t ................... ok
t/actions/installdeps.t ........ ok
t/add_property.t ............... ok
t/basic.t ...................... ok
t/bundle_inc.t ................. skipped: $ENV{MB_TEST_EXPERIMENTAL} is
not set
t/compat.t ..................... ok
t/compat/exit.t ................ ok
t/debug.t ...................... ok
t/destinations.t ............... ok
t/ext.t ........................ ok
t/extend.t ..................... ok
t/files.t ...................... ok
t/help.t ....................... ok
t/install.t .................... ok
t/install_extra_target.t ....... ok
t/manifypods.t ................. ok
t/metadata.t ................... ok
t/metadata2.t .................. ok
t/moduleinfo.t ................. ok
t/mymeta.t ..................... ok
t/new_from_context.t ........... ok
t/notes.t ...................... ok
t/par.t ........................ ok
t/parents.t .................... ok
t/perl_mb_opt.t ................ ok
t/pod_parser.t ................. ok
t/ppm.t ........................ ok
t/properties/module_name.t ..... ok
t/properties/needs_compiler.t .. ok
t/properties/share_dir.t ....... ok
t/resume.t ..................... ok
t/runthrough.t ................. ok
t/sample.t ..................... ok
t/script_dist.t ................ ok
t/signature.t .................. skipped: $ENV{TEST_SIGNATURE} is not set
t/test_file_exts.t ............. ok
t/test_type.t .................. ok
t/test_types.t ................. ok
t/tilde.t ...................... ok
t/use_tap_harness.t ............ ok
t/versions.t ................... ok
t/write_default_maniskip.t ..... ok
t/xs.t ......................... ok
All tests successful.
Files=44, Tests=1164, 63 wallclock secs ( 0.42 usr  0.13 sys + 46.39 cusr
11.93 csys = 58.87 CPU)
Result: PASS
  DAGOLDEN/Module-Build-0.3607.tar.gz
  ./Build test -- OK
Running Build install
Prepending
/u/username/path/to/cpan-cache/build/Module-Build-0.3607-K86OwJ/blib/arch
/u/username/path/to/cpan-cache/build/Module-Build-0.3607-K86OwJ/blib/lib
to PERL5LIB for 'install'
Building Module-Build
Installing /u/username/path/to/man/man1/config_data.1p
Installing /u/username/path/to/lib/perl5/Module/Build.pm
Installing /u/username/path/to/lib/perl5/Module/Build/PodParser.pm
Installing /u/username/path/to/lib/perl5/Module/Build/YAML.pm
Installing /u/username/path/to/lib/perl5/Module/Build/ModuleInfo.pm
Installing /u/username/path/to/lib/perl5/Module/Build/ConfigData.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Version.pm
Installing /u/username/path/to/lib/perl5/Module/Build/PPMMaker.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Bundling.pod
Installing /u/username/path/to/lib/perl5/Module/Build/Authoring.pod
Installing /u/username/path/to/lib/perl5/Module/Build/Cookbook.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Config.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Compat.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Notes.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Dumper.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Base.pm
Installing /u/username/path/to/lib/perl5/Module/Build/API.pod
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/Windows.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/Amiga.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/VOS.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/Unix.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/MPEiX.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/darwin.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/MacOS.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/Default.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/os2.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/RiscOS.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/VMS.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/aix.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/EBCDIC.pm
Installing /u/username/path/to/lib/perl5/Module/Build/Platform/cygwin.pm
Installing /u/username/path/to/lib/perl5/inc/latest.pm
Installing /u/username/path/to/lib/perl5/inc/latest/private.pm
Installing /u/username/path/to/man/man3/Module::Build::Compat.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::Unix.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::Windows.3pm
Installing /u/username/path/to/man/man3/Module::Build::ConfigData.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::VOS.3pm
Installing /u/username/path/to/man/man3/Module::Build::API.3pm
Installing /u/username/path/to/man/man3/Module::Build::PPMMaker.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::Default.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::cygwin.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::darwin.3pm
Installing /u/username/path/to/man/man3/Module::Build::Base.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::EBCDIC.3pm
Installing /u/username/path/to/man/man3/Module::Build::Notes.3pm
Installing /u/username/path/to/man/man3/Module::Build::Authoring.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::MPEiX.3pm
Installing /u/username/path/to/man/man3/Module::Build::ModuleInfo.3pm
Installing /u/username/path/to/man/man3/inc::latest.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::MacOS.3pm
Installing /u/username/path/to/man/man3/Module::Build::Cookbook.3pm
Installing /u/username/path/to/man/man3/Module::Build::Bundling.3pm
Installing /u/username/path/to/man/man3/Module::Build.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::RiscOS.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::VMS.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::os2.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::aix.3pm
Installing /u/username/path/to/man/man3/Module::Build::Platform::Amiga.3pm
Installing /u/username/path/to/bin/config_data
  DAGOLDEN/Module-Build-0.3607.tar.gz
  ./Build install  -- OK




So, maybe Module::Build is assuming the user 'foo' doesn't exist, and this
is a bad assumption?



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<think>这个错误表明在Soong插件的Go代码中,`android.AidlInterfaceFactory`未定义。这是因为在Soong构建系统中,`AidlInterfaceFactory`可能不是公开可用的函数,或者需要特定的导入路径。我们需要调整实现方式。 ### 解决方案修正 我们将使用另一种方法:创建一个自定义模块类型,它包含一个`aidl_interface`模块,并根据Android版本动态设置其`enabled`属性。 ### 修正后的实现 #### 1. 修改`custom_plugin.go` ```go:custom_plugin.go package main import ( "android/soong/android" "android/soong/cc" "strconv" ) func init() { android.RegisterModuleType("conditional_aidl_interface", conditionalAidlInterfaceFactory) } type conditionalAidlInterface struct { android.ModuleBase properties struct { // 我们将在这里包含原始aidl_interface的所有属性 // 但实际上,我们不需要复制所有属性,而是通过一个隐藏的aidl_interface模块 Srcs []string Versions []string Stability string // 其他属性... } // 我们将创建一个隐藏的aidl_interface模块 hiddenModule android.Module } func conditionalAidlInterfaceFactory() android.Module { module := &conditionalAidlInterface{} module.AddProperties(&module.properties) android.InitAndroidModule(module) return module } func (m *conditionalAidlInterface) DepsMutator(ctx android.BottomUpMutatorContext) { // 在Android 9上跳过创建模块 sdkVerStr := ctx.Config().Getenv("RELEASE_PLATFORM_SDK_VERSION") if sdkVerStr == "" { // 默认处理,如果无法获取版本,则跳过 return } sdkVer, err := strconv.Atoi(sdkVerStr) if err != nil { ctx.PropertyErrorf("sdk_version", "Invalid SDK version: %s", sdkVerStr) return } // 如果SDK版本大于28(Android 9),则创建隐藏的aidl_interface模块 if sdkVer > 28 { // 创建一个aidl_interface模块 props := struct { Name string Srcs []string Versions []string Stability string }{ Name: m.Name() + "_hidden", Srcs: m.properties.Srcs, Versions: m.properties.Versions, Stability: m.properties.Stability, } ctx.CreateModule(android.AidlInterfaceFactory(), &props) } } ``` #### 2. 修改`Android.bp` ```bp:Android.bp bootstrap_go_package { name: "soong-custom-plugin", pkgPath: "android/soong/custom", deps: [ "soong-android", "soong-builtins", ], srcs: ["custom_plugin.go"], pluginFor: ["soong_build"], } conditional_aidl_interface { name: "my_service", srcs: ["IMyService.aidl"], versions: ["1"], stability: "vintf", } ``` ### 关键修正点说明 1. **避免直接使用未导出函数**: - 不再尝试直接使用`android.AidlInterfaceFactory()`创建模块,而是使用`ctx.CreateModule`动态创建模块 - 通过`ctx.CreateModule`可以创建任何类型的模块 2. **条件化创建模块**: - 在`DepsMutator`阶段(依赖关系处理阶段)检查Android版本 - 当版本>28(即Android 9以上)时,动态创建一个隐藏的`aidl_interface`模块 - 隐藏模块的名称加上`_hidden`后缀避免冲突 3. **属性传递**: - 将`conditional_aidl_interface`中定义的属性传递给隐藏的`aidl_interface`模块 - 需要确保传递所有必要的属性(如srcs, versions, stability等) ### 处理Android 9及以下版本 - 当SDK版本<=28时,不创建任何模块,相当于跳过编译 - 这样在Android 9上构建时,`conditional_aidl_interface`不会产生任何输出文件 ### 注意事项 1. **属性传递完整性**: - 示例中只传递了部分属性,实际需要传递`aidl_interface`支持的所有属性 - 可以在`conditionalAidlInterface`结构体中添加更多属性字段 2. **模块可见性**: - 隐藏模块的名称使用`_hidden`后缀,避免与其他模块冲突 - 其他模块依赖时,应依赖`conditional_aidl_interface`的名称(如`my_service`),而不是隐藏模块 3. **动态创建模块**: - `ctx.CreateModule`的第一个参数是模块工厂函数,这里使用`android.AidlInterfaceFactory()` - 第二个参数是模块属性,以结构体形式传递 ### 完整属性传递示例 如果需要传递更多属性(如`backend`): ```go // 在conditionalAidlInterface结构体中添加属性 type conditionalAidlInterface struct { ... properties struct { Srcs []string Versions []string Stability string Backend struct { Java struct { Enabled bool } Cpp struct { Enabled bool } } } ... } // 在DepsMutator中传递属性 props := struct { Name string Srcs []string Versions []string Stability string Backend struct { Java struct { Enabled bool } Cpp struct { Enabled bool } } }{ Name: m.Name() + "_hidden", Srcs: m.properties.Srcs, Versions: m.properties.Versions, Stability: m.properties.Stability, Backend: m.properties.Backend, } ``` ### 验证构建 ```bash # 在Android 12上构建隐藏模块 RELEASE_PLATFORM_SDK_VERSION=31 m my_service_hidden # 在Android 9上应无输出 RELEASE_PLATFORM_SDK_VERSION=28 m my_service_hidden # 输出: "nothing to build" ``` --- **§§相关问题§§**: 1. 如何在Soong插件中处理模块依赖关系? 2. Soong构建系统有哪些不同的阶段(phase)? 3. 如何为动态创建的模块设置可见性(visibility)? 4. 除了`DepsMutator`,还有哪些Mutator阶段可用?</think>您遇到了一个关键问题:`android.AidlInterfaceFactory` 在 Soong 插件中不可直接访问。这是因为 `aidl_interface` 模块类型是在 Soong 的 AIDL 包中定义的,需要特殊处理才能访问。下面是完整的修正方案: ### 解决方案修正:正确访问 AIDL 模块工厂 #### 1. 修改 `custom_plugin.go` 使用正确的导入路径 ```go:custom_plugin.go package main import ( "android/soong/android" "android/soong/aidl" // 添加 AIDL 包导入 "strconv" ) func init() { // 注册自定义模块类型 android.RegisterModuleType("conditional_aidl_interface", conditionalAidlInterfaceFactory) } func conditionalAidlInterfaceFactory() android.Module { // 使用 aidl.AidlInterfaceFactory() 替代 android.AidlInterfaceFactory() module := aidl.AidlInterfaceFactory() // 添加加载钩子 android.AddLoadHook(module, func(ctx android.LoadHookContext) { sdkVerStr := ctx.Config().Getenv("RELEASE_PLATFORM_SDK_VERSION") if sdkVerStr == "" { // 处理未定义环境变量的情况 return } sdkVer, err := strconv.Atoi(sdkVerStr) if err != nil { // 处理转换错误 ctx.PropertyErrorf("sdk_version", "Invalid SDK version: %s", sdkVerStr) return } // Android 9 (API 28)跳过编译 if sdkVer <= 28 { type props struct { Enabled *bool } p := &props{Enabled: boolPtr(false)} ctx.AppendProperties(p) } }) return module } func boolPtr(b bool) *bool { return &b } ``` #### 2. 更新 `Android.bp` 添加必要的依赖 ```bp:Android.bp bootstrap_go_package { name: "soong-custom-plugin", pkgPath: "android/soong/custom", deps: [ "soong-android", "soong-builtins", "soong-aidl", // 添加 AIDL 依赖 ], srcs: ["custom_plugin.go"], pluginFor: ["soong_build"], } conditional_aidl_interface { name: "my_service", srcs: ["IMyService.aidl"], versions: ["1", "2"], stability: "vintf", backend: { java: { enabled: true, }, cpp: { enabled: true, }, }, // 添加其他原始属性... } ``` ### 关键修正说明 1. **添加 AIDL 包导入**: ```go import "android/soong/aidl" ``` - 这是访问 `AidlInterfaceFactory` 的必要导入 - 该包定义了所有 AIDL 相关的构建逻辑 2. **使用正确的工厂函数**: ```go module := aidl.AidlInterfaceFactory() ``` - `aidl.AidlInterfaceFactory()` 返回实际的 AIDL 模块工厂 - 替代了之前不存在的 `android.AidlInterfaceFactory()` 3. **添加 AIDL 依赖**: ```bp deps: [..., "soong-aidl"] ``` - 在 `bootstrap_go_package` 中添加 `soong-aidl` 依赖 - 确保插件可以链接到 AIDL 包 4. **错误处理增强**: ```go if sdkVerStr == "" { ... } if err != nil { ... } ``` - 添加环境变量未定义的处理 - 添加版本转换错误的处理 ### 完整项目结构验证 ``` project/ ├── aidl/ │ ├── Android.bp │ ├── custom_plugin.go │ └── IMyService.aidl └── other_modules/ └── ... ``` ### 构建流程验证 1. **首次构建插件**: ```bash m soong_plugins ``` 2. **检查插件加载**: ```bash # 查看 soong.log 确认插件加载 tail -f out/soong/soong.log ``` 期望输出: ``` [DEBUG] Registered module type: conditional_aidl_interface ``` 3. **测试不同版本**: ```bash # Android 9 (API 28) export RELEASE_PLATFORM_SDK_VERSION=28 m my_service # 应输出: "module my_service disabled - skipping" # Android 12 (API 31) export RELEASE_PLATFORM_SDK_VERSION=31 m my_service # 应正常编译生成: # out/soong/.intermediates/my_service ``` ### 备选方案:使用 ModuleFactory 注册 如果上述方法仍不可用,可以使用更底层的注册方式: ```go:custom_plugin.go package main import ( "android/soong/android" "android/soong/aidl" "strconv" ) func init() { // 直接注册模块工厂 android.RegisterModuleType("conditional_aidl_interface", func() android.Module { module := aidl.AidlInterfaceFactory() android.AddLoadHook(module, versionHook) return module }) } func versionHook(ctx android.LoadHookContext) { // 相同版本检查逻辑 sdkVer, _ := strconv.Atoi(ctx.Config().Getenv("RELEASE_PLATFORM_SDK_VERSION")) if sdkVer <= 28 { type props struct { Enabled *bool } p := &props{Enabled: boolPtr(false)} ctx.AppendProperties(p) } } func boolPtr(b bool) *bool { return &b } ``` ### 注意事项 1. **依赖顺序**: - 确保在 `soong-aidl` 之后加载插件 - 在 `Android.bp` 中添加: ```bp pluginFor: ["soong_build", "soong-aidl"] ``` 2. **API 级别对照**: | Android 版本 | API 级别 | |--------------|----------| | Android 9 | 28 | | Android 10 | 29 | | Android 11 | 30 | | Android 12 | 31 | | Android 13 | 33 | | Android 14 | 34 | | Android 15 | 35 | 3. **调试技巧**: ```go // 添加调试输出 ctx.Module().(*aidl.AidlInterface).Name()) ``` --- **
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值