How to get bundle id in flutter
Solution 1
You can use get_version package to Get the App ID, Version Name and Version Code on iOS and Android.
Add this dependency to your App and get the app id like this
String projectAppID;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
projectAppID = await GetVersion.appID;
} on PlatformException {
projectAppID = 'Failed to get app ID.';
}
Full example
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_version/get_version.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
String _projectVersion = '';
String _projectCode = '';
String _projectAppID = '';
String _projectName = '';
@override
initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await GetVersion.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
String projectVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
projectVersion = await GetVersion.projectVersion;
} on PlatformException {
projectVersion = 'Failed to get project version.';
}
String projectCode;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
projectCode = await GetVersion.projectCode;
} on PlatformException {
projectCode = 'Failed to get build number.';
}
String projectAppID;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
projectAppID = await GetVersion.appID;
} on PlatformException {
projectAppID = 'Failed to get app ID.';
}
String projectName;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
projectName = await GetVersion.appName;
} on PlatformException {
projectName = 'Failed to get app name.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
_projectVersion = projectVersion;
_projectCode = projectCode;
_projectAppID = projectAppID;
_projectName = projectName;
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Plugin example app'),
),
body: new SingleChildScrollView(
child: new ListBody(
children: <Widget>[
new Container(
height: 10.0,
),
new ListTile(
leading: new Icon(Icons.info),
title: const Text('Name'),
subtitle: new Text(_projectName),
),
new Container(
height: 10.0,
),
new ListTile(
leading: new Icon(Icons.info),
title: const Text('Running on'),
subtitle: new Text(_platformVersion),
),
new Divider(
height: 20.0,
),
new ListTile(
leading: new Icon(Icons.info),
title: const Text('Version Name'),
subtitle: new Text(_projectVersion),
),
new Divider(
height: 20.0,
),
new ListTile(
leading: new Icon(Icons.info),
title: const Text('Version Code'),
subtitle: new Text(_projectCode),
),
new Divider(
height: 20.0,
),
new ListTile(
leading: new Icon(Icons.info),
title: const Text('App ID'),
subtitle: new Text(_projectAppID),
),
],
),
),
),
);
}
}
Solution 2
To find the project name manually, you can look in AndroidManifest.xml or in Info.plist.
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;
See also
Solution 3
In iOS portion of a Flutter project Product Bundle Identifier is in project.pbxproj
file in path:
[your-flutter-project-dir]\ios\Runner.xcodeproj\project.pbxproj
and that is specified as following:
PRODUCT_BUNDLE_IDENTIFIER = com.app.flutter.example;
Note in that this value is same as Android Package Name
in Flutter projects.
Solution 4
If you just need to get the IOS bundle ID manually, here is how
- In Android Studio select the root folder (ex.
flutte_name
) - In the taskbar go to
Tools>>Flutter>>Open IOS Modules in Xcode
- In Xcode open Runner and under
Identity/Bundle Identifier
there is your ID
Solution 5
You probably want to update it to a custom name rather than com.example.appName anyways so you can check out this package called change_app_name on pub.dev here https://pub.dev/packages/change_app_package_name
Super simple I just did it myself. Add the package to your pubspec file and than in a terminal in the root folder type in "flutter pub run change_app_package_name:main com.company.app" change the last part to whatever you want and it will update your whole project with the new name you chose
Vithani Chandresh
Updated on February 03, 2022Comments
-
Vithani Chandresh over 2 years
I used the below method to get the app name and packageName but I need Bundle id for iPhone users. I want to share an app link. I did it in android but on iPhone, I need bundle id.
Future<Null> _initPackageInfo() async { final PackageInfo info = await PackageInfo.fromPlatform(); setState(() { _packageInfo = info; packageName = info.packageName; appName = info.appName; buildNumber = info.buildNumber; }); }
-
Bostrot almost 6 years
info.packageName
should work on iOS. Doesn't it?
-
-
pawan over 2 yearsHow can I get IOS bundle ID if I am using android studio on windows 11?
-
Paul over 2 years@pawan As far as I am concerned Xcode requires a Mac/macOS. If you have windows I would probably go for this answer.
-
Jeff over 2 yearsI think this answer belongs over here:stackoverflow.com/questions/51534616/… instead.
-
Yogi Arif Widodo almost 2 yearsplease more be clear
https://apps.apple.com/app/id$appId
i still only get package name , not the id12312312312 the bundle id -
Yogi Arif Widodo almost 2 yearsthe question looking for bundleID not package name, but i have solved by lookup or get from
iTunes
API. -
Yogi Arif Widodo almost 2 years
-
Suragch almost 2 years@YogiArifWidodo, I wasn't aware of a separate bundle id besides
PRODUCT_BUNDLE_IDENTIFIER
before. That's good that you added a new answer for other people who come here.