[英]Rename Android Studio package error: Not a valid identifier name
Renaming from com.example.test to org.example.test: I have only found examples of changing the example part of this, but I need to change the com one. 从com.example.test重命名为org.example.test:我只找到了更改示例部分的示例 ,但我需要更改com 。
I have tried Refactor then select Rename package, but I get the message Not a valid identifier name when I enter org.example.test. 我已经尝试了Refactor然后选择重命名包,但是当我输入org.example.test时,我收到消息Not a valid identifier name 。
Does anyone know the correct way? 有谁知道正确的方法?
The accepted solution did not work for me. 接受的解决方案对我不起作用。 I had to do the following: 我必须做以下事情:
That's all. 就这样。 It run perfectly after that! 之后它完美运行!
I've had to do the same a few months ago. 几个月前我不得不这样做。 As far as I know, Android Studio does not bound java packages with the app package. 据我所知,Android Studio没有将Java包与app包绑定。 That said, you may have to change your app package (if that's what you want) and your java package. 也就是说,您可能需要更改您的应用程序包(如果这是您想要的)和您的Java包。
First, your Java package 首先,您的Java包
Select the 1. Project tab in Android Studio. 在Android Studio中选择1.项目选项卡。 There's a Settings button. 有一个设置按钮。 Click on it and check Flatten Packages . 单击它并检查展平包 。 Then, select the package you want to rename. 然后,选择要重命名的包。 Press Shift + F6
to rename the whole package. 按Shift + F6
重命名整个包。 If you have more than one package inside com.example.test
, Android Studio will warn you "Multiple directories correspond to package..." and ask if you want to rename package or directory. 如果com.example.test
有多个包,Android Studio会警告您“多个目录对应于包...”并询问您是否要重命名包或目录。 Choose package and it will do its magic. 选择包装,它将发挥其魔力。
Unless you have something else other than test
under com.example
, you're good to go. 除非你在com.example
下test
以外的其他东西,否则你很高兴。
Then, your Android app 然后,你的Android应用程序
For this one, I don't know any shortcuts. 对于这个,我不知道任何捷径。 But if it helps, the app package is mentioned in AndroidManifest.xml
and build.gradle
for your module. 但如果它有帮助, build.gradle
中的AndroidManifest.xml
和build.gradle
会提到应用程序包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.