Android的工作室瓦特/摇篮:包r不存在 [英] Android Studio w/gradle: Package r does not exist

查看:196
本文介绍了Android的工作室瓦特/摇篮:包r不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最后编辑:

这是一种与几个编辑长的问题,我不一定做正确的事,在的每一步。对于任何人谁绊倒在这个问题上,并有麻烦转换项目的Andr​​oid Studio来摇篮,我建议你检查出的这个仓库的提到的<一个href="http://stackoverflow.com/questions/16718026/how-to-build-an-android-library-with-android-studio-and-gradle">question #16718026 并试图导入并编译并运行它。一旦你有工作的东西更容易,看看有什么可能是错了你自己的项目。

This was kind of a long question with several edits, and I wasn't necessarily doing the right thing at each step of the way. For anyone who stumbles on this question and is having trouble converting a project to gradle in Android Studio, I'd suggest checking out this repository mentioned in question # 16718026 and trying to import that and compile and run it. Once you have something working it's easier to see what might be wrong with your own project.

总之,这是我做了一个非摇篮的Andr​​oid Studio项目转换成一个工作摇篮之一,采用Android工作室.2.5,其中自动安装1.6摇篮和摇篮插件.5我。

To summarize, here's what I did to convert a non-Gradle Android Studio project into a working Gradle one, using Android Studio .2.5, which auto installed Gradle 1.6 and the Gradle Plugin .5 for me.

(1)创建一个新的空白的Andr​​oid Studio项目有一个图标和活动。注:在第一,因为我是学Android和摇篮的同时,而Android工作室(在这个版本反正)我没有意识到这实际上是设置你了一个多项目的设置,这是混淆了我。多项目意味着有层次结构中的项目上面的另一个文件夹,使存储的设置对所有项目的位置。一样的没有的创建中的子项目文件夹中的build.gradle文件(在我的情况,FrontlineSMS),尽管视频指南说明会。所以我不得不创建一个子项目build.gradle文件,也可以创建一个非常简单的settings.gradle(请参阅更新2 下面。)

(1) Created a new blank Android Studio project with an icon and an activity. NOTE: I didn't realize this at first because I was learning Android and Gradle at the same time, but Android Studio (in this version anyway) actually sets you up with a multi-project setup, which was confusing for me. Multi-Project means there's another folder above your project in the hierarchy, giving a location to store settings for all projects. AS did not create a build.gradle file in the subproject folder (in my case, FrontlineSMS), despite a video guide indicating it would. So I had to create that subproject build.gradle file and also create a very simple settings.gradle (see Update 2 below.)

(2)复制src /下RES /,git的/,LIB /,的.gitignore和AndroidManifest.xml中新项目的根目录。

(2) Copied src/, res/, .git/, lib/, .gitignore, and AndroidManifest.xml to the root of the new project.

(3)使用 git的MV 根据摇篮插件用户指南中的约定将这些项目到适当的地方,在替换或删除一些现有的文件或文件夹空白的项目中有必要的。

(3) Used git mv to move these items to the appropriate places according to conventions in the Gradle Plugin User Guide, replacing or removing some existing files or folders in the blank project where necessary.

(4)创建一个 build.gradle 在我的子项目文件夹,并给它一些基本设置(见下面或上面链接的问题)

(4) Created a build.gradle in my subproject folder and gave it some basic settings (see below or in the question linked above)

(5)进口中的更新说明的项目4

原题:

我是一个新手,Android开发者试图使用摇篮在OS X我被困在一个资源错误,一个Android Studio项目目前不使用摇篮(和编译和运行得很好)一个转换哪个我想可能有什么关系无论是我的项目结构,在IDE设置,在build.gradle文件中的设置,或它们的组合。

I'm a novice Android developer trying to convert an Android Studio project that does not currently use Gradle (and compiles and runs just fine) to one that uses Gradle on OS X. I'm stuck on a Resource error, which I think may have to do with either my project structure, settings in the IDE, settings in the build.gradle files, or some combination of those.

我就这样做了转换的方法是先在Android的Studio中的一个新的项目,文件复制过来适当的位置,然后在IDE和build.gradle文件添加一些设置。我得到的项目结构是,

The way I went about doing the conversion was to first create a new project in Android Studio, copy over files to appropriate locations, then add some settings in the IDE and build.gradle files. My resulting project structure is,

├── frontlinesms-for-android
     ├── build.gradle
     ├── gradle
     ├── gradlew
     ├── gradle.bat
     ├── settings.gradle (added in update 2)
     ├── local.properties
     ├── lib
        └── lib1.jar
        └── lib2.jar
        └── ...
     ├── frontlinesms-for-android.iml
     ├── FrontlineSMS
        └── build.gradle
        └── src
           ├── main
           │   └── res
           │   └── AndroidManifest.xml
           │   └── java
           │       └── net
           │           └── frontlinesms
           │               └── android
           │                   ├── FrontlineSMS.java
           │                   ├── ...

