I. R file disappearance
1. Background:
Some time ago, when I helped my students modify the XML Code during the android program development process, sometimes the r file was suddenly missing. After some restoration operations failed, I had to recreate a project. Because R files are extremely special in Android projects, I have carried out some small tests.
2. Missing information:
An R file is a file automatically generated by the ADT. It resides in the gen directory and defines a unique ID for each resource, the entire project references related resources through ID identification, so r files are the resource center of our work.
3. Case Analysis:
Due to the special nature of R files, its role is crucial, but it is actually missing !! A non-large factory cannot carry out any "production" because it lacks resources for "import. Who bound our R files? The following possibilities are estimated:
A) The developer accidentally deleted the gen directory;
B) a bug in development tools.
4. Case Reasoning:
A) test environment: Android-1.5
I. Is it the carelessness of developers?
- Create a common project and manually delete the gen directory. An error is reported immediately in the project, but the gen directory is automatically generated in the project directory soon, in addition, you can find the r class file in this directory, and the program runs correctly.
- With the project-> clean function, the reason for this operation is that the R file is synchronized with the resource file to define the resource ID, and this function can clear the operations generated by the development tool itself. Sure enough, the gen directory disappears, but after any file is modified and saved, the gen directory re-appears in the project directory, which is inconsistent with the background description.
- Delete the gen directory in the actual path of the project, and then import the project in eclipse. The error is shown in the right figure. The file is also modified, and the gen directory is returned, it does not match the background description.
- To sum up, we can conclude that the ability of development tools to automatically generate R-class files is so powerful, and I think every android developer should know the importance of R-class files, it will not be so dangerous to operate on it. ^_^ ..
Ii. Is it a bug?
- After the files in the layout folder are intentionally changed to the error reporting State and saved, after the clean operation, the R files will not be restored as long as they remain in the error reporting State.
- I really don't know how to perform more tests on this issue. According to the introduction on the network, a considerable number of people have lost R files, in most cases, because the XML resource file in the resource folder uses escape characters, that is, the development tool may define escape characters but ignore the possibility of using them in strings.
5. Case conclusion:
A) correct all errors.
B) since it may be a bug caused by the escape characters of the development tool, you should pay attention to it when using escape characters. Below are common escape characters.
Escape characters |
Actual symbol |
Name |
& Lt; |
< |
Yu no. |
& Gt; |
> |
Yu no. |
& Amp; |
& |
And |
& Apos; |
' |
Single quotes |
& Quot; |
" |
Double quotation marks |
Note: The semicolon after the escape character cannot be omitted. For more escape characters, refer to network resources.
C) solution:
I. Right-click the project and choose Android tools> fix project properties.
Ii. Right-click the project and choose Properties> Android> select the target and click Apply.
Iii. When the above two methods are invalid, you can check the XML resource files in the res Folder:
(1) XML file names cannot contain uppercase letters.
Ii. Android project error for no reason -- conversion to Dalvik format failed with error 1
Conversion to Dalvik format failed with error 1:
If an android earlier version Project (such as Android 2.1) is placed in a later version environment (such as Android 2.2), the preceding error may occur.
Method (1): android2.1 problem. We recommend that you use version 2.2 or later for Project Creation.
Method (2): Try Project Clean.
Method (3): Modify the SDK version.
If the selected version (such as 2.2) is not successful, you need to re-introduce the jar. Properties-> JAVA build path-> Libraries
-> Add external jars .. -> select the path of Android-8 (corresponding to Android-8 due to Version 2.2) in the Android-SDK during installation. If you forget the path, you can find a project of Version 2.2 In workspace, open its libraries, view the jar storage address under android2.2, and add it as needed.
Appendix on online problem solving:
You can use project ---------> clean to easily solve many problems that occur when developing Android projects in eclipse.
However, if the android library cannot be found, or the Android system library is accidentally removed, how can I re-Add the Android system library?
In Java build path in eclipse, you cannot add a defined system library such as Android 2.1. While I try to manually add
The android. jar in the SDK folder has the conversion to Dalvik format failed with error 1 problem. Tossing
After that, many netizens said that using project clean can solve the problem, but it is useless for me.
Find the solution on Baidu:
Modify the project classpath file.
<! -- Note that the. classpath file is stored in the hard disk of the eclipse workspace in the directory of the project. -->
<Classpathentry kind = "lib" Path = "Custom jar address"/>
Modify
<Classpathentry kind = "con" Path = "com. Android. Ide. Eclipse. ADT. android_framework"/>.
In this way, the project is refreshed, And the Android system library Android 2.1 is back, and the error is also solved.
Bytes --------------------------------------------------------------------------------------------------------------------------
This problem has been encountered in the past few days, but the. classpath file already contains the con path above.
(Http://www.eoeandroid.com/thread-53880-1-1.html) Find the new method on:
Project-> properties-> Android label, check a target from the Project Build target list
<! -- In this case, the error cannot be removed. Note that after you enter project> Properties> Android
A is library item, check it, and click OK to solve the error.
And the subsequent methods cannot be solved. Finally, I can see an is library item. Check it and try again. The error is gone -->
========================================================== ==========================================
Appendix:
Solution to widespread Internet access: conversion to Dalvik format failed with error 1
If an android earlier version Project (such as Android 1.5) is placed in a later version environment (such as Android 2.2), the preceding error may occur. The solution is as follows:
1. If the android SDK version is not modified, use the Project Clean command to act on a project. (This Processing Method
It is only compatible with lower-version projects in the high version and has not been upgraded in the real sense)
2. to modify the android SDK version, perform the following steps:
1) modify the SDK
Select the project, build path --> Configure build path ---> library to delete the referenced low-version SDK,
Add external jars, select SDK of later version, OK, and save
2) modify the classpath File
This file may contain this item: <classpathentry kind = "lib" Path = "Your specified High Version address"
Change her to <classpathentry kind = "con" Path = "com. Android. Ide. Eclipse. ADT. android_framework"/>
3) Modify androidmanifest. xml
In the androidmanifest. xml file, add the <uses-SDK Android: minsdkversion = "3"> </uses-SDK>
4) Modify default. properties (important)
Target = Android-3 in the last line of the file (not used in the previous step), and save it as target = Android-8.
Let's take a look at your project and the new Android 2.2 project structure.