2013-03-20 100 views
4

好的。Maven + AndroidAnnotations生成但無法訪問類

我試圖創建一個完全可以通過使用maven和maven構建的項目。

目前我正面臨着這個問題的類生成,並工作正常,只要沒有在實際的Java代碼中的引用。

這意味着,如果我創建一個例子,如documentation它的工作原理。

當我這樣做

意向書I =新意圖(SettingsActivity_);

然後構建失敗,

未能執行目標org.apache.maven.plugins:Maven的編譯器插件:3.0:編譯(默認編譯)項目InterestingFind: 編譯失敗找不到符號

cannot find symbol 
symbol: variable DerpActivity_ 
location: class be.company.android.DisplayMapActivity 

然而,該文件,確實會產生,因爲你可以附着在圖像中看到,但是當項目EN Eclipse視圖的看了一下,他們是僅被視爲普通文件夾,而不是「源文件夾」。

這也許可以解釋爲什麼他們沒有拿起,但給我一點頭痛。 我克隆了一個Android原型,即發佈版本。

請幫助,如果你以某種方式認爲你可以幫助我解決這個問題! Project structure

http://maven.apache.org/maven-v4_0_0.xsd「> 4.0.0

<parent> 
    <groupId>be.idamediafoundry</groupId> 
    <artifactId>InterestingFind-parent</artifactId> 
    <version>1.0-SNAPSHOT</version> 
</parent> 

<groupId>be.idamediafoundry</groupId> 
<artifactId>InterestingFind</artifactId> 
<version>1.0-SNAPSHOT</version> 
<packaging>apk</packaging> 
<name>InterestingFind - Application</name> 
<properties> 
    <androidannotations.version>3.0-SNAPSHOT</androidannotations.version> 
</properties> 

<repositories> 
    <repository> 
     <id>snapshots-repository</id> 
     <name>Sonatype oss snapshot repo</name> 
     <url>https://oss.sonatype.org/content/repositories/snapshots</url> 
    </repository> 
</repositories> 
<dependencies> 
    <dependency> 
     <groupId>com.google.android</groupId> 
     <artifactId>android</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>de.akquinet.android.androlog</groupId> 
     <artifactId>androlog</artifactId> 
    </dependency> 
    <!-- JSON --> 
    <dependency> 
     <groupId> org.codehaus.jackson</groupId> 
     <artifactId>jackson-mapper-asl</artifactId> 
     <version>1.9.5</version> 
    </dependency> 
    <!-- AndroidAnnotations --> 
    <dependency> 
     <groupId>org.androidannotations</groupId> 
     <artifactId>androidannotations</artifactId> 
     <version>${androidannotations.version}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.androidannotations</groupId> 
     <artifactId>androidannotations-api</artifactId> 
     <version>${androidannotations.version}</version> 
    </dependency> 

    <!-- Needed for androidannotations --> 
    <dependency> 
     <groupId>org.springframework.android</groupId> 
     <artifactId>spring-android-rest-template</artifactId> 
     <version>${spring-android-version}</version> 
    </dependency> 

    <!-- Google Play Services : Should be compiled and added to local repo --> 
    <dependency> 
     <groupId>com.google.android.gms</groupId> 
     <artifactId>google-play-services</artifactId> 
     <version>5</version> 
     <type>apklib</type> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 


     <plugin> 
     <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
     <artifactId>android-maven-plugin</artifactId> 
     <version>3.5.1</version> 
     <inherited>true</inherited> 
     <extensions>true</extensions> 
     <configuration> 
      <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile> 
      <assetsDirectory>${project.basedir}/assets</assetsDirectory> 
      <resourceDirectory>${project.basedir}/res</resourceDirectory> 
      <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory> 
      <sdk> 
       <platform>15</platform> 
      </sdk> 
      <undeployBeforeDeploy>true</undeployBeforeDeploy> 
     </configuration> 
    </plugin> 

     <plugin> 
      <artifactId>versions-maven-plugin</artifactId> 
      <groupId>org.codehaus.mojo</groupId> 
      <version>2.0</version> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-eclipse-plugin</artifactId> 
      <version>2.9</version> 
      <configuration> 
       <additionalProjectnatures> 
        <projectnature>com.android.ide.eclipse.adt.AndroidNature</projectnature> 
        <projectnature>org.eclipse.jdt.core.javanature</projectnature> 
       </additionalProjectnatures> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

