I just imported a project in my Android Studio. When I tried to refactor the package name, I started facing errors. I am a beginner in Android so just need your help. When I refactored the package name by renaming the first folder after java. It did change the folder name but there were some imports in files of java (generated). Now I am unable to optimize imports in the generated files as it cannot be changed and all the changes are lost.
Asked
Active
Viewed 1,262 times
1
-
you are trying to change the packagename of auto generated java folder, which u dont need to – Wahdat Jan Sep 29 '20 at 11:45
-
I didn't change the package name of the generated java folder. It got changed automatically when I changed the name of the main java folder. – BasitBee Sep 29 '20 at 11:47
-
just close the folder and sync files with gradle – Wahdat Jan Sep 29 '20 at 11:48
-
I tried it. Did not work. – BasitBee Sep 29 '20 at 12:07
3 Answers
1
you are under java (generated) folder ...
those java files should not be edited...
those are generated by compiler....
it is clearly written above it should not be edited
as you said I am trying to refactor the package name
just refer this this
Thanks

Wini
- 1,906
- 1
- 12
- 31
-
@BasitBee you are under java (generated) folder ...those java files should not be edited...those are generated by compiler....it is clearly written above it should not be edited – Wini Sep 30 '20 at 05:42
-
Then how can I optimize the imports? As I am trying to refactor the package name. – BasitBee Sep 30 '20 at 05:44
-
refer this for refactoring --> https://stackoverflow.com/a/29092698/12553303 – Wini Sep 30 '20 at 05:46
-
2Thanks @Wini, your reference helped. The issue is solved by doing "Clean Project" and "Rebuild Project" after refactoring. – BasitBee Sep 30 '20 at 05:58
-1
from Android Studio IDE
file menu -> Invalidate Cache and restart -> Invalidate Cache and restart.
this should solve your errors

Remon Shehatta
- 1,324
- 1
- 10
- 21
-
I tried doing "Invalidate Cache and Restart" but I did not solve the errors. – BasitBee Sep 29 '20 at 12:06
-1
If you are planning to change the name of the package try this answer. what is the purpose to edit a generated file

Sindujan Nirmalan
- 470
- 1
- 8
- 18