developer tip

패키지 R이 없습니다.

optionbox 2020. 8. 14. 07:40
반응형

패키지 R이 없습니다.


나는 무서운 패키지 R가 존재하지 않는다는 것을 얻고 있는데 , 그것은 나를 죽이고 있습니다. 코드는 괜찮습니다. 코드를 실행하는 앱이 시장에 나와 있습니다.

이제 간단한 webview응용 프로그램에 영향을 미치고 있습니다. o.0

R.string.app_name내 오류 main.xml이고 string.xml괜찮습니다. 나는 너무 혼란스러워.

이전 버전을 "borrow"일부 코드로 다시 열었고 맨 위에 R. errors.가져 오기 R.android가 추가되는 것을 제외하고는 깨끗하고 아무것도 변경되지 않았습니다 .

Netbeans에로드 했는데도 같은 결과를 얻었습니다. 청소가 작동하지 않습니다. R.java직접 파일을 작성할 수 있습니까 ?

이게 뭐야 R? 아닙니다 R. 대응해야한다R.java


이 문제를 겪은 사람을 위해 네임 스페이스 폴더의 이름을 변경하여 리팩토링했습니다. AndroidManifest도 편집하는 것을 잊었 기 때문에이 오류가 발생했습니다.

이것도 확인하십시오.


간단하게하기 위해서 :

import your.app.package.R;

물론 your.app.package앱 패키지로 대체 합니다.

R 자원 참조를 사용하는 모든 클래스에서 제거 다른 import.R, 즉import android.R;


TL; DR , "패키지 R이 존재하지 않습니다"오류가 발생하면 가능한 이유는 다음과 같습니다.

  • XML 리소스 파일의 일부 오류
    -> XML 오류 수정
  • 현재 패키지가 패키지와 다릅니다 R( packageAndroidManifest.xml의 속성 참조 )
    -> 가져 오기 R클래스 (예 : import com.example.android.R;
    ->) 또는 소스에서 적절한 패키지 (예 : package com.example.android;
    ->)를 사용하거나 적절한 경우 AndroidManifest.xml 패키지 속성을로 변경합니다.<manifest xmlns:android="..." package="com.example.android" ...>
  • 사용 된 RID는 시스템 리소스에서
    가져온 것입니다-> do not import android.R,하지만 문제가되는 ID 앞에를 붙입니다 android.. 예를 들어 ID를 접두사로 지정하는 대신 android.R.layout.simple_list_item_2
    가져올 수 android.R있지만 R더 이상 애플리케이션 클래스를 가져올 수 없으며 애플리케이션 ID를 접두사로 지정해야합니다 com.example.android.R.id.main_menu.

R 클래스는 응용 프로그램의 자원에서 자동으로 생성됩니다. 여기에는 id이러한 리소스에 대한이 포함 <manifest>되어 있으며 해당 AndroidManifest.xml파일 태그에 이름이 지정된 패키지에 포함되어 있습니다.

리소스 XML 파일에 오류가없는 경우 R.java소스는 아래의 패키지 하위 디렉터리에 생성되어 gen/컴파일됩니다.


패키지 R다른 클래스가 있습니다 android. android.R클래스에는 시스템 리소스에 id대한 s 및 기타 값 포함 된 일부 중첩 클래스가 포함 됩니다.


Java에서 클래스를 사용하려면 전체 패키지로 클래스 이름을 지정해야합니다. 예 :

java.util.List<Object> list = new java.util.ArrayList<Object>();

또는 클래스를 가져온 다음 패키지없이 사용

import java.util.List;
import java.util.ArrayList;
List<Object> list = new ArrayList<Object>();

현재 클래스와 사용 된 클래스가 같은 패키지에있는 경우 패키지 이름을 지정하지 않고 클래스를 사용할 수도 있습니다.

package com.example.android;
public class A {
    /* ... */
}
package com.example.android;
public class B {
    public void useA() {
        A a = new A();
    }
}

절대로 R 클래스를 직접 작성하지 마십시오!

파일에 올바른 R 클래스를 가져 왔습니까?

하기

import android.R;

대신에

import com.example.R;

많은 사람들에게 문제인 것 같습니다. 청소 및 구축 후 수업에서 가끔 잘못된 수업을 가져옵니다.


Android 스튜디오에서 개발 중이고 패키지 이름을 리팩터링 한 경우 Android 매니페스트 및 앱 Gradle 파일에서 패키지 이름을 변경해야합니다.

 applicationId "change here your package name"

및 매니페스트 파일

 package="change here your package name"

R.java는 자동 생성 파일이며 xml 파일에 오류가있는 경우 일반적으로 컴파일되지 않습니다.

아니요 자신의 R.java 파일을 작성할 수 없으며 리소스 컴파일러에 의해 생성되어야합니다.

모든 xml 파일에서 오류를 확인하십시오.


The R class is Java code auto-generated from your XML files (UI layout, internationalization strings, etc.) If the code used to be working before (as it seems it is), you need to tell your IDE to regenerate these files somehow:

  • in IntelliJ, select Tools > Android > Generate sources for <project>
  • (If you know the way in another IDE, feel free to edit this answer!)

I suppose it used to work but now it doesn't..

This can happen if you change PACKAGE name inside your MANIFEST file

<manifest
   package="com.example.android...."