最值得注意的是,也许,是我把RES /文件夹在同一级别的Java /和AndroidManifest.xml中。我试图按照摇篮插件用户指南中提到的约定,所以我没有太多的build.gradle文件来定制。

Most notably, maybe, is I put the res/ folder at the same level as java/ and AndroidManifest.xml. I'm trying to follow the conventions mentioned in the Gradle Plugin User Guide so I don't have to customize too much in the build.gradle files.

我也标志着该文件夹FrontlineSMS / src目录/主/爪哇/净源,因为如果我不那么什么都尝试编译。我在FrontlineSMS / build.gradle创建了一个新的build.gradle文件,因为它不存在,当我做了新的项目,即使一个教学视频的摇篮网站上说的那样。

I also marked the folder FrontlineSMS/src/main/java/net as source because if I don't then nothing attempts to compile. I created a new build.gradle file in FrontlineSMS/build.gradle because it did not exist when I made the new project, even though an instructional video on the Gradle website said it would.

在IDE中我还设置了依赖外部库,我在/ lib目录下。

In the IDE I also set the dependencies for the external libraries I have in /lib.

当我试着通过我得到很多的包r不存在错误的IDE来编译,表示自动生成的R舱是没有得到生成或认可。这是在项目定义为,

When I try to compile via the IDE I get many Package r does not exist errors, indicating the auto generated R class is not getting generated or recognized. This is defined in the project as,

import net.frontlinesms.android.R;

在几个文件中。我能做些什么来让Android工作室/摇篮承认我已经在src /主/资源定义的资源?

in several files. What can I do to make Android Studio / Gradle recognize the resources I have defined under src/main/res?

读了别人的问题,我注意到了一些解决这个错误涉及标志着一个根/文件夹作为源根目录或清洗的项目。我试着在根目录下创建一个根/文件夹并将其标记为源,但没有奏效。而且,重建项目只是给了我同样的错误。

Reading up on others' questions, I notice that some solutions to this error involved marking a "gen/" folder as a source root or "cleaning" the project. I tried creating a gen/ folder in the root directory and marking it as source but that didn't work. And, rebuilding the project just gives me the same errors.

我的根build.gradle文件具有以下

My root build.gradle file has the following,

dependencies {
   compile project(':FrontlineSMS')
}

和下FrontlineSMS / build.gradle的人有,

And the one under FrontlineSMS/build.gradle has,

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
   compile file('../lib/acra-3.1.1.jar')
   compile file('../lib/activation.jar')
   compile file('../lib/additionnal.jar')
   compile file('../lib/annotations.jar')
   compile file('../lib/libGoogleAnalytics.jar')
   compile file('../lib/mail.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

<打击>当我尝试在命令行中使用来建立./ gradlew干净我得到这个错误,

When I try to build from the command line using ./gradlew clean I get this error,

(removed error)

在除了我的previous问题,我AP preciate任何提示,你可以借,如何这个项目的结构应。这并不意味着是一个多项目设置。感谢您的帮助。

In addition to my previous question, I'd appreciate any tips you can lend as to how this project should be structured. This is not meant to be a multi-project setup. Thanks for your help.

更新1

我可以从命令行生成APK。我的主要问题有我打电话摇篮干净从错误的目录。从FrontlineSMS调用它的工作。我猜Android的工作室给我安排了一个多项目的设置,当我刚做了一个项目,我没有进入所有的设置是,IE,我没有创造一个settings.gradle文件。

I was able to generate an APK from the command line. My main problem there is I was calling gradle clean from the wrong directory. Calling it from FrontlineSMS worked. I'm guessing Android Studio set me up with a multi-project setup when I just had one project, and I hadn't entered all the settings for that, ie, I hadn't created a settings.gradle file.

更新2

创建以下settings.gradle文件,它可以让我跑摇篮清洁及放大器;&安培;摇篮打造从根目录(其中settings.gradle所在):

Created the following settings.gradle file, which allows me to run gradle clean && gradle build from the root directory (where settings.gradle resides):

include ':FrontlineSMS'

注:摇篮,我在这里使用的版本是由自制,1.6安装一个。如果我使用已安装的gradlew包装它说,

Note: the version of gradle I'm using here is the one installed by homebrew, 1.6. If I use the gradlew wrapper that was installed it says ,

Gradle version 1.6 is required. Current version is 1.7

在网上搜索这个错误似乎表明,Android不支持1.7在这一点上,只有1.6(也许它总是一个或两个版本之后),然而,这是所安装Android的工作室时,我的版本创建一个新的项目!

Searching the web for this error seems to indicate that Android doesn't support 1.7 at this point, only 1.6 (and maybe it's always a version or two behind), yet this is the version that was installed by Android Studio when I created a new project!

