Rename Android App Package Name

broken image


Change App Package Name with single command. It makes the process very easy and fast.

If you rename the package name from manifest file, it will have NO impact on the applicationId even if they have the same name. We can also create multiple APKs through productFlavors like above. Remember, once an app has been published to Google Play. Establish and run Xposed Framework, go to the 'Download' section, find the xRenamer module, go to the download page, download it, install it, and then activate it in the 'Modules' section and reboot the device. In the application list, xRenamer will appear, run it, and rename the applications whose original names do not suit you. Android apps on the play store have a unique package name and iOS apps have bundle identifier that serves the same purpose. Often we create our project with some other package and name and before.

What It does? #

  • [x] Update AndroidManifest.xml files for release, debug & profile
  • [x] Update build.gradle file
  • [x] Update MainActivity file. Both java & kotlin supported.
  • [x] Move MainActivity file to new package directory structure
  • [x] Delete old package name directory structure.

How to Use? #

Add Change App Package Name to your pubspec.yaml in dev_dependencies: section

Update dependencies

Rename android app name

Run this command to change the package name.

Where com.new.package.name is the new package name that you want for your app. replace it with any name you want.

Meta #

Atiq Samtia– @AtiqSamtia – me@atiqsamtia.com

Distributed under the MIT license.

Contributing #

  1. Fork it (https://github.com/atiqsamtia/change_app_package_name/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request
Google is committed to advancing racial equity for Black communities. See how.

Every Android app has a unique application ID that looks like a Java packagename, such as com.example.myapp. This ID uniquely identifies your app on thedevice and in Google Play Store. If you want to upload a new version of yourapp, the application ID (and the certificate you sign itwith) must bethe same as the original APK—if you change the application ID, Google PlayStore treats the APK as a completely different app. So once you publish yourapp, you should never change the application ID.

Your application ID is defined with the applicationId property in yourmodule's build.gradle file, as shown here:

When you create a new project in Android Studio, the applicationId exactlymatches the Java-style package name you chose during setup. However, theapplication ID and package name are independent of each other beyond this point.You can change your code's package name (your code namespace) and it will notaffect the application ID, and vice versa (though, again, you should not changeyour application ID once you publish your app). However, changing the packagename has other consequences you should be aware of, so see the section abouthow to change the package name.

And although the application ID looks like a traditional Java packagename, the naming rules for the application ID are a bit more restrictive:

  • It must have at least two segments (one or more dots).
  • Each segment must start with a letter.
  • All characters must be alphanumeric or an underscore [a-zA-Z0-9_].

Note: The application ID used to be directly tied toyour code's package name; so some Android APIs use the term 'package name' intheir method names and parameter names, but this is actually your applicationID. For example, the Context.getPackageName() method returns your application ID.There's no need to ever share your code's true package name outside yourapp code.

Caution: If you are using WebView,consider using your package name as a prefix in your application ID; otherwiseyou might encounter problems as described in issue211768.

Change the application ID for build variants

When you build an APK for your app, the build tools tag the APK with theapplication ID defined in the defaultConfig block from the build.gradle file(as shown below). However, if you want to create different versions of your appto appear as separate listings on Google Play Store, such as a 'free' and 'pro'version, you need to create separatebuild variants that each have a differentapplication ID.

In this case, each build variant should be defined as a separate productflavor. For each flavorinside the productFlavors block, you can redefine the applicationIdproperty, or you can instead append a segment to the default application IDusing applicationIdSuffix, as shown here:

This way, the application ID for the 'free' product flavor is'com.example.myapp.free'.

You can also use applicationIdSuffix to append a segment based onyour build type, as shown here:

Federal do not detain list. Because Gradle applies the build type configuration after the product flavor,the application ID for the 'free debug' build variant is now'com.example.myapp.free.debug'. This is useful when you want to have both thedebug and the release build on the same device, because no two APKs can have thesame application ID.

Remember that APKs with different application IDs are treated asdifferent apps in Google Play Store. So if you instead want to use the same applisting to distribute multiple APKs that each target a different deviceconfiguration (such as the API level), then you must use the same application IDfor each build variant but give each APK a different versionCode. For moreinformation, read aboutMultiple APK support.

Caution: For compatibility with previous SDK tools, ifyou do not define the applicationId property in yourbuild.gradle file, the build tools use the package name from theAndroidManifest.xml file as the application ID. In that case,refactoring your package name also changes your application ID.

Tip: If you need to reference the application ID in yourmanifest file, you can use the ${applicationId} placeholder in anymanifest attribute. During a build, Gradle replaces this tag with the actualapplication ID. For more information, see Inject Build Variables intothe Manifest.

Change the application ID for testing

By default, the build tools apply an application ID to yourinstrumentation testAPK using the application ID for the given build variant, appended with.test. For example, a test APK for the com.example.myapp.free build varianthas the application ID com.example.myapp.free.test.

Although it shouldn't be necessary, you can change the application ID bydefining the testApplicationId property in your defaultConfig orproductFlavor block.

Note: To avoid name collisions with the app under test, the build tools generatethe R class for your test APK with a namespace based on the testapplication ID, instead of the package name defined in the manifest file.

Change the package name

Although your project's package name matches the application ID by default, youcan change it. However, if you want to change your package name, be aware thatthe package name (as defined by your project directory structure) should alwaysmatch the package attribute in the AndroidManifest.xml file, as shownhere:

The Android build tools use the package attribute for two things:

  • It applies this name as the namespace for your app's generatedR.java class.

    Example: With the above manifest, the R classwill be com.example.myapp.R.

  • It uses it to resolve any relative class names that are declared in themanifest file.

    Example: With the above manifest, an activity declared as is resolved to becom.example.myapp.MainActivity.

As such, the name in the package attribute should always match your project'sbase package name where you keep your activities and other app code. Of course,you can have sub-packages in your project, but then those files mustimport the R.java class using the namespace from the package attribute, andany app components declared in the manifest must add the missing sub-packagenames (or use fully-qualified package names).

Rename Android App Package Name Android Studio

If you want to refactor your package name completely, be sure you update thepackage attribute as well. As long as you use Android Studio's tools to renameand refactor your packages, then these automatically stay in sync. (If theydon't stay in sync, your app code can't resolve the R classbecause it's no longer in the same package, and the manifest won't identify youractivities or other components.)

Android Rename Package

You must always specify the package attribute in your project's mainAndroidManifest.xml file. If you have additional manifest files (such as for aproduct flavor or build type), be aware that the package name supplied by thehighest-priority manifest file is always used in the final merged manifest.For more information, seeMerge multiple manifest files.

One more thing to know: Although you may have a differentname for the manifest package and the GradleapplicationId, the build tools copy the application ID into yourAPK's final manifest file at the end of the build. So if you inspect yourAndroidManifest.xml file after a build, don't be surprised that thepackage attribute has changed. The package attributeis where Google Play Store and the Android platform actually look to identifyyour app; so once the build has made use of the original value (to namespace theR class and resolve manifest class names), it discards that valueand replaces it with the application ID.





broken image