Android的工作室不能找到我的资源我的、工作室、资源、Android

2023-09-07 23:10:49 作者:叩首称王

Android的工作室不能编译我的测试项目,因为它无法解析的资源。我试图在gradle.build res目录一些不同的设置,但没有奏效。我失去了一些东西简单吗?这是在它没有单独的一个简单的HelloWorld项目。

我有以下的项目结构,因为它是由Android的工作室向导(最新版本0.2.5)中创建:

在我的Andr​​oidManifest.xml中有平时的应用程序名称参考:@字符串/ APP_NAME此字符串在主/ RES /价值/ strings.xml中(在上面的截图中选择)定义。

我从IDE(Android的一室公寓)得到的错误是:

  Android的易编译:[MyApplicationProject] C:\\ ... \\ MyApplication的\\ SRC \\主\\ AndroidManifest.xml中:6:错误:错误:没有资源发现,给定的名称相匹配(在标签,值为@字符串/ APP_NAME')。 

我在命令行中得到当我运行gradle这个任务的错误是:

  A问题发生配置根项目MyApplicationProject。 >未能通知项目评估监听器。    >主要清单从C丢失:\\ ... \\ MyApplicationProject的\\ src \\ MAIN \\ AndroidManifest.xml中 
Android Studio小技巧之查找资源

解决方案

如果您有在目前的Andr​​oid Studio版本这个问题,或者说在相同的程度(例如:我添加图片到我的绘制文件夹,他们不承认)你的问题可能是我遇到过的。

如果你复制一个项目,你工作后遇到了这个问题,那么这个新项目很可能无法正确​​导入。

我做复制错误并在IDE粘贴该项目,将其重命名(编辑清单),然后试图进行这项工作。这是行不通的,因为新的项目仍在访问原来的res文件夹。

在复制一个项目,以免毁了你原来的你应该:

转到您的Andr​​oid Studio项目文件夹(右键单击在IDE中当前项目,并选择显示在资源管理器。复制粘贴+在同一目录下这个项目;因此重命名文件夹新版本的名称。在IDE转到文件>导入项目> ...并找到您的新项目目录。(继续IDE中的重命名相应的项目。在AndroidManifest.xml更改包名)

这种方式,IDE创建一个新项目,并访问正确的res文件夹(而不是原来的)。

虽然这可能不是解决你们许多人读了这个问题;我碰到这个问题,发现重复项目的正确方法之前,就多次。

我希望这可以节约一些时间。

Android Studio cannot compile my test project, because it cannot resolve the resources. I tried some different settings for the res directory in the gradle.build, but nothing worked. Am I missing something simple here? It's a simple HelloWorld project with nothing individual in it.

I have the following project structure as it was created by the Android Studio wizard (newest release 0.2.5):

In my AndroidManifest.xml there is the usual app name reference: @string/app_name This string is defined in main/res/values/strings.xml (selected in the screenshot above).

The error I get from the IDE (Android Studio) is:

android-apt-compiler: [MyApplicationProject] C:\...\MyApplication\src\main\AndroidManifest.xml:6: error: 
Error: No resource found that matches the given name (at 'label' with value '@string/app_name').

The error I get from the command line when i run "gradle tasks" is:

A problem occurred configuring root project 'MyApplicationProject'.
 > Failed to notify project evaluation listener.
    > Main Manifest missing from C:\...\MyApplicationProject\src\main\AndroidManifest.xml

解决方案

If you are having this problem in current Android Studio version, or something to the same extent (E.g. I added images to my drawable folder, and they were not recognized) your problem may be what I encountered.

If you ran into this problem after duplicating a project you were working on, then this new project was likely not imported correctly.

I made the mistake of copying and pasting the project in the IDE, renaming it (editing manifest), then trying to work on it. This will not work, because the new project is still accessing the original's res folder.

When duplicating a project, so as not to ruin your original you should:

Go to your Android Studio project folder (Right click on your current project in the IDE, and select "Show In Explorer". Copy + Paste this project in the same directory; renaming folder accordingly to new version name. In IDE go to File > Import Project > ... And locate the directory of your new project. (Proceed to rename project in IDE accordingly. Change the package name in AndroidManifest.xml)

This way the IDE creates a new project for it, and it access the correct res folder (not that of the original).

Though this may not be the solution to many of you reading this question; I came across this question many times prior to discovering the proper way to duplicate a project.

I hope this can save someone some time.