maven build android项目:指定aidl文件的位置

时间:2015-07-02 07:56:57

标签: android maven aidl android-maven-plugin

我的android项目只有 aidl 文件,项目结构如下:

MyProject/
  src/
     main/
         com.my.aidl/
               IMyService.aidl
  pom.xml

我用maven构建我的android项目。我的 pom 使用 dexguard-maven-plugin ,这是 android-maven-plugin 的扩展。

在插件配置中,我明确指定了source aidl文件&的目录。生成的java文件的目录。

<build>
    <plugins>
        <plugin>
           <groupId>com.saikoa.dexguard.maven</groupId>
           <artifactId>dexguard-maven-plugin</artifactId>
           <configuration>
               <aidlSourceDirectory>
                   ${project.basedir}/src/main/com/my/aidl
               </aidlSourceDirectory>

               <genDirectoryAidl>
                    ${project.build.directory}/generated-sources/aidl/main/com/my/aidl
               </genDirectoryAidl>
            </configuration>
            <extensions>true</extensions>
         </plugin>
     </plugins>
</build>

但是在我运行mvn clean install -e之后,我得到了以下错误跟踪:

[ERROR] Failed to execute goal com.saikoa.dexguard.maven:dexguard-maven-plugin:6.1.18:generate-sources (default-generate-sources) on project MyProject: Execution default-generate-sources of goal com.saikoa.dexguard.maven:dexguard-maven-plugin:6.1.18:generate-sources failed. NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.saikoa.dexguard.maven:dexguard-maven-plugin:6.1.18:generate-sources (default-generate-sources) on project MyProject: Execution default-generate-sources of goal com.saikoa.dexguard.maven:dexguard-maven-plugin:6.1.18:generate-sources failed.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-generate-sources of goal com.saikoa.dexguard.maven:dexguard-maven-plugin:6.1.18:generate-sources failed.
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:115)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 19 more
Caused by: java.lang.NullPointerException
    at java.io.File.<init>(File.java:334)
    at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.generateAidlFiles(GenerateSourcesMojo.java:1266)
    at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.execute(GenerateSourcesMojo.java:343)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
    ... 20 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 

有什么问题?

3 个答案:

答案 0 :(得分:4)

几个月前有一个类似的问题,我把我的调用相关aidl文件放到错误的位置(我从Eclipse ANT迁移到Studio Gradle)。下面的链接在我的情况下有帮助:
{ {3}}
与此有关的官方文件:
how can I add the aidl file to Android studio (from the in-app billing example)

答案 1 :(得分:1)

取决于你的日志消息,有一个nullexception。我猜目录不对。您是否尝试将genDirectoryAidl从'generated-sources / aidl / main / com / my / aidl'更改为'generated-sources / aidl /'?也许如果你创建一个名为'main / com / my / aidl'的目录,你就会成功。

希望此消息可以帮助您。

答案 2 :(得分:0)

正如我所看到的,可能是由一些未解析的依赖项引起的NullPointerException。 Here是类似问题的链接。 还尝试使用-X重新运行maven并向我们显示调试输出。