<profiles> 
    <profile> 
     <id>release</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>com.pyx4me</groupId> 
        <artifactId>proguard-maven-plugin</artifactId> 
        <executions> 
         <execution> 
          <id>process-classes-with-proguard</id> 
          <phase>process-classes</phase> 
          <goals> 
           <goal>proguard</goal> 
          </goals> 
          <configuration> 
           <proguardVersion>4.4</proguardVersion> 
           <maxMemory>256m</maxMemory> 
           <injar>classes</injar> 
           <libs> 
            <lib>${rt.jar.path}</lib> 
            <lib>${jsse.jar.path}</lib> 
           </libs> 
           <obfuscate>true</obfuscate> 
           <addMavenDescriptor>false</addMavenDescriptor> 
           <proguardInclude>${project.basedir}/proguard.conf</proguardInclude> 
          </configuration> 
         </execution> 
        </executions> 
        <dependencies> 
         <dependency> 
          <groupId>net.sf.proguard</groupId> 
          <artifactId>proguard</artifactId> 
          <version>4.4</version> 
          <scope>runtime</scope> 
         </dependency> 
        </dependencies> 
       </plugin> 
       <plugin> 
        <artifactId>maven-jarsigner-plugin</artifactId> 
        <executions> 
         <execution> 
          <id>sign-application-apk</id> 
          <phase>package</phase> 
          <goals> 
           <goal>sign</goal> 
           <goal>verify</goal> 
          </goals> 
         </execution> 
        </executions> 
       </plugin> 
       <plugin> 
        <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
        <artifactId>android-maven-plugin</artifactId> 
        <executions> 
         <execution> 
          <id>zipalign-application-apk</id> 
          <phase>package</phase> 
          <goals> 
           <goal>zipalign</goal> 
          </goals> 
         </execution> 
        </executions> 
        <configuration> 
         <release>true</release> 
         <zipalign> 
          <verbose>true</verbose> 
          <inputApk>${project.build.directory}/${project.artifactId}-${project.version}.apk</inputApk> 
          <outputApk>${project.build.directory}/${project.artifactId}-${project.version}-signed-aligned.apk</outputApk> 
         </zipalign> 
         <sign> 
          <debug>false</debug> 
         </sign> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>build-helper-maven-plugin</artifactId> 

        <configuration> 
         <artifacts> 
          <artifact> 
           <file>${project.build.directory}/proguard_map.txt</file> 
           <type>map</type> 
           <classifier>release</classifier> 
          </artifact> 
         </artifacts> 
        </configuration> 
        <executions> 
         <execution> 
          <id>attach-signed-aligned</id> 
          <phase>package</phase> 
          <goals> 
           <goal>attach-artifact</goal> 
          </goals> 
         </execution> 
         <execution> 
          <phase>generate-sources</phase> 
          <goals> 
           <goal>add-source</goal> 
          </goals> 
          <configuration> 
           <sources> 
            <source>${project.basedir}/target/generated-sources/annotations</source> 
           </sources> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

父POM:

http://maven.apache.org/maven-v4_0_0.xsd「> 4.0.0

<groupId>be.idamediafoundry</groupId> 
<artifactId>InterestingFind-parent</artifactId> 
<version>1.0-SNAPSHOT</version> 
<packaging>pom</packaging> 
<name>InterestingFind - Parent</name> 

<modules> 
    <module>InterestingFind</module> 
    <module>InterestingFind-it</module> 
</modules> 

<properties> 
    <platform.version>4.1.1.4</platform.version> 
    <android-plugin>3.5.1</android-plugin> 
    <spring-android-version>1.0.1.RELEASE</spring-android-version> 
    <sign.keystore>${project.basedir}/my-release-key.keystore</sign.keystore> 
    <sign.alias> 
    </sign.alias> 
    <sign.storepass> 
    </sign.storepass> 
    <sing.keypass> 
    </sing.keypass> 

</properties> 

<repositories> 
    <repository> 
     <id>codehaus-snapshots</id> 
     <url>http://snapshots.repository.codehaus.org</url> 
    </repository> 

</repositories> 

