Renaming modules in Android Studio?

前端 未结 9 2515
闹比i
闹比i 2020-12-12 18:05

I picked the wrong name of a specific module which I imported to the Gradle project in Android Studio.

\"\"

9条回答
  •  感情败类
    2020-12-12 18:28

    Different people seem to have success with different methods, but when I wanted to rename my project from:

    com.example.myname.projectname

    to

    com.company.projectname

    I tried everything and the only way I got it to work in the end was:

    1) Exit Android Studio 2) back everything up! (find your project folder and make a copy of it) 3) Find and replace all instances of com.example.myname.projectname with com.company.projectname

    Note that there are five places (actually it probably depends on your project, I had five) where you need to rename folders, as it creates subfolders called com\example\myname\projectname:

    project\app\src\main\java project\app\src\androidTest\java project\app\build\generated\source\buildConfig\debug\ project\app\build\generated\source\buildConfig\test\ project\app\build\generated\source\r\debug\

    Also, in project.idea\ there is a file called workspace.xml - in that file you'll need to find the text com\example\myname\projectname

    Otherwise, do a search through the project directory to find "com.example.myname.projectname" and replace with "com.company.projectname"

    4) Open Android Studio again. if the initial project directory name is the same (possibly if the project name itself is the same?) it will reopen if you had it open last time, otherwise you should be able to open as normal.

    5) Go to File - Project Structure (CONTROL+ALT+SHIFT+S). 6) Under "Flavors", change the application ID to the new name. 7) Excit Android Studio and restart it. 8) Now you should be able to build your project. 9) Go have a drink, that was a lot more effort than it should have been!

    One really important note, you can only have ASCII letters in your package name (you may be able to have numbers, but not as the first character). Java itself allows numbers to start a package name, but Android does not: Package names in Android studio when dev name starts with a number? I was trying to rename

    My workaround (and from a look around the apps on my phone it seems to be what others are doing) is if you wanted a number at the start of either your company name or app name, write the word - instead of com.123company.55project perhaps use com.onetwothreecompany.fiftyfiveproject

提交回复
热议问题