1. Renaming methods, many online see
2. For the level of the package name that needs to be re-modified
A. Modify the package names of the packages and gradle, corresponding to the same.
B. Modify the package name R, using Crtl+n to modify the path of the R file
c. Manual first change manifest file error message, and the associated package name path, activity recommends using the local to the path
D. Clean and rebuild projects, at this point if the R reference is still an error, you can replace the method with the global replacement of the old R as the new method.
Reference Document HTTP://BLOG.CSDN.NET/QQ_21445563/ARTICLE/DETAILS/52057189
Today, a friend asked me how to change the app's package name using Android Studio.
His case is that the project was imported from eclipse into as above, do not know for Mao, the original package name is com.xxx.yyy.activity, want to change to COM.AAA.BBB.
Well, actually I did not in as on the package name, so try to play the next, the process a bit of a pit, write a summary of the blog.
With Android Studio's ownRefactor-Rename(重构-重命名)Change package Name
Of course, the first thing to think about is the rename function of as (shortcut key shift+f6 ),
Well, it's easy to use, but found only a single level of the package path at a time? Well, what the hell?
Just like that, you can only change one layer at a time.重命名One floor.
And most importantly, cannot change the hierarchy, that is, the original package name is COM.XXX.YYY, can not be changed to com.xxx or com.xxx.yyy.zzz.
If the target package name is the same as the original package name hierarchy, you can ignore the following. This renaming function of as is very useful.
After the change, by the way GradleapplicationIdThe change is OK.
Another way
If only with the renaming function of as, it is estimated that I can not complete the needs of my friends, after all, to change the level.
It appears that you can only manually change the package name of the manifest file and then change the package name of the R file in the code.
Feel like crazy, after all, in the code, the reference r file frequency is slightly higher, one to change the amount of work is too large.
Remember to try to move the Xxx.java in as, then all files referencing the XXX class will also change the path of the corresponding import package.
So it is not possible to start from the R file, the R file to the new package, using as the powerful refactoring function to automatically change the path of other files referencing R files.
The discovery is indeed feasible.
Here's a quick summary of the steps:
-
Change how the As project structure is displayed, such as;
-
Modify target Moduleandroidmanifest.xml in package , and build.gradle in applicationid ;
-
Locate R file (here with the shortcut key ctrl+n ), in the R file where the 那些个目录 (this does not know how to use the text description, wait to see the picture bar) to create a new package;
-
Move the R file into the new package and follow the prompts to select the refactoring related file.
-
AndroidManifest.xmlSome of the four components of the name properties may use a relative path, this will prompt an error, re-change the path, it is best to change to absolute path.
Above is not what nutrition of the text description, the specific operation or to see the map bar.
Note When moving R files and Refactor other files, as will be stuck for a while, in fact, there is content behind.
That's it, it's actually quite simple.
Notice that the R file is actually in the build folder, that is, the automatically generated file,
So after changing the package name, if the original package of the folder, you can actually do not have to control it, the next time the compilation will automatically disappear.
Android Studio how to modify registration