【问题标题】:NetBeans does not recognize classes in apklib (ActionBarSherlock for instance)NetBeans 无法识别 apklib 中的类(例如 ActionBarSherlock)
【发布时间】:2013-06-29 19:11:51
【问题描述】:

我正在使用 NetBeans 7.3 开发一个 Android 应用程序(因为它是我首选的 IDE)。 这是一个 Maven 项目,它依赖于 ActionBarSherlock,我正在使用 android-maven-plugin。

我的 POM 和这个类似:

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

    <parent>
        <groupId>amnl.example</groupId>
        <artifactId>android-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>amnl.example</groupId>
    <artifactId>android-app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>Yet Another 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.actionbarsherlock</groupId>
            <artifactId>actionbarsherlock</artifactId>
            <version>4.3.1</version>
            <type>apklib</type>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <!-- use the copy resources instead of resources, which adds it to
                        the eclipse buildpath -->
                        <phase>initialize</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.basedir}/res</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/src/templates/res</directory>
                                    <targetPath>${project.basedir}/res</targetPath>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <sdk>
                        <platform>16</platform>
                    </sdk>
                    <manifest>
                        <debuggable>true</debuggable>
                    </manifest>
                </configuration>
                <executions>
                    <execution>
                        <id>manifestUpdate</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>manifest-update</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>alignApk</id>
                        <phase>package</phase>
                        <goals>
                            <goal>zipalign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>release</id>
            <!-- via this activation the profile is automatically used when the release
            is done with the maven release plugin -->
            <activation>
                <property>
                    <name>performRelease</name>
                    <value>true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jarsigner-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>signing</id>
                                <goals>
                                    <goal>sign</goal>
                                    <goal>verify</goal>
                                </goals>
                                <phase>package</phase>
                                <inherited>true</inherited>
                                <configuration>
                                    <removeExistingSignatures>true</removeExistingSignatures>
                                    <archiveDirectory />
                                    <includes>
                                        <include>${project.build.directory}/${project.artifactId}.apk</include>
                                    </includes>
                                    <keystore>${sign.keystore}</keystore>
                                    <alias>${sign.alias}</alias>
                                    <storepass>${sign.storepass}</storepass>
                                    <keypass>${sign.keypass}</keypass>
                                    <verbose>false</verbose>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- the signed apk then needs to be zipaligned and we activate proguard
                    and we run the manifest update -->
                    <plugin>
                        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                        <artifactId>android-maven-plugin</artifactId>
                        <inherited>true</inherited>
                        <configuration>
                            <release>true</release>
                            <sign>
                                <debug>false</debug>
                            </sign>
                            <zipalign>
                                <skip>false</skip>
                                <verbose>true</verbose>
                                <inputApk>${project.build.directory}/${project.artifactId}.apk</inputApk>
                                <outputApk>${project.build.directory}/${project.artifactId}-signed-aligned.apk
                                </outputApk>
                            </zipalign>
                            <manifest>
                                <debuggable>false</debuggable>
                                <versionCodeAutoIncrement>true</versionCodeAutoIncrement>
                            </manifest>
                            <!-- Change to true to skip Proguard -->
                            <proguard>
                                <skip>false</skip>
                            </proguard>
                        </configuration>
                        <executions>
                            <execution>
                                <id>manifestUpdate</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>manifest-update</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>alignApk</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>zipalign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.artifactId}-signed-aligned.apk</file>
                                    <type>apk</type>
                                    <classifier>signed-aligned</classifier>
                                </artifact>
                                <artifact>
                                    <file>${project.build.directory}/proguard/mapping.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>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

在我真正想要使用 ActionBarSherlock 库之前,一切正常。 NetBeans 似乎无法识别 apklib 中的类(例如 com.actionbarsherlock.app.SherlockActivity)。 我可以在 NetBeans 的项目树结构中找到 apklib,但它在非类路径依赖项下归档。 它确实识别库的生成源(如com.actionbarsherlock.R)。

我该如何解决这个问题,以便 NetBeans 不会抱怨找不到类,并且自动完成功能适用于这些类?

我尝试了几种可能的解决方法(123),但它们对我不起作用。 我也很确定NetBeans bug 220446 是相关的

【问题讨论】:

  • 你好 Arno,这可能不是你想听到的,但我建议你迁移到 Android Studio 或 IntellijIDEA,因为它更适合 Android 开发,你会习惯使用它几天..
  • @Cata Android Studio (== Eclipse) 绝对不是我首选的 IDE。但这不是这个问题的目的。我可以告诉更多人对此有问题,我只想知道如何解决它。
  • 我使用Android Kickstartr 开始了一个新项目。这个项目确实有效,我很确定使用了提到的解决方法之一。如果我能找到时间,我将在问题中使用 POM 进行试验,并用 Kickstartr 创建的新 POM 中的部件替换部件。同时,我很想听听您的建议。
  • @ArnoMoonen Android Studio != Eclipse。 Android Studio 基于 IntelliJ IDEA:developer.android.com/sdk/installing/studio.html
  • @Intrications 当我开始为 Android 开发时,Eclipse 是要走的路(使用 Google 提供的插件),因此是我的假设。但是,这仍然不能解决 NetBeans 的问题。

标签: android maven netbeans actionbarsherlock android-maven-plugin


【解决方案1】:

您应该安装应该能够为您处理 android 类路径的 nbandroid 模块。 http://www.nbandroid.org/

【讨论】:

  • 我已经安装了 NB Android 插件的 1.141 版本。所以这并不能解决问题。
  • 好的,那么不幸的是 nb.org 问题 220446 的评估适用。 netbeans 中的通用 maven 支持无法了解在构建执行期间完成的 maven 模型修改。我想你可以针对 nbandroid 提出问题。
猜你喜欢
  • 2015-04-20
  • 1970-01-01
  • 1970-01-01
  • 2012-08-08
  • 1970-01-01
  • 1970-01-01
  • 2012-07-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多