<dependencyManagement> 
    <dependencies> 

     <dependency> 
      <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
      <artifactId>android-maven-plugin</artifactId> 
      <version>3.5.1</version> 
     </dependency> 
     <dependency> 
      <groupId>com.google.android</groupId> 
      <artifactId>android</artifactId> 
      <version>${platform.version}</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.google.android</groupId> 
      <artifactId>android-test</artifactId> 
      <version>${platform.version}</version> 
      <scope>provided</scope> 
     </dependency> 

     <!-- Androlog is a logging and reporting library for Android --> 
     <dependency> 
      <groupId>de.akquinet.android.androlog</groupId> 
      <artifactId>androlog</artifactId> 
      <version>1.0.5</version> 
     </dependency> 

     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.10</version> 
      <scope>provided</scope> 
     </dependency> 

    </dependencies> 


</dependencyManagement> 

<build> 
    <pluginManagement> 
     <plugins> 

      <plugin> 
       <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
       <artifactId>android-maven-plugin</artifactId> 
       <version>3.5.1</version> 
       <inherited>true</inherited> 
       <configuration> 
        <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile> 
        <assetsDirectory>${project.basedir}/assets</assetsDirectory> 
        <resourceDirectory>${project.basedir}/res</resourceDirectory> 
        <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory> 
        <sdk> 
         <platform>15</platform> 
        </sdk> 
        <undeployBeforeDeploy>true</undeployBeforeDeploy> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.0</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
       <extensions>true</extensions> 
      </plugin> 
      <plugin> 
       <artifactId>maven-enforcer-plugin</artifactId> 
       <version>1.0</version> 
      </plugin> 
      <plugin> 
       <artifactId>maven-release-plugin</artifactId> 
       <version>2.1</version> 
       <configuration> 
        <autoVersionSubmodules>true</autoVersionSubmodules> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-jarsigner-plugin</artifactId> 
       <version>1.2</version> 
       <inherited>true</inherited> 
       <configuration> 
        <removeExistingSignatures>true</removeExistingSignatures> 
        <archiveDirectory /> 
        <archive>${project.build.directory}/${project.build.finalName}.${project.packaging}</archive> 
        <verbose>true</verbose> 
        <certs>true</certs> 
        <keystore>${sign.keystore}</keystore> 
        <alias>${sign.alias}</alias> 
        <storepass>${sign.storepass}</storepass> 
        <keypass>${sign.keypass}</keypass> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>com.pyx4me</groupId> 
       <artifactId>proguard-maven-plugin</artifactId> 
       <version>2.0.4</version> 
       <dependencies> 
        <dependency> 
         <groupId>net.sf.proguard</groupId> 
         <artifactId>proguard</artifactId> 
         <version>4.4</version> 
         <scope>runtime</scope> 
        </dependency> 
       </dependencies> 
       <configuration> 
        <proguardVersion>4.4</proguardVersion> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