If you want to change package name

  1. Change the package name manually in the manifest file.
  2. Click on your R.java class and the press F6. It will allow you to move the class to other package, and all references to that class will be updated.

I just ran into this error while using Bazel to build an Android app:

error: package R does not exist
                + mContext.getString(R.string.common_string),
                                      ^
Target //libraries/common:common_paidRelease failed to build
Use --verbose_failures to see the command lines of failed build steps.

Ensure that your android_library/android_binary is using an AndroidManifest.xml with the correct package= attribute, and if you're using the custom_package attribute on android_library or android_binary, ensure that it is spelled out correctly.


Sample: My package is com.example.mypc.f01, to fix error you add line below to Activity:

import com.example.mypc.f01.R;


Delete import android.R; from all the files.. once clean the the project and build the project.... It will generate


In my case I realized that I was creating multiple packages in the project. Within the Android Manifest I found that the provider name was incorrectly holding the value of MyContentProvider instead of .provider.MyContentProvider. My main package (with the UI) was co.companyname.database.provider instead of co.companyname.database.

Then on the import statements for the affected class I simply right-clicked and asked Android Studio (0.8.6) to optimize my import statements. I also noted that if you search for .R in the AS search bar at the top right corner of the IDE you can find an auto generated R.java file that is part of your package. At this point you don't have to change anything. Studio should fix up the project after you correct the Android Manifest file and rebuild.

One other item is that in one class I was doing making use of the toString().length() to evaluate a string but swapped those out for TextUtils.IsEmpty (stringVal); Can't think of anything else that I did to resolve the issue.

Hope this helps someone.

NB - All of this is with AS 0.8.6

P.S.

R.java is auto-generated so read the header: /* AUTO-GENERATED FILE. DO NOT MODIFY. * * This class was automatically generated by the * aapt tool from the resource data it found. It * should not be modified by hand. */


When I experienced this, I created a new project, and copied the files from my old project to my new one.

  1. Start a new project
  2. Add the old files into the new project (copy and right click on Layout, drawables,com.packagename,...) to paste my old projects files

However, I still had the same problem: R does not exist. Then I realised that I had copied and pasted Manifest from my notepad into Android Studio manifests and I hadn't changed the package name in the manifest file.

Therefore, once I changed the package name in the manifest to the new project name, the new project I'd created worked fine.


What files are you importing into the files getting the R error?

My understanding of the R file are that they are automatically generated reference lists to all attributes within the Android app. Therefore, you can't change it yourself.

Are you using Eclipse to build this project? Were the older projects getting these errors made before updating Eclipse? What are the references that are getting errors?

Check to make sure that you've not imported another R file from other copied code in another app.


I run into this problem every time I switch computers and try to import old projects from files transferred via a USB.

My workaround is to just create a new project and copy (drag) the files into the IDE (currently using Netbeans) and rebuild. This is an annoyance and a bit of a hacky solution, but it fixes the problem.

If this happens to you, worst case is you might have to backup your files, delete the project, and just drag the files in there and recompile. Hopefully it won't come to that but that would be your nuclear option.


You may try

Android Studio top menu > File > Invalidate caches / restart...

Click on invalidate cache / restart button to restart your project

Resolve R.xxxx.xxx again if some of the fragment class R class didn't resolve properly

then rebuild your project

Hope it helps


If you encounter this error in Android Studio:

Check the Gradle module file(s) -> defaultConfig -> applicationId setting.

Check the AndroidManifest.xml -> manifest package tag.

Check the package declarations in all src java files.

Sync, Clean then Rebuild with Gradle.

NEVER build your own R file. R is auto-generated from your source java files and build settings.


I had: "error: package R does not exist" and assumed javac didn't have access to R.java.
So I appended %PROJ_LOC%\gen to sourcepath, and it worked! SOURCEPATH=%PROJ_LOC%\src;%PROJ_LOC%\gen

I'm not using Android Studio or Ant (or XML).


If this error appeared after resolving merge conflicts, simple Build -> Clean project could help.


Just got rid of the error in my project. I had imported a sample project, I had changed the package folders but I had not updated the package in one of the java files.

Most likely cause of this error 'package R does not exist' is that the package name in Java or manifest file is incorrect. Make sure it is correct and in sync and then do a clean build.


Sometimes, it gets solved when you just re-import the project into Android Studio.


Wrong path: Project "cashes" the pointers to the images and if you have made name changes to the path for example Refactored package or folders. Then just simply write the R letter again and the editor suggests the right path and it will work. In this case your filenames are right and the content that is referred in the R. pointer is present but the path is wrong, thus clean and build won't work.


Another case of R. breakage is Annotations Processing.

Some processing could refer to classes located in certain folders or folder levels. If you move required classes to other location, you can get R. as an unknown class.

Unfortunately the error-pointer to this problem is not evident in Android Studio.


No benefit of writing R.java yourself because it is changed on every build,

Just remember to use R.something for example : R.raw.filename from inside classes that has package value similar to the package value inside the AndroidManifest.xml

because R. resources IDs are defined for the current application or library and they are all checked if exist on compile time, so does not make sense to allow them to be accessed from "code" that does not target the current application or library and can be used in other places.


I solve My problem:

package R does not exist

.

Goto AndroidManifest.xml file and changed the minSDKVersion="17" from 19

참고URL : https://stackoverflow.com/questions/12986301/package-r-does-not-exist

반응형