【问题标题】:Android Maven project in IntelliJ 14.1.2 unable to resolve appcompat v7 classesIntelliJ 14.1.2 中的 Android Maven 项目无法解析 appcompat v7 类
【发布时间】:2015-04-26 16:47:49
【问题描述】:

我有一个带有传统 pom.xml 的 Maven Android 项目,我在 IntelliJ 14.1.2 中打开它。我已经使用maven-android-sdk-deployer helper 实用程序为 android 安装了 maven 存储库。 IntelliJ 成功解决依赖关系:

然而,我的解决方案没有构建,IDE 也没有检测到 v4 或 v7 appcompat 类:

Error:(9, 30) java: package android.support.v4.app does not exist
Error:(7, 30) java: package android.support.v4.app does not exist

我错过了什么?

这是我的complete pom.xml

编辑: 要复制,请克隆并尝试编译this github project

我还向IntellIJ issue tracker 发布了关于此问题的问题

编辑 2 通过使用我在 maven repo 文件夹中的一些 apklib 工件,我让它在我的工作计算机上工作。不知道他们是怎么到那里的,所以这是个问题。 .apklib 也已被弃用 afaik。

<dependency>
    <groupId>android.support</groupId>
    <artifactId>compatibility-v7-appcompat</artifactId>
    <version>22.1.1</version>
    <type>apklib</type>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>android.support</groupId>
    <artifactId>compatibility-v7-appcompat</artifactId>
    <version>22.1.1</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency>

编辑 3

maven 的settings.xml:

<settings>
 <profiles>
   <profile>
     <id>myprofile</id>
     <repositories>
       <repository>
         <id>android-sdk-repo</id>
         <name>Android SDK repo</name>
         <url>file:///D:\coding\android-sdk\extras\google\m2repository</url>
       </repository>  
       <repository>
        <id>android-sdk-repo2</id>
         <name>Android SDK repo2</name>
         <url>file:///D:\coding\android-sdk\extras\android\m2repository</url>
       </repository>     
       <repository>
         <id>default</id>
         <name>Default</name>
         <url>file:///C:\Users\Frode\.m2\repository</url>
       </repository>
     </repositories>
   </profile>
 </profiles>

 <activeProfiles>
   <activeProfile>myprofile</activeProfile>
 </activeProfiles>
</settings>

dir D:\coding\android-sdk\extras\android\m2repository /s 的输出:http://pastebin.com/0WzZwMGT

dir C:\Users\Frode\.m2\repository\com\android /s 的输出: http://pastebin.com/Pznha22J

来自 maven-android-sdk-deployer 的 mvn install 的输出:http://pastebin.com/RX8qdx4N(失败了,因为它会尝试安装一些 API v15 的东西,而我没有安装)

来自 maven-android-sdk-deployer 的 mvn install -P 5.0 的输出:http://pastebin.com/szyMvNXM(成功)

v21 / Android 5.0 是我安装的最新 SDK

【问题讨论】:

  • 试试 AppCompatActivity
  • 也不起作用。imgur.com/FcftmO3 。根本没有解析来自 v4 或 v7 命名空间的类。就好像我没有将依赖项添加到 pom.xml 文件中一样
  • 你为什么不直接使用Gradle
  • 当人们在 SO 上问 Java 问题时,你会问他们为什么不直接使用 C#?
  • JavaC# 是完全不同的东西。但是GradleMaven是亲戚。

标签: android maven intellij-idea


【解决方案1】:

您的 pom 中缺少一些元素:

  • &lt;packaging&gt;apk&lt;/packaging&gt;
  • 声明android-maven-plugin
  • 对 android 包的依赖

查看完整的 pom.xml:

    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0</version>
    <packaging>apk</packaging>

    <dependencies>
        <dependency>
            <groupId>com.android.support</groupId>
            <artifactId>support-v4</artifactId>
            <version>22.1.1</version>
            <scope>compile</scope>
            <type>aar</type>
        </dependency>
        <dependency>
            <groupId>com.android.support</groupId>
            <artifactId>appcompat-v7</artifactId>
            <version>22.1.1</version>
            <type>aar</type>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.android.support</groupId>
                    <artifactId>support-annotations</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>android</groupId>
            <artifactId>android</artifactId>
            <version>5.0.1_r2</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.simpligility.maven.plugins</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>4.2.0</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.simpligility.maven.plugins</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <configuration>
                    <sdk>
                        <platform>21</platform>
                    </sdk>
                </configuration>
            </plugin>
        </plugins>
    </build>

【讨论】:

  • 越来越近了。现在唯一没有编译的是android:theme="@android:style/Theme.AppCompat"。有什么建议吗?
  • 啊..它必须是android:theme="@style/Theme.AppCompat。现在它可以工作了 - 谢谢! :-)
猜你喜欢
  • 1970-01-01
  • 2018-05-07
  • 2017-11-25
  • 2014-03-17
  • 1970-01-01
  • 1970-01-01
  • 2015-11-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多