<profiles> 
    <profile> 
     <id>release</id> 
     <activation> 
      <property> 
       <name>performRelease</name> 
       <value>true</value> 
      </property> 
     </activation> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
        <artifactId>android-maven-plugin</artifactId> 
        <version>${android-plugin}</version> 
        <configuration> 
         <release>true</release> 
        </configuration> 
       </plugin> 

       <plugin> 
        <artifactId>maven-enforcer-plugin</artifactId> 
        <executions> 
         <execution> 
          <id>enforce-signing-properties</id> 
          <goals> 
           <goal>enforce</goal> 
          </goals> 
          <configuration> 
           <rules> 
            <requireProperty> 
             <property>sign.keystore</property> 
             <message>The 'sign.keystore' property is missing. It must 
              contain the path to the 
              keystore used to sign the 
              application. 
             </message> 
            </requireProperty> 
            <requireFilesExist> 
             <files> 
              <file>${sign.keystore}</file> 
             </files> 
             <message>The 'sign.keystore' property does not point to a 
              file. It must contain the 
              path to the keystore used to sign 
              the application. 
             </message> 
            </requireFilesExist> 
            <requireProperty> 
             <property>sign.alias</property> 
             <message>The 'sign.alias' property is missing. It must 
              contain the key alias used to 
              sign the application. 
             </message> 
            </requireProperty> 
            <requireProperty> 
             <property>sign.storepass</property> 
             <message>The 'sign.storepass' property is missing. It must 
              contain the password of 
              the keystore used to sign the 
              application. 
             </message> 
            </requireProperty> 
            <requireProperty> 
             <property>sign.keypass</property> 
             <message>The 'sign.keypass' property is missing. It must 
              contain the password of the 
              key used to sign the application. 
             </message> 
            </requireProperty> 
           </rules> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
    <profile> 
     <id>linux</id> 
     <activation> 
      <os> 
       <family>unix</family> 
      </os> 
     </activation> 
     <properties> 
      <rt.jar.path>${java.home}/jre/lib/rt.jar</rt.jar.path> 
      <jsse.jar.path>${java.home}/jre/lib/jsse.jar</jsse.jar.path> 
     </properties> 
    </profile> 
    <!-- mac profile has to be after unix since running on mac will trigger 
     both --> 
    <profile> 
     <id>mac</id> 
     <activation> 
      <os> 
       <family>mac</family> 
      </os> 
     </activation> 
     <properties> 
      <!-- absolute path --> 
      <!--<rt.jar.path>/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/classes.jar</rt.jar.path> --> 
      <!-- or with JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/ --> 
      <rt.jar.path>${java.home}/../Classes/classes.jar</rt.jar.path> 
      <jsse.jar.path>${java.home}/../Classes/jsse.jar</jsse.jar.path> 
     </properties> 
    </profile> 
    <profile> 
     <id>windows</id> 
     <activation> 
      <os> 
       <family>windows</family> 
      </os> 
     </activation> 
     <properties> 
      <rt.jar.path>${java.home}/jre/lib/rt.jar</rt.jar.path> 
      <jsse.jar.path>${java.home}/jre/lib/jsse.jar</jsse.jar.path> 
     </properties> 
    </profile> 
</profiles> 

編輯:更新POM。 編輯:上傳Log file

+0

您是否嘗試在父pom.xml中放置' true'? – ben75 2013-03-20 11:36:31

+0

@ ben75是的,它在父pom。 – Daneo 2013-03-20 11:54:40

+0

我的意思是對於maven-android-plugin(在你的文章中:' true'只在應用程序pom中。你能用你的實際pom.xml更新你的文章嗎?) – ben75 2013-03-20 11:59:33

回答

0

似乎問題是由依賴沒有得到解決造成的。

起初,Maven甚至沒有報告這個缺失的依賴關係,直到我開始從我的pom中刪除一些東西,我試圖解決這個問題。

現在,什麼解釋了依賴沒有得到自動解決,是在中央Maven存儲庫沒有這樣的工件。

因此,我增加了以下庫:

<repositories> 
    <!-- For developing with Android ROME Feed Reader --> 
    <repository> 
     <id>android-rome-feed-reader-repository</id> 
     <name>Android ROME Feed Reader Repository</name> 
     <url>https://android-rome-feed-reader.googlecode.com/svn/maven2/releases</url> 
    </repository> 
</repositories> 

在「隱藏」的依賴導致可能解決。

這種依賴性似乎是由

<!-- Needed for androidannotations REST interface--> 
    <dependency> 
     <groupId>org.springframework.android</groupId> 
     <artifactId>spring-android-rest-template</artifactId> 
     <version>${spring-android-version}</version> 
    </dependency> 

Spring docs報告,需要這種「隱藏的依賴性」,而我們在說由其餘的模板RSS和Atom feed支持是必要的。

什麼讓這個更奇怪的是,由AA註釋的初始活動得到了很好的創建和解決。只要我沒有提及生成的課程,例如進行導航,然後編譯並運行。 從我嘗試在代碼中使用class_的那一刻起,它便沿着這條道路前進。

希望這會有所幫助!

0

嗯......在你的Maven處理器的插件配置您正在使用的舊包命名爲AA處理器(即:com.googlecode.androidannotations.AndroidAnnotationProcessor)。

正如你使用3。0-SNAPSHOT,你應該修改它以使用新的:org.androidannotations.AndroidAnnotationProcessor

另外,我不確定你真的需要這個插件來製作AA作品。

+0

謝謝,通常不應該需要,但我補充說,只是爲了確保。我將刪除它並相應地更新pom。 – Daneo 2013-03-20 14:06:59

+0

您是否有其他錯誤 – DayS 2013-03-20 15:15:57

+0

不,我上傳了日誌文件,完成調試。只有關於平臺編碼的警告。感謝您抽出寶貴的時間 – Daneo 2013-03-20 21:15:12