Changing the project name - flutter

Is it possible changing the project name of a Flutter project? With project name I mean the name you provide when creating a flutter project flutter create name.

That depends on what you are trying to achieve. If you want to change the name of the app which is displayed in the mobile phones menu together with the app icon, you have to change the android:label in the android/app/src/main/AndroidManifest.xml (Code Sample 1) and the CFBundleName in the ios/Runner/Info.plist (Code Sample 2).
Last time I did this it took me ages to find out, why the name of the app was not changed in the list of currently running apps on Android. For that you also need to change the title of your MaterialApp (Code Sample 3).
For renaming it everywhere I would suggest to use search and replace in the project. If you do this, you have to choose a name without spaces or special characters. A project name 'new project' in the pubspec.yaml for example will break the build.
Code Sample 1:
<application
android:name="io.flutter.app.FlutterApplication"
android:label="New Name"
android:icon="#mipmap/ic_launcher">
Code Sample 2:
<key>CFBundleName</key>
<string>New Name</string>
Code Sample 3:
return new MaterialApp(
title: 'New Name'
...);

To change project name , you need to change it for all platforms .
You can use rename package to make it easy .
Run this command inside your flutter project root
flutter pub global run rename --appname "Application Name"
You can also specify the platform you want to apply the change
flutter pub global run rename --appname yourappname -t macOS // support also ios and android
or
Edit AndroidManifest.xml for Android and info.plist for iOS
Do a flutter clean and restart your application if you have a problem.

You can let flutter do this for you:
Using Terminal:
cd /path/to/existing/flutter_project
flutter create --project-name newprojname --org com.yourorgdomain .
Next change the name on line 1 of pubspec.yaml
Trash all generated folders to remove all references of the old project name.
NB - Some import statements will need to have their package references
updated manually to the new name. Review the project structure (in
your IDE) for any references to the old project name inside of IDE
generated files.
Recreate the trashed generated files by using flutter create . (including the space and period at the end) from within the project folder.
Now run flutter clean then debug as normal
Gotchas
You should expect that the project name still resides in all the generated folders for the various environments and in comments/strings. You can use a tool to search all files in the project or folder structure (e.g Cmd + Shift + F in Android Studio or ag {the_silver_searcher in Homebrew}) to find the old name and trash any generated folders including ios, windows, linux. After trashing the generated folders remember to re-create them by running flutter create .

To add to Rainer's answer, you may also have to change the com.example.myprojectname file under android/app/build.gradle
Also for the com.example.myprojectname, do not use underscores (ie:
com.example.my_project_name)
You may also have to find and replace the com.example.myproject name in the files project.pbxproj and MainActivity.java.

If you want to change the project name, simply change it in all these files.
build.gradle (app)
AndroidManifest.xml
MainActivity.java
Rebuild your app and you should be good to go.

1-flutter clean
2- Search and replace all OLD_PROJECT_NAME with NEW_PROJECT_NAME
3- Search for OLD_PROJECT_NAME in the project folder, and replace them with NEW_PROJECT_NAME one by one. Some of them are in the text files, make sure that you have changed them too.

If you are using Android Studio, follow these steps:
Right-click your project in the Project window (Alt+1 to show).
Click Refactor > Rename.
Enter new name.
This will rename the project's name on all required places except in the test directory.

Steps to rename your project: (For Editors that has search & replace across project feature)
Use VSCode's any other editor's search and replaceAll across entire project feature. But always turn on the match cases (for vscode: located on right side).
You have to do this two time as for the first you have to replace com.orgname.currentname with com.orgname.newname then
currentname with newname.
Rename the folders inside /android/app/src/main/kotlin/com/orgname/currentname to new /android/app/src/main/kotlin/com/orgname/newname.
If you're using only Java with flutter than just replace the kotlin with java.
rename the currentname.iml of your root project folder to newname.iml

Ctrl+Shift+R then Replace for one by one replace
or Replace All for all at a time. Be cautious , if your project name is similar with other variable or class name then don't do that. Before doing that check twice.

If you are using Android Studio, from the Menu > Edit > Find > Replace in files > Enter old and new name...

If you want to change the project name, simply change it in all these files.
build.gradle (app)
AndroidManifest.xml
MainActivity.java
Rebuild your app and you should be good to go.

Related

Unable to create desktop application support from existing project in flutter

