对于Android项目&QUOT Maven的编译错误;错误:包R不存在" [英] Maven compilation error for android Project "error: package R does not exist "

查看:337
本文介绍了对于Android项目&QUOT Maven的编译错误;错误:包R不存在"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立与Android应用Maven项目。
我有这个POM文件

I am trying to set up a MAVEN project with Android application. I have this pom file

<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.myproject</groupId>
  <artifactId>userprofile</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>userprofile</name>
  <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>4.1.1.4</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>
</project>

和Maven编译期间我得到这个错误(约100倍,因为它是在我的方法,即使用多次)

and during MAVEN compile I get this error (about 100 times, ie as many times as it is used in my methods)

    [INFO] -------------------------------------------------------------
    [ERROR] COMPILATION ERROR : 
    [INFO] -------------------------------------------------------------
src\main\java\com\myproject\userprofile\BaseActivity.java:[52,43] error: package R does not exist
    Process finished with exit code 1

有关此错误的任何想法?在网络上我要么找到类似的错误输出悬而未决的问题。我对MAVEN没有经验,所以我相信我在这里失去了一些东西。

Any idea about this error? On the web I either find unanswered questions about similar error output. I have no experience on MAVEN, so I believe I am missing something here.

推荐答案

研究类是在编译过程中你的IDE建设。 MAVEN找不到R类,因为默认情况下,类可以建立文件夹下找到。您需要添加像这样

R class is build by your IDE during compilation. MAVEN cannot find the R class because by default the class can be found under build folder. You need to add something like this

<sourceDirectory>build</sourceDirectory>
<outputDirectory>target</outputDirectory>

告诉MAVEN你有build文件夹下的一些资源文件,并要使其可编译所以这将是您的项目中的目标文件夹下添加它们。

telling MAVEN that you have some resource files under build folder and you want to make them available to compile so add them under the target folder which will be under your project.

所以现在我有

build
  |----res
  |----src
src
  |----main
       |----java
       |----res 
target

这篇关于对于Android项目&QUOT Maven的编译错误;错误:包R不存在&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