Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change package name in flutter?

Is there any way to change Package Name of Flutter project?

I want to change package name and application name in flutter project.

like image 445
Abc Xyz Avatar asked Jul 26 '18 08:07

Abc Xyz


People also ask

Can we change package name of an app?

Select Refactor. Click on Rename. In the Pop-up dialog, click on Rename Package instead of Rename Directory. Enter the new name and hit Refactor.


2 Answers

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 
like image 141
diegoveloper Avatar answered Sep 21 '22 06:09

diegoveloper


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 
like image 33
Vicky Salunkhe Avatar answered Sep 21 '22 06:09

Vicky Salunkhe