I am creating a desktop application from an existing app.
The command given in documentation is :
flutter create .
Running this command in the root of the project directory I am getting this error
"MyApp" is not a valid Dart package name.
Note: MyApp is name of my project
Flutter only allows project names that are lower case letters and may contain an underscore or a number. This is actually a convention from dart packages. Check here for the prescribed convention. It is likely that your folder name is used by flutter as its project name. You can try to overcome this by changing the folder name. But please do keep a backup before doing flutter create on an existing project. For more details on possible options check this post as well.
write app name in lowercase
flutter create myapp

I cannot initialize Flutter for web after adding flavors to my project

I have a Flutter project that currently builds for iOS and Android. I created the project around Flutter v1.9 or so. Since creating the project, I have added flavor support to my project (dev, prod) via the guide found here
However, after having done this, it doesn't seem like I am able to add web support to my project. Following Flutter's official instructions to enable web for a pre-existing project, I try to run flutter create . in the root directory of the project. When I do this I get the output:
The Xcode project defines schemes: dev, prod You must specify a --flavor option to select one of the available schemes.
So I try to run: flutter create . --flavor=dev and get Multiple output directories specified. Try moving --flavor=dev to be immediately following create
Soooo, I try: flutter create --flavor=dev . and get Could not find an option named "flavor".
Does anyone know how I can initialize web for this project? Thanks.
You need to do the following:
Goto root folder and rename manually ios folder temporarily to something like ios1
Goto terminal and make sure you are standing in root, then run this line:
flutter create --platforms=web .
Return to project folder and rename back manually ios1 to ios
Done

How to enable Swift support for existing project in flutter

I want to know if there is a way to enable swift support for flutter project. I only enabled Kotlin support while creating the project. I need to enable Swift too. Is there a command I can execute or any setting in flutter plugin for Android studio where I can enable or is there is an option to enable in Xcode?
This is what I want to do but for existing Flutter project
Delete existing ios folder from root of flutter project.
Run this command flutter create -i swift .
This command will create only ios directory with swift support.
Well, I search the same thing now, also I enable the kotlin support...
so, how to enable swift or kotlin support for a existing proyect?
For swift support, you need to move your ios folder to outside of your project folder, for kotlin move outside the android folder, also check your package name in your manifest, or your PRODUCT_BUNDLE_IDENTIFIER
Run the below flutter command in your terminal on root folder of your proyect (I'm using com.custom_name.my_proyect for the package name of this example)
-i swift is for swift
-a kotlin is for kotlin.
--org is to set the first two words of your package, in this case com.custom_name
--project-name is to set the last word of your package in this case my_proyect
You can use only switf/kotlin or both, (Don't forget the period '.' at the end of the command)
flutter create -i swift -a kotlin --org com.custom_name --project-name my_proyect .
*Apply again your previous custom changes on the ios folder (E.g: info.plist, custom splash screen, etc.), now in Runner folder you don't have main.m and AppDelegate.h files, instead you have only the AppDelegate.swift file in swift language, so if you need to put API_KEYs there, the code is different.
*If you apply -a kotlin line, is the same logic that swift in your android folder, so your MainActivy.java file is now a MainActivity.kt file in kotlin language, and you need to apply again your previous custom changes in Android folder (E.g: build.gradle, res folder, android_manifest, etc.).
Little known secret -- you can run flutter create . in your Flutter app directory and it will repair the project, recreating any files that are missing. So if you already have a project created with Objective-C and Java, you can run:
flutter create -i swift -a kotlin .
to convert the host app to Kotlin and Swift.
(Ignore Kotlin you you want, but my experience is that just leave it there)
Bridging Header must be created.
Open the project with XCode. Then choose File -> New -> File -> Swift File.
A dialog will be displayed when creating the swift file(Since this file is deleted, any name can be used.). XCode will ask you if you wish to create Bridging Header, click yes.
Make sure you have use_frameworks! in the Runner block, in ios/Podfile。
Make sure you have SWIFT_VERSION 4.2 selected in you XCode -> Build Settings
Do flutter clean
Go to your ios folder, delete Podfile.lock and Pods folder and then execute pod install --repo-update
For the scenario where you already have an ios module partially written in Objective-C, and now just want to use Swift code alongside, than I suggest you to right click on ios in project window and choose Open iOS module in XCode this from context menu
Than you can just follow those instructions:
https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c
If your plan is to rewrite module in swift than I'd create a new project with the same name as your original one and turned on Swift support. Than I'd just copy the whole ios module to your original project.
First delete AppDelegate.h, AppDelegate.m, main.m files
And also remove main.m from build phases -> compile sources
After that run this command
flutter create -i swift .

Android Studio - Library reference ../google-play-services_lib could not be found importing project

I am trying to import from Eclipse to AndroidStudio a project of mine and I am getting the following error
First I do not understand why it does not replace the google play services lib for the corresponding entry in the gradle file.
What should I do in order to fix the situation? Any guidance or link to a tutorial would be helpful.
Well, there might be another way of solving this problem, but I ended up removing the line in the project.properties file that was making reference to the google-play-services_lib library.
The simplest solutions is remove this line of code , android.library.reference.2=../google-play-services_lib,from project file (you will find it in project's root folder ) rest android studio will handle itself
Find the file:
An alternative is to simply set the path. You'll need to have installed play services via the Android SDK to use it with Android studio anyway.
Once play services are installed, if you highlight the Google play services entry in the Android SDK manager it will show you the path to the install location. On MAC this is normally something like /Users/[homedir]/android-sdks/extras/google/google_play_services/libproject
Edit the path in project.properties to point to this file and it will import. You can then update your gradle build file as necessary.
I think "removing the line in the project.properties file that was making reference to the google-play-services_lib library" is not a good fix.
To really fix it do either of these :
Just edit the location of the path to google-play-services_lib in project.properties file in your Eclipse project root directory.
android.library.reference.1=path/to/the/google-play-services_lib
Note:If you are on windows path\comes\like\this you have to replace the backward slash with the forward slash and your path/will/become/like/this.
e.g :
C:/Users/username/AppData/Local/Android/sdk/extras/google/google_play_services/libproject/google-play-services_lib
or replace "\" with "\" like below :
android.library.reference.1=C:\\Users\\username\\AppData\\Local\\Android\\sdk\\extras\\google\\google_play_services\\libproject\\google-play-services_lib
otherway is - just look at the last portion of the last line of the error
....which resolves to ...folder_name/google-play-services_lib
just create a folder at that location and paste google-play-services_lib from your google_play_services\libproject\google-play-services_lib
I just changed it works for me
android.library.reference.2../google-play-services_lib which changed to
as
android.library.reference.google-play-services_lib
The easiest and simple solution is to copy google-play-services_lib folder from another project or SDK folder and past it to the location which is address in the error. By removing or commenting line in the project.properties will create errors in the project and won't allow you to build unless you take necessary steps and fix.

folder structure in xcode vs folder structure in finder

I have the following folder structure in xcode for a project.
However, I have the above file structure in finder.
Is there any way to reflect the file structure from xcode to finder ?
I recently discovered a Command Line Tool that will do exactly what you need. You can find it here:
https://github.com/venmo/synx
To install the tool, you just need to open the terminal and run the following command (use sudo to run it as a superuser and get permission):
$ sudo gem install synx
Then, just like the instructions on the GitHub webpage above indicate, use the following command to re-organize your folder structure:
$ synx path/to/your/project.xcodeproj
This should do it :).
You should managed it yourself in Finder, then set new Path for folders in Utility View
The "folders" in Xcode are actually groups and not necessarily linked to a folder in Finder.
You need to manage it yourself if you want a mirror in Xcode/Finder.
What you can do is create the folder structure you desire in Finder, then drag each folder into Xcode, this will create references to the folders as groups in Xcode and any files you create in those groups will be saved in the appropriate Finder folders.
You can do this to some extent! There's just one extra step to do every time you create a new group (and this first time you'll have a lot of catching up to do!):
Xcode 3: Whenever you create a group in Xcode, immediately get info on it, and notice the "Path:" setting just below its name. Click "Choose..." and set it to a new folder with the same name.
Xcode 4: Whenever you create a group in Xcode, immediately select it and open the righthand sidebar. Notice the "Path:" setting just below its name. Click the icon next to "None" (what is that, a file in a window?) and set it to a new folder with the same name.
Now, whenever you add files to the group, they'll head to the corresponding folder on disk. Woo!
Hence, I always create folder in Finder and then add that in Xcode.
Check out this article. It might help you organise your project.
http://www.blackdogfoundry.com/blog/xcode4-folder-structure/
After version 9 Xcode (haven't checked previous versions) handles this for you! As long as you create a group and you don't select "New group without folder" Xcode automagically creates a corresponding folder in your project that will be reflected in your project's file structure.