Adit Luhadia
Adit Luhadia

Reputation: 412

How to change company domain name in flutter?

I have made an application using Flutter. However, now I want to change the domain name I initially used while creating the application. How can I do that?

Most of the answers on Stackoverflow explain how to change package name and domain name in normal Android Studio projects (not for Flutter projects).

Upvotes: 6

Views: 8135

Answers (3)

Mahmudur Rahman Shovon
Mahmudur Rahman Shovon

Reputation: 494

I picked to try Casareafer's suggested approach. Here is how I did it my way while my project had firebase as well. That should work for anyone. Make sure you have proper access to the connected firebase account.

  • Delete android and ios directories.

  • Delete pubspec.lock file.

  • Run the following command:

flutter create . --org com.yourdomain --platform ios,android

It will create fresh android and ios directories keeping all the rest same. You're done with your updated domain.

Now you have to restore the services like firebase. Specifically for firebase it's pretty simple. Ensure that you have firebase CLI and flutterfire CLI installed Check the doc

  • Disconnect the flutter app from the existing firebase project from the firebase console > project > project settings > Your apps > delete both android and ios.
  • Run the following command and choose your project. It should automatically connect your project to the firebase.
flutterfire configure
  • Now run the app by
flutter run

If you face any issues try using:

flutter pub cache repair

and then

flutter run

Upvotes: 0

Casareafer
Casareafer

Reputation: 165

To change your domain name and to save some headaches, redo iOS and Android Folders:

If your project doesn't have android or iOS specific files like

GoogleService-Info.plist

or

google-services.json

you could safely delete both ios and android folder from your project root directory, just have in mind all the stuff you'd need to set up later and then run in the project root directory the following command

flutter create . --org com.foo.bar

then it will regenerate both ios and android projects configured with your desired domain(com.foo.bar) and will add your project name after the domain (com.foo.bar.you_project_name); Your build.gradle will look something like this:

 defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.foo.bar.YOUR_PROJECT_NAME"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

If your iOS or Android project contain specific files, you could just back up them, then do the above steps and finally add up the files to the project or generate new files.. I find these steps more convenient and less prune to mistakes than having to search variables in different files within the project and change directory names,

Pros: Faster, Easier than changing names, no need to fix in-code packages imports & folders because they're generated automatically, less prone to make mistakes

Cons: building the projects might use old gradle&kotlin versions so probably you need to update these, need to declare dependencies i.e firebase, need to restore specific files

Upvotes: 2

Igor Kharakhordin
Igor Kharakhordin

Reputation: 9913

For Android project (android folder of Flutter project):

  • Change applicationId in android/app/build.gradle;
  • Change package attribute in manifest tag in android/app/src/XX/AndroidManifest.xml, where XX is a build type (main, debug, profile);
  • Change package name in your MainActivity.java (or .kt) (also rename directory).

For iOS project (ios folder of Flutter project):

  • Change PRODUCT_BUNDLE_IDENTIFIER for 3 buildSettings (debug, release, profile) in ios/Runner.pbxproj (you can open it in xcode or just as text).
  • Change value for key CFBundleName in ios/Runner/Info.plist

Upvotes: 8

Related Questions