更新3 (编辑:这基本上是完全错误的,不遵循这一点)

Update 3 (edit: this is basically all wrong, don't follow this)

试图建立项目从Android的工作室得到了同样的错误与上述关于1.6被要求。我试图重新导入这个项目,虽然它说,它无法找到任何的源文件。我想这意味着无论是(1)我有错版的摇篮,需要修复它,也许(2)我需要在build.gradle文件中定义的源文件毕竟,即使我还以为是继公约的指导。

Trying to build the project from Android Studio yields the same error as above regarding 1.6 being required. I tried reimporting the project, though it said it could not find any source files. I guess this means either (1) I have the wrong version of gradle and need to fix it and maybe (2) I'll need to define source files in the build.gradle file after all, even though I thought I was following the conventions from the guide.

我试图复制摇篮 - 包装 - 1.6.jar 来代替摇篮/封装/摇篮 - wrapper.jar 但是这只是给了一个类或方法未找到错误,当我通过跑了 ./ gradlew干净

I tried copying gradle-wrapper-1.6.jar to replace gradle/wrapper/gradle-wrapper.jar but that just gave a class or method not found error when I ran it via ./gradlew clean.

尝试性解决方案:在摇篮/封装/ gradle-wrapper.properties 有一行 distributionUrl = 和我改变了这种指向1.6版本,

Attempted solution: In gradle/wrapper/gradle-wrapper.properties there is a line distributionUrl= and I changed this to point to the 1.6 version,

distributionUrl=http\://services.gradle.org/distributions/gradle-1.6-bin.zip

那么下一次我跑 ./ gradlew干净它下载的摇篮中的新版本到我的主目录〜/ .gradle (它到现在为止我并没有意识到存在的),现在当我键入 ./ gradlew --version 它说,它是1.6,和一切使用通过命令行构建 ./ gradlew清洁和放大器;&安培; ./gradlew构建,造成的apk。因此,似乎在命令行工作,但我也希望这从IDE工作

Then the next time I ran ./gradlew clean it downloaded a new version of of gradle into my home directory ~/.gradle (which up until now I didn't realize existed) and now when I type ./gradlew --version it says it is on 1.6, and everything builds via the command line using ./gradlew clean && ./gradlew build, resulting in apks. So it seems to work from the command line, but I also want this to work from the IDE

在IDE中,现在说

Project is using an old version of the Android Gradle plug-in. The minimum supported version is 0.5.0

所以,我更新了 build.gradle 文件说

classpath 'com.android.tools.build:gradle:0.5'

和重新打开IDE,它告诉我,

And reopen the IDE, which tells me,

Could not find com.android.tools.build:gradle:0.5.

是Android的工作室摇篮插件和摇篮版本捆绑在一起?如果是的话我该怎么想,摇篮插件0.4 + 1.6摇篮或摇篮插件.5摇篮1.7?我如何正确地安装这些?

Are Android Studio gradle plugin and gradle versions tied together? If so what do I want, gradle plugin .4 + gradle 1.6 or gradle plugin .5 and gradle 1.7? And how do I properly install these?

更新4

我终于得到这个同时通过在命令行中的的IDE来编译。诀窍是已经创造了基本摇篮文件后导入使用摇篮项目。由于阮经天!在导入项目过程中出现的,你选择或者导入项目从外部模型,从现有来源创建项目的一个步骤。我一直在选择前时,我应该已经选择了后者,拿起摇篮。从那以后,我选择了使用摇篮 - 包装(推荐),并选中使用自动导入并单击Finish(完成)。它提醒我,有两件事情我必须改变,比如采用了最新的摇篮插件,为此,我做了这个变化,我的 build.gradle 文件,

I finally got this to compile via both the command line and the IDE. The trick was to import the project using Gradle after having created the basic Gradle files. Thanks Ethan! During the Import Project process there's a step where you choose "Create project from existing sources" or "Import project from external model". I'd been choosing the former when I should've chosen the latter and picked Gradle. After that I selected "use gradle-wrapper (recommended)" and checked "use auto-import" and clicked Finish. It warned me about a couple things I had to change, such as using the latest gradle plugin, for which I made this change in my build.gradle file,

classpath 'com.android.tools.build:gradle:0.5.+'

这是建议的已知问题对于Android摇篮插件。

which is suggested in the known issues for the android gradle plugin.

推荐答案

看起来你缺少你从项目的根目录settings.gradle文件。

It looks like you are missing your settings.gradle file from the project root directory.

您将需要的settings.gradle文件来访问位于源回购内部的子项目。

You are going to need the settings.gradle file to access the subproject that is located inside your source repo.

在导入项目一定要选择摇篮为源!

When you import the project be sure to select Gradle as the source!

这篇关于Android的工作室瓦特/摇篮:包r不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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