简体   繁体   中英

Maven and Android - Cannot find symbol

I have the following build configuration in my pom.xml which is located in the root of my project:

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

but unfortunately I get the error:

[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

I thought that the error comes from the API version but @JavascriptInterface is supported since Jelly Bean so I have no idea what is the case...

You'll need to find another annotations dependency, as the com.google.android:android:4.1.1.4 doesn't contain any class named JavascriptInterface (the com.google.android:annotations:4.1.1.4 neither).

This maven repository search will give you all jars containing the JavascriptInterface .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM