How to change package name in flutter? How to change package name in flutter? dart dart

How to change package name in flutter?


For Android App Name

Change the label name in your AndroidManifest.xml file:

 <application    android:name="io.flutter.app.FlutterApplication"    android:label="TheNameOfYourApp"   

For Package Name

Change the package name in your AndroidManifest.xml (in 3 of them, folders: main, debug and profile, according what environment you want to deploy) file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="your.package.name">

Also in your build.gradle file inside app folder

defaultConfig {    applicationId "your.package.name"    minSdkVersion 16    targetSdkVersion 27    versionCode 1    versionName "1.0"    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}

Finally, change the package in your MainActivity.java class (if the MainActivity.java is not available, check the MainActivity.kt)

    package your.package.name;    import android.os.Bundle;    import io.flutter.app.FlutterActivity;    import io.flutter.plugins.GeneratedPluginRegistrant;    public class MainActivity extends FlutterActivity {

Change the directory name:

From:

  android\app\src\main\java\com\example\name

To:

  android\app\src\main\java\your\package\name  

EDITED : 27-Dec-18

for package name just change in build build.gradle only

defaultConfig {    applicationId "your.package.name"    minSdkVersion 16    targetSdkVersion 27    versionCode 1    versionName "1.0"    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}

For iOS

Change the bundle identifier from your Info.plist file inside your ios/Runner directory.

<key>CFBundleIdentifier</key><string>com.your.packagename</string>

UPDATE

To avoid renaming the package and bundle identifier, you can start your project using this command in your terminal:

flutter create --org com.yourdomain appname


Changing name manually doesn't seem to work, throws gradle errors, well in my case it does throw error.

So I usually create a new flutter project.

I use below mentioned command to create a new flutter app

flutter create --org com.yourdomain appname

your project will have the package name as -> com.yourdomain.appname


if you just want to keep your package name as com.appname then make some changes as below

flutter create --org com appname

to add java instead of kotlin for android add -a java

flutter create -a java --org com.yourdomain appname

EDIT


If you have already created a project you can use change_app_package_name package to change the package name.

flutter pub run change_app_package_name:main com.package.appname


For those like me that doesn't like to change specific files, I've used https://pub.dev/packages/rename.

Using this, you simply run these commands in your terminal and your app name and identifiers will be changed.pub global run

Installing: pub global activate rename

And then, Run this command inside your flutter project root.

pub global run rename --bundleId com.example.android.app --target android