Can't rename resource (layout) files (Android Studio 3.0 Beta 3 is installed)

邮差的信 提交于 2019-12-03 09:27:19

meh, just get rid of the generated files && then refactor.

Gradle --> app --> build --> clean.

I am experiencing the same issue on Android Studio 3.0 Beta 3. I fixed the problem by:

  1. Exiting Android Studio
  2. Navigating to the folder that the layout file is saved in (either CLI or GUI)
  3. Rename the file to whatever you want the refactored file to be called.
  4. Reopen Android Studio.

Obviously this forces you to have to manually refactor the references to the old file, but I tried about a dozen different things (changing R.java permissions, Gradle clean, invalidate cache, etc.) and none of them worked.

Anyone else who has this issue should submit this bug in Android Studio by using Help > Submit Feedback.

Also, is there a chance you might also be using multiple layouts folders like I am?

I've got the same issue. I was solved this with

File --> Invalidate Caches and Restart --> Invalidate and Restart.

And than try to rename again.

Hope this help. Happy coding :)

I was able to work around it temporarily by moving my R.java file into my src directory. For example, if you're package name is com.example.sample, move your R.java file from app/build/generated/source/r/debug/com/example/sample/R.java to app/src/main/java/com/example/sample/R.java. Be sure to delete it when you're finished refactoring, it will be regenerated during the build process.

Cleaning doesn't work for everything. For instance, renaming a view isn't possible because the R.java file is automatically regenerated. I tried disabling Instant Run, but that didn't help either. Eventually I had to rename the view manually in the layout file.

From the comments on the bug ticket at https://issuetracker.google.com/issues/65032914 the fix will be in the beta 5 release of Android Studio.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!