Program Tip

Android-R 클래스를 재생성하는 방법은 무엇입니까?

programtip 2020. 10. 16. 07:57
반응형

Android-R 클래스를 재생성하는 방법은 무엇입니까?


중복 가능성 :
Eclipse에서 Android 용 개발 : R.java가 생성되지 않음

Eclipse IDE로 프로젝트를 가져 왔지만 R 파일이 자동으로 생성되지 않기 때문에 오류가 발생합니다.

내 프로젝트 요구 사항과 일치하도록 R 파일을 편집하려면 어떻게해야합니까?


다른 stackoverflow 질문 에서 누군가 대답했습니다. xml 파일에서 경고와 오류 (구문 및 링크)를 제거해야합니다. 이것과 더불어 클린 / 빌드 프로젝트를 수행합니다.

프로젝트-> 정리를 클릭하고 프로젝트 빌드 옵션을 선택합니다.


나는 이것이 깨진 레이아웃으로 나에게 일어나고 모든 것이 폭발하는 것을 발견했습니다. 진정하세요. 처음 프로그래밍을 배웠을 때 세미콜론 하나를 잊어 버리고 100 개의 오류가 발생하는 오래된 실수와 같습니다. 많은 사람들이 당황하고 모든 버튼을 누르면 상황이 악화됩니다.

해결책

  • R.링크가 끊어지지 않았는지 확인하십시오 . 손상된 경우 ADK가 R을 다시 생성하지 못할 수 있습니다 . XML 파일의 모든 오류를 수정합니다 .
  • 어떻게 든 무언가를 치고 import android.R활동에서 만든 경우 제거하십시오 .
  • 프로젝트 실행 -> 정리 . 그러면 R 및 BuildConfig가 삭제되고 다시 생성됩니다.
  • 프로젝트-> 자동 빌드 가 선택되어 있는지 확인하십시오 .
  • 오류가 사라질 까지 몇 초 정도 기다리십시오 .
  • 작동하지 않으면 / gen / 폴더 안의 모든 항목을 삭제하십시오.
  • 그래도 작동하지 않으면 프로젝트-> Android 도구-> 프로젝트 속성 수정을 마우스 오른쪽 버튼으로 클릭합니다 .

R이 재생성되지 않는 경우 수행 할 작업

이는 일반적으로 xml 파일이 손상되었을 때 발생합니다.

  • 주로 / res / 폴더 내에서 XML 파일 내부의 오류를 확인합니다.
  • 일반적인 장소는 / layout / 및 / values ​​/입니다. 특히 최근에 그중 하나를 변경 한 경우
  • AndroidManifest.xml을 확인하십시오. 자주 문자열을 변경하고 AndroidManifest.xml에서 문자열 이름을 변경하는 것을 잊었습니다.
  • 문제를 찾을 수없는 경우. / gen /-> 로컬 기록에서 복원 ...-> R.java 선택-> 복원을 클릭 합니다. 이것은 문제를 해결하지 못하지만 문제를 더 쉽게 찾을 수 있도록 추가 오류를 제거합니다.

나는 이미 여기에 많은 답변이 있다는 것을 알고 있지만 이것은 Google의 첫 번째 링크이므로 여기에 모든 조언을 컴파일하고 있으며 다른 사람에게 도움이되기를 바랍니다. :)


좋아, 수정했습니다.

매니페스트를 1.5 버전을 대상으로 변경했을 때 백만 개의 오류가 나타나고 하나만 R 클래스의 존재와 관련이 없었습니다. 매니페스트 파일 속성 "targetSdkVersion"및 "maxSdkVersion"이 sdk 1.5에 존재하지 않았습니다.

이 때문에 R 클래스를 생성 할 수 없었습니다.


일부 아이콘과 레이아웃 파일을 추가 한 후 R.java 파일이 재생성되지 않는 비슷한 문제가 발생했습니다. 나는 청소와 재 구축을 시도했지만 원래 R.java 파일이 사라지고 여전히 재생성되지 않은 이후 상황이 악화되었습니다. 결국 R.java를 생성하는 컴파일러에 대한 컴파일러 오류가 있어야하며 콘솔에 표시되지 않는다는 사실이 나에게 떠 올랐습니다. 다행히도 이전에

  1. 하나의 .xml 파일이 존재하지 않는 다른 파일을 참조하는 경우 오류입니다.
  2. 파일 이름에 대문자를 사용하는 것은 오류입니다 (금지 된 이유, I LOVE camel case).

어쨌든 내 아이콘과 .xml 파일의 이름을 모두 소문자로 바꾼 다음 .xml 파일 내의 모든 참조를 수정 한 후 voila, R.java가 재생성되었습니다. 내가 점심을 먹으러 멈췄을 때 기분이 좋아질 때가되었습니다. :-)


R 파일을 다시 생성하려면 다음을 수행하십시오.

  1. layout-> activity_main.xml에서 수정
  2. 파일 저장
  3. 프로젝트-> 청소 ...

gen 디렉토리에있는 R 파일을 삭제 한 다음 Project-> Clean을 시도하십시오. 그런 다음 앱을 다시 빌드하십시오.


를 마우스 오른쪽 버튼으로 클릭 할 수도 있습니다 project -> Android Tools -> Fix Project Properties. 그러면 R.java 클래스가 다시 생성됩니다.


내 문제는 Manifiest 파일에 있습니다. 런처 아이콘을 삭제하고 Manifiest에서 새 아이콘을 참조하지 않았습니다. :)


이클립스를 다시 열고 xml 파일 중 하나를 편집 한 다음 내 activy 클래스가 내 패키지 "R"대신 android.R을 참조하고 있음을 발견했습니다. :-)


R.class를 재생성하려면 여러 기술을 시도해야합니다.

  • Java 소스 파일에서 R 가져 오기를 제거하십시오. import R.android
  • Window-> Show view-> Problems로 이동하여 "Problems"패널을여십시오.
  • xml 리소스에 오류가있는 경우 해당 오류를 수정해야합니다. 제 경우에는 다음과 같이 "+"기호를 포함하도록 ID 속성을 변경해야했습니다.android:id="@+id/grp_txt"
  • 이제 Project-> Clean을 진행하십시오.
  • 마지막으로 프로젝트-> 닫기, 프로젝트-> 열기

"+"기호는 새 리소스 ID를 나타내며 aapt 도구가 R.java 클래스에 새 리소스 정수를 생성하도록합니다.


Intellij IDEA를 사용하는 경우 Build-Rebuild Project를 클릭 할 수 있습니다.


실수로 eclipse에서 "project clean"에 의해 R을 삭제 한 경우 (하지 마십시오) Projectfile을 마우스 오른쪽 버튼으로 클릭-> 로컬 기록에서 복원 ...

당신의 R을 재현

내 경우:

  • 깨진 xml은 R에서 버그를 일으켰습니다. (ä, ö, ü, id의 문자로 인해)
  • 깨끗한 프로젝트가 내 R을 삭제했습니다.

제가 한:

  • 지역 역사에서 재현 된 R
  • 내 클래스에서 잘못된 R 가져 오기 (예 : import android.R)를 확인하고 제거했습니다.
  • fixed that xml file and saved its content in an external txt file
  • deleted the xml completely from my project.
  • ran my project one time
  • put that fixed xml back at its place

and...

  • gave my girlfriend a big hug without a reason after freaking out like a Hulk.

My problem was errors in my XML files. Errors aren't always automatically detected in the Android Common XML Editor or Android Common Manifest Editor, so try using the regular text editor instead. For example, somehow some random gibberish from a .java file had been inserted into my manifest and strings.xml files.

Right click on any XML files (most likely in the /res folder or AndroidManifest.xml) and click "Open With," then select "Text editor." Make sure everything looks good and then save. Also, make sure to enable "Build Automatically" for your project. I had deleted my R.java file and it was rebuilt from scratch, so no need to restore it from local history.


Try to add a new "Android XML file" to, for example, the /res/layout folder. This might cause the plugin to to regenerate the R class.


You can just modify any xml files in /res folder and even just add a space and save, it will be regenerated.


I had the same problem - "R" missing. And none of the advices given here helped. Fortunately, I've found the reason - somehow Eclipse got lost the Project-Properties-target. It was unset. I don't know till now, what had done it, but setting it back helped. So, attention - missing R can mean the missing target, too!


I have tried all the solutions above. But they unfortunately it did not solve my problem. My R.java was gone as soon as I pasted a new picture to my drawable folder. After reading the answers for this question I tried to delete the icon I have previously pasted (while Build Automatically Enabled) and everything was fine afetr. Hope this will help someone!


I had that problem and I just right-clicked on packet of my project and Build Project. Instantly the class R appeared in packet gen.


In case someone else finds this thread when Googling, like I did:

I had what appeared to be the same problem for a while, and after some digging I noticed that the R.java file got correctly built, but was ignored for only one of my source files. The problem for this particular file was that Eclipse had "helpfully" added the following line at the top:

import android.R;

That effectively hides the project R stuff. Just remove it and everything will be fine again...


You can use Eclipse's "Restore from local history" to restore your old R file if it has been deleted. After that you possibly see what keeps Eclipse from building your files (I've seen other errors than before which really helped fixing the problem).


May be you can go to project properties and select Android option and then define the target for the project. Once you apply the selected target API for this project, it will automatically generate R.java.


Mostly a problem with an invalid layout file. Open the 'Problems' view and look for erros in XML layout files. Fix them and the R class will be recreated.

In my case there wasn't a real error. The problem view showed an error in a xml layout. The editor showed the xml error too. Just reformatting the xml using the auto formatter with 'ctrl-f' 'fixed' the xml 'error' and the R class was recreated.


You can just delete the R.java file from your project and it will regenerate assuming you have build automatically enabled. If you do not have build automatically enabled simply goto project->build all


For me, it was a String value Resource not being defined … after I added it by hand to Strings.xml, the R class was automagically regenerated!


This problem normally happens when importing from an existing project. Try to fix all errors from all .xml files in res folder, as well as Manifest file. Most likely the errors are shown at "match_parent" parameter, change it to "fill_parent". When all errors are clear, R.java will be appeared.

If there is no error on any .xml file. Try edit any xml file (like delete a letter and type it back) and then save the file, this will cause to generate the R.java.


I have a problem that the findViewById(R.id.edit_text) but return a TextView not a EditText. I think the problem is the R.id class has wrong id number, then, i clean the project then its works fine.


In my case it was an improperly named XML file that caused my R file not to rebuild. This did not show up in the package explorer, but it was shown in the LogCat. Look out for any warnings there about your res files. No matter how many times you clean your project, the R file will not rebuild until those errors are taken care of.

참고URL : https://stackoverflow.com/questions/2041083/android-how-to-regenerate-r-class

반응형