【问题标题】:Maven and Android - Cannot find symbolMaven 和 Android - 找不到符号
【发布时间】:2014-01-25 12:31:10
【问题描述】:

我的pom.xml 中有以下构建配置,它位于我的项目根目录中:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.project.math</groupId>
   <artifactId>android-math-project</artifactId>
   <version>1.0.0-SNAPSHOT</version>
   <packaging>apk</packaging>
   <name>Math App Android App</name>
   <dependencies>
      <dependency>
         <groupId>com.google.android</groupId>
         <artifactId>android</artifactId>
         <version>4.1.1.4</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>com.google.code.gson</groupId>
         <artifactId>gson</artifactId>
         <version>2.2.4</version>
      </dependency>
      <dependency>
         <groupId>log4j</groupId>
         <artifactId>log4j</artifactId>
         <version>1.2.17</version>
      </dependency>
      <dependency>
         <groupId>org.apache.httpcomponents</groupId>
         <artifactId>httpclient</artifactId>
         <version>4.3.1</version>
      </dependency>
      <dependency>
         <groupId>org.apache.httpcomponents</groupId>
         <artifactId>httpcore</artifactId>
         <version>4.3.1</version>
      </dependency>
      <dependency>
         <groupId>org.apache.httpcomponents</groupId>
         <artifactId>httpmime</artifactId>
         <version>4.3.1</version>
      </dependency>
   </dependencies>
   <build>
      <finalName>${project.artifactId}</finalName>
      <sourceDirectory>src</sourceDirectory>
      <pluginManagement>
         <plugins>
            <plugin>
               <groupId>com.jayway.maven.plugins.android.generation2</groupId>
               <artifactId>android-maven-plugin</artifactId>
               <version>3.8.2</version>
               <extensions>true</extensions>
            </plugin>
         </plugins>
      </pluginManagement>
      <plugins>
         <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <configuration>
               <sdk>
                  <platform>17</platform>
               </sdk>
            </configuration>
         </plugin>
      </plugins>
   </build>
</project>

但不幸的是我得到了错误:

[INFO] 6 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.059s
[INFO] Finished at: Tue Jan 07 19:33:06 EET 2014
[INFO] Final Memory: 18M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project android-math-app: Compilation failure: Compilation failure:
[ERROR] /Users/user/Projects/Math-Project-Appp/android-math-app/src/com/app/math/apwebview/ApWebViewJSInterface.java:[23,22] cannot find symbol
[ERROR] symbol  : class JavascriptInterface
[ERROR] location: package android.webkit
[ERROR] /Users/user/Projects/Math-Project-Appp/android-math-app/src/com/app/math/apwebview/ApWebViewJSInterface.java:[38,10] cannot find symbol
[ERROR] symbol  : class JavascriptInterface
[ERROR] location: class com.app.math.apwebview.ApWebViewJSInterface
[ERROR] /Users/user/Projects/Math-Project-Appp/android-math-app/src/com/app/math/apwebview/ApWebViewJSInterface.java:[44,10] cannot find symbol
[ERROR] symbol  : class JavascriptInterface
[ERROR] location: class com.app.math.apwebview.ApWebViewJSInterface
[ERROR] /Users/user/Projects/Math-Project-Appp/android-math-app/src/com/app/math/apwebview/ApWebViewJSInterface.java:[49,10] cannot find symbol
[ERROR] symbol  : class JavascriptInterface
[ERROR] location: class com.app.math.apwebview.ApWebViewJSInterface
[ERROR] /Users/user/Projects/Math-Project-Appp/android-math-app/src/com/app/math/apwebview/ApWebViewJSInterface.java:[61,10] cannot find symbol
[ERROR] symbol  : class JavascriptInterface
[ERROR] location: class com.app.math.apwebview.ApWebViewJSInterface
[ERROR] /Users/user/Projects/Math-Project-Appp/android-math-app/src/com/app/math/apwebview/ApWebViewJSInterface.java:[68,10] cannot find symbol
[ERROR] symbol  : class JavascriptInterface
[ERROR] location: class com.app.math.apwebview.ApWebViewJSInterface
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

我认为错误来自 API 版本,但自 Jelly Bean 以来支持 @JavascriptInterface,所以我不知道是什么情况......

【问题讨论】:

  • 您找到解决方案了吗?我有完全相同的问题,但什么也没找到...

标签: java android maven


【解决方案1】:

您需要找到另一个注解依赖项,因为 com.google.android:android:4.1.1.4 不包含任何名为 JavascriptInterface 的类(com.google.android:annotations:4.1.1.4 也不包含)。

这个maven repository search 会给你所有包含JavascriptInterface 的罐子。

【讨论】:

    猜你喜欢
    • 2014-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 2014-04-11
    • 2011-09-25
    • 2015-07-21
    相关资源
    最近更新 更多