How to change package name in flutter?

2020-01-29 03:40发布

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

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

10条回答
地球回转人心会变
2楼-- · 2020-01-29 03:49

This is how i renamed package for both ios and android

  1. Go to build.gradle in app module and rename applicationId "com.company.name"
  2. Go to Manifest.xml in app/src/main and rename package="com.company.name" and android:label="App Name"
  3. Go to Manifest.xml in app/src/debug and rename package="com.company.name"
  4. Go to Manifest.xml in app/src/profile and rename package="com.company.name"
  5. Go to app/src/main/kotlin/com/something/something/MainActivity.kt and rename package="com.company.name"
  6. Go to app/src/main/kotlin/ and rename each directory so that the structure looks like app/src/main/kotlin/com/company/name/
  7. Go to pubspec.yaml in your project and change name: something to name: name, example :- if package name is com.abc.xyz the name: xyz
  8. Go to each dart file in lib folder and rename the imports to the modified name.
  9. Open XCode and open the runner file and click on Runner in project explorer.
  10. Go to General -> double click on Bundle Identifier -> rename it to com.company.name
  11. Go to Info.plist click on Bundle name -> rename it to your App Name.
  12. close everything -> go to your flutter project and run this command in terminal flutter clean
查看更多
淡お忘
3楼-- · 2020-01-29 03:56

You can follow this official documentation by Google: https://developer.android.com/studio/build/application-id.html

Application ID should be changed in Build.gradle, while package name can be changed in AndroidManifest.xml.

However one should be careful changing package name.

Also while re uploading the app, one should be careful since it matches the application ID of previously uploaded app with new upload.

查看更多
小情绪 Triste *
4楼-- · 2020-01-29 03:58

I had two manifest.xml file in my app section,so I needed to change package name in bothHere you can see

查看更多
再贱就再见
5楼-- · 2020-01-29 04:00

On Visual Studio code

Edit > Replace in Files

vs code replace in files

On Android studio

1. Right click on your project > Replace in path

replace in path

2. Write your old package and new package > Replace all

replace all screenshot

查看更多
淡お忘
6楼-- · 2020-01-29 04:02

Android

In Android the package name is in the AndroidManifest:

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

iOS

In iOS the package name is the bundle identifier in Info.plist:

<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>

which is found in Runner.xcodeproj/project.pbxproj:

PRODUCT_BUNDLE_IDENTIFIER = com.example.appname;

Changing the name

The package name is found in more than one location, so to change the name you should search the whole project for occurrences of your old project name and change them all.

Android Studio and VS Code:

  • Mac: Command + Shift + F
  • Linux/Windows: Ctrl + Shift + F

Thanks to diegoveloper for help with iOS.

查看更多
孤傲高冷的网名
7楼-- · 2020-01-29 04:02

Updated You have to change the package name to your desired package name in these five location.

1.) src/profile/AndroidManifest.xml
2.) src/debug/AndroidManifest.xml
3.) src/main/AdroidManifest.xml
4.) build.gradle .
       defaultConfig {
           applicationId
5.) MainActivity.java on "package"

last step is to run flutter clean

查看更多
登录 后发表回答