your programing

R을 해결할 수 없음-Android 오류

lovepro 2020. 9. 27. 13:32
반응형

R을 해결할 수 없음-Android 오류


방금 새 Android SDK를 다운로드하여 설치했습니다. 나는 그것을 테스트하기위한 간단한 애플리케이션을 만들고 싶었다.

마법사는 다음 코드를 생성했습니다.

package eu.mauriziopz.gps;

import android.app.Activity;
import android.os.Bundle;

public class ggps extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

하지만 이클립스 는 나에게 오류를 준다

R을 확인할 수 없습니다.

온라인

setContentView(R.layout.main);

왜?

PS : 나는라는 이름의 XML 파일이 할 main.xml아래를 res/layout/.


이 문제도 추적 한 후 Android 문서에서이 메모를 발견했습니다.

http://source.android.com/source/using-eclipse.html

* 참고 : Eclipse는 리소스를 사용하는 파일 맨 위에 "import android.R"문을 추가하는 것을 좋아합니다. 특히 Eclipse에 가져 오기를 정렬하거나 관리하도록 요청할 때 특히 그렇습니다. 이것은 당신의 메이크 가 깨지게 할 것입니다. 이러한 잘못된 import 문을 찾아 삭제하십시오. *

Android 샘플 자습서를 진행하는 동안 종종 Ctrl+ Shift+ O명령을 사용하여 "가져 오기 구성"을 수행하고 누락 된 가져 오기 문을 생성합니다. 때때로 이것은 R.java빌드 할 때 자동으로 생성 되는 클래스를 숨기는 잘못된 import 문을 생성합니다.


R 문제가 생성되지 않거나 사라질 때마다 이는 XML 레이아웃 파일의 문제로 인해 응용 프로그램이 빌드되지 않았기 때문입니다.


당신이 얻을 때마다

R을 확인할 수 없습니다.

그런 다음 /res디렉토리 를 확인하고 일부 오류가있는 파일이 있어야 응용 프로그램을 빌드 할 수 없습니다. 예를 들어, 레이아웃 파일이거나 일부 리소스가 누락 되었기 때문일 수 있지만 이미 XML 파일에 정의했습니다.

파일 명명 규칙을 준수하지 않는 res / drawables-mdpi와 같은 폴더에 사용되지 않은 (!) 또는 참조되지 않은 (!) 이미지가 추가로있는 경우 ([a-z0-9_.] 만 포함 할 수 있음), R.java 클래스가 생성되지 않아 다른 모든 게시물이 참조하는 이벤트 체인이 발생할 수 있습니다. 도움이 되었기를 바랍니다.


내 프로젝트에는 처음에 r.java.가 포함되어 있습니다 .R.layout.main은 잘 작동하지만 일부 코드를 추가하면 작동하지 않으며 오류는 R.layout.main이 해결할 수 없습니다. 문제는 무엇입니까? ?

수입품을보세요. 가능성은 다음과 같습니다.

import android.R;

거기있을 게. 이 경우 프로젝트가 기본 Android 리소스 클래스가 아니라 / res / 폴더에서 자동 생성 된 클래스로 R을 확인하도록 제거합니다.


그리고이 문제를 일으킬 수있는 또 다른 것 :

새 ADT (v. 22)를 설치했습니다. gen을 포함 하는 폴더 생성을 중지했습니다 R.java. 해결책은 Android SDK Manager에서 새로운 Android SDK 빌드 도구도 설치하는 것이 었습니다.

여기 에서 찾은 솔루션


R.javaAndroid Eclipse 플러그인이 애플리케이션을 빌드하는 동안 생성하는 파일입니다. R.java"gen"디렉토리 아래에 생성됩니다. 이 파일은 "res"디렉토리의 정보에서 생성됩니다. Eclipse 메뉴에서 "Project"-> "Clean ..."을 선택하면 R.java파일 이 제거되고 재생성 됩니다.

AndroidManifest.xml파일 에서 패키지 이름을 변경할 때 "R을 해결할 수 없습니다"문제가 발생 합니다. Android 패키지 이름을 사용하여 R.java파일을 저장하는 "gen"디렉토리 아래에 하위 디렉토리를 만듭니다 .

Eclipse는 R.javaAndroid 패키지 이름을 변경했을 때 파일 위치가 혼동되기 때문에 클린 실행에 문제 가있을 수 있습니다. gen새 패키지 이름과 일치하도록 아래의 하위 디렉토리 이름을 바꾸 거나 패키지 이름을 다시 이전 이름으로 변경할 수 있습니다. 정리를 수행 한 다음 패키지 이름을 원하는 새 이름으로 변경합니다. 패키지 이름을 변경하는 동안 Eclipse가 빌드를 시도하지 않도록하는 경우 가장 잘 작동합니다. "프로젝트"메뉴에서 "자동으로 빌드"옵션을 선택 취소하고 "정리 ..."대화 상자에서 "즉시 빌드 시작"여부를 묻는 경우 상자를 선택 취소하여 변경하는 동안 빌드를 시도하지 않습니다. 패키지 이름. 이름을 변경 한 후 "자동으로 빌드"를 다시 켤 수 있습니다.

참고 사용자의 경우 것으로 AndroidManifest.xml파일 패키지 이름이 Java 패키지 이름과 일치하지 않는, Eclipse는 자동으로 추가 끝날 것 "수입 <안드로이드 패키지 이름> .R을;" .javaR에 대한 참조가있는 모든 파일의 행. AndroidManifest.xml패키지 이름 을 변경하면 Eclipse가 이러한 추가 된 가져 오기를 모두 업데이트하지 않는 경우가 있습니다. 이 경우 Eclipse 리팩토링 ( ALT+ Shift+ R)을 사용하여 Java 파일 중 하나의 import 문을 새 AndroidManifest.xml패키지 이름으로 변경하십시오. "자동으로 빌드"를 비활성화 한 상태에서이 작업을 수행하는 것이 가장 좋습니다.


윌의 말이 옳았다

R은 리소스를 식별하는 데 사용되는 상수를 보유하는 자동 생성 클래스입니다. R.java 파일 (1.5 SDK를 사용하는 Eclipse에서 gen / eu.mauriziopz.gps / R.java)이없는 경우 프로젝트를 닫았다가 다시 열거 나> 프로젝트> 모두 빌드로 이동하는 것이 좋습니다. (그리고> Josef에서 권장하는대로 "자동으로 빌드"선택). 새 프로젝트를 만드는 것보다 문제가 해결되지 않으면 문제가 다시 생성되면 여기에 다시 게시하고 더 자세히 설명하겠습니다.

하지만 첫 번째 문제를 일으키는 또 다른 문제가 있음을 알아 냈습니다. SDK 디렉토리의 도구에는 실행할 권한이 없었기 때문에 이클립스에는 존재하지 않는 것 같아서 R.java파일을 빌드하지 않았습니다 .

따라서 권한을 수정하고 "자동으로 빌드"를 선택하면 문제가 해결되었습니다.


R은 리소스를 식별하는 데 사용되는 상수를 보유하는 자동 생성 클래스입니다. R.java 파일 (1.5 SDK를 사용하는 Eclipse의 gen / eu.mauriziopz.gps / R.java)이없는 경우 프로젝트를 닫았다가 다시 열거 나 프로젝트> 모두 빌드로 이동하는 것이 좋습니다. Josef에서 권장하는대로 "자동으로 빌드"를 선택합니다. 새 프로젝트를 만드는 것보다 문제가 해결되지 않으면 여기에 다시 게시하는 것보다 문제가 재현되면 더 자세히 설명하겠습니다.


모든 파일을 닫고 프로젝트를 정리하고 Eclipse를 다시 시작하십시오.


체크인 할 가치가 AndroidManifest.xml있습니다. 속성 package에 올바른 값이 있습니다.

그건:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="your.correct.package.name"
   ...

이를 변경 R.java하면이 다시 생성됩니다.


이 오류는 패키지의 루트 네임 스페이스와 다른 네임 스페이스에 활동을 추가하여 발생할 수도 있습니다.

예를 들어 com.example.myapp패키지의 루트 네임 스페이스 인 경우 네임 스페이스에 활동을 추가 할 수 있습니다 com.example.myapp.activities.

이렇게하면 "R을 확인할 수 없습니다"오류가 발생합니다.

가져 오기를 수정하려면 활동의 기본 네임 스페이스에있는 R은 다음과 같아야합니다.

import com.example.myapp.R;

이전 답변의 훌륭한 제안과 함께 Android 대상이 설정되어 있는지 확인하십시오.

  1. 프로젝트를 마우스 오른쪽 버튼으로 클릭하십시오.
  2. 속성 선택
  3. 왼쪽 메뉴에서 Android를 선택합니다.
  4. 적절한 프로젝트 빌드 대상 옆에있는 상자를 선택합니다.
  5. 적용 및 확인을 클릭하십시오.

편집 : 1 년 후 다른 원인을 찾았습니다. 드로어 블 폴더에 .png 이미지와 이름이 같은 .jpg 이미지가 있습니다. 내 코드에서이 이미지를 참조하면 프로그램이 혼란스러워서 "R을 확인할 수 없습니다"오류가 발생했습니다.


Android 빌드 도구 양식 SDK 관리자를 설치했는지 확인하십시오.

프로젝트 오른쪽 클릭 속성-> Java BuildPath 라이브러리를 선택하고 android-support.jar을 추가하고 다음 단계를 따르십시오.

프로젝트-> 속성-> 자바 빌드 경로로 이동하여 주문 및 내보내기 탭을 선택하십시오. android-support .jar 라이브러리를 확인하고 목록 상단에 설정하십시오. 그리고 청소하고 재건합니다. 대부분의 경우에 작동합니다.

여기에 이미지 설명 입력


저는이 문제를 수백만 번 겪었고 그 원인을 깨달았습니다. 이름에 대문자가 포함 된 XML 파일을 만들었습니다. 의 모든 XML 파일 이름이 /res일치해야합니다 [a-z0-9\\._].


Simplest solution - Sometimes you just need to save the XML file you were working on to get the autogenerator to kick in.

Save the file (e.g. main.xml) then delete the R.java file and see if the regenerated R.java resolves the R resolve problem.


R is a generated class. If you are using the Android Development Tools (ADT) it is generated whenever the project is built. You may have 'Build Automatically' turned off.


Check the XML file names. Be sure that they're all in lowercase.

Also make sure that any image resource names are also all in LOWER CASE. I had a capital letter in the name of my jpg file, and it caused the R unresolved error right across my project.


This error cropped up on my x64 Linux Mint installation. It turned out that the result was a failure in the ADB binary, because the ia32-libs package was not installed. Simply running apt-get install ia32-libs and relaunching Eclipse fixed the error.

If your x64 distro does not have ia32-libs, you'll have to go Multiarch.

Check #4 and #5 on this post: http://crunchbang.org/forums/viewtopic.php?pid=277883#p277883

Hope this helps someone.


You may need to update/install SDK tools. Relaunch Android SDK Manager again and install a new item: Android SDK Build-tools.one by one delete,fix which one work for you.여기에 이미지 설명 입력


You may need to update SDK tools. Relaunch Android SDK Manager again and install a new item: Android SDK Build-tools.

여기에 이미지 설명 입력


I had this problem as well. It turned out that I had inadvertently deleted the "app_name" string resource from the strings.xml file, which was causing a silent error. Once I added it back, the R class was generated successfully and everything was back up and running.


First check is there any error in any xml layout or not, if then resolve it first.

Otherwise remove junit dependency from project and rebuild the project.

여기에 이미지 설명 입력


Try to make your new XML layout file name lower case. For example, use my_file.xml instead of myFile.xml.


Yet another reason R.java might not get autogenerated is if you have directories like res/drawable-hdpi, res/drawable-mdpi, or res/drawable-ldpi.

1.6+ seems to be OK with these directories, but 1.5 doesn't want them. When I removed those directories, R.java started autogenerating for me again.


Just go to Android Top menu list. click on Build Menu, in under Build click on Rebuild Project.

여기에 이미지 설명 입력


I had the examples of Android 8 and was trying to use Android 7 SDK. When I closed the project and reopened the application folder and chose to use Android 8 SDK, it was able to find the R file. Hope this helps.


In my case, I had an error in my AndroidManifest.xml. Others have said that your XML files must be free from errors, but I was only looking in the res/ folder. Find and fix as many possible errors and the problem may well resolve itself.


Often times this is because of the MinSDK version number you supplied when creating the project. Example:

If you want 2.1 to be the minimum, Android 2.1 is actually API Level 7.

You can see what I am talking about when you browse the SDK you downloaded and installed. Navigate to the place you installed the SDK to (C:\android-sdk-windows for example) and open the folder named "platforms". You will see something like "android-7" listed as a folder, and if you open that there is a source.properties file that, when opened with a text editor, will show you the corresponding platform version.

When you create a project, and you must select a "Build Target" API, the last column in that list named "API Level" shows the number you are looking for when populating the MinSDK setting.

This is probably one of the most common mistakes that results in the R.java file not being created under Project > gen > packagename > R.java.


Remove main.out.xml. I'm new to this and don't yet know what this file is used for, but removing it cleared the problem.


Unfortunately none of the existing questions helped. Since my problem seems platform specific, this may only work if you are on Ubuntu 64 Bit (I am currently using Ubuntu 12). At first I did not see the "Problems" Window, which already hinted a solution, that on 64 Bit Environment you need the 32 Bit libs, which may be missing:

sudo apt-get install ia32-libs

I installed the package and rebuild my project, which fixed the issue for me.

참고 URL : https://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error

반응형