How to rename an Android project
Sometimes, you have worked a lot on an Android project and realize you need to rename the project. However, you’re not sure how to do that. There are lots of configuration files, .xml files, and gradle files in Android Studio that you’re afraid to break things up. So you end up creating a new Android Studio project, with the correct name, and then pass the source files from the old project to the new one.
Although that brute-force way works, there’s a better way to achieve that. I will outline the steps you need to take. If you follow this steps carefully, it would be like if you hadn’t even renamed the project and had created it with the correct name from the start.
- Rename the root folder where the project is located.
- Open
settings.gradle
and change this line:
rootProject.name = "YOUR NEW PROJECT NAME WITH SPACES"
3. Open app/build.gradle
and change this line:
android {
defaultConfig {
applicationId "com.example.yournewprojectnamewithoutspaces"
}
}
Make sure to not include spaces in here (Java package name don’t support spaces!)
4. Open app/src/main/AndroidManifest.xml
and change the following line:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yournewprojectnamewithoutspaces">
5. Change the package names (names of directories + package
statements in Java) of you app source files. You have to change all package names under the folders main
, androidTest
, and test
.
NOTE: If you are using the default test files included when you create your Android project, go to the ExampleInstrumentedTest.java
file under the androidTest
folder, and change this line inside the useAppContext
test case:
assertEquals("com.example.yournewprojectnamewithoutspaces", appContext.getPackageName())
6. Update app/src/main/res/values/strings.xml
:
<string name="app_name">YOUR PROJECT NAME WITH SPACES</string>
7. If you included native code in your project (in C or C++, under the cpp
folder), you also need to update the signatures of the JNI functions:
extern "C" JNIEXPORT jstring JNICALL Java_com_example_yournewprojectnamewithoutspaces_MainActivity_stringFromJNI(JNIEnv* env, jobject,