Starting a new react-native project, the xcode-project gots the bundle-identifier "org.reactjs.native.example.XYZApp". XYZ is the placeholder here for my real project name.
Is there any way to change this bundle identifier on react-native side? Sure, I can change it in XCode. But this is not safe because it can be overriden when react-native will recreate the xcode-project, which could happen at any time, as well es when rebuilding the project.
Based on the react-native version you are using there are bunch of files that have to be changed on both platforms (android and ios)
List of files to edit:
IOS
[application_build_scheem].plist (this is a dict/xml file that contains keys that are used by default if no changes added to project (react-native-cli init type of project)
ANDROID
strings.xml (change app_name key value)
manifest.xml (change package attribute)
build.gradle (change applicationId value)
MainActivity.java (change java class package)
MainApplication.java (change java class package)
It's worth mentioning that there is an an npm module (https://www.npmjs.com/package/react-native-ci-tools) that does all of the above; use it and make life easy.
Update (6/Mar/2019)
Update Folder Paths:
We also need to change the folder paths to match new name -- change com.oldName to com.newname.mobile, then change folder paths from app/src/java/com/oldName/ to app/src/java/com/newname/mobile/.
For those who want a simple way to do exactly this I create react-native-app-id, It'll basically edit the files mentioned. react-native-ci-tools actually forked my code to produce a now outdated react-native-app-id-fixed , which won't work with the latest react native. Mine however will..
https://github.com/kyle-ssg/react-native-app-id
usage is as easy as react-native-app-id com.foo.bar
Edit : Deprecated in favour of https://github.com/junedomingo/react-native-rename
To update iOS bundle id -
From terminal or command prompt navigate to react-native project folder and then go inside iOS folder.
enter command Open ProjectName.xcodeproj
This command will open the project in Xcode where you need to update bundle identifier information of the app
To update android package name follow below steps -
Update folder structure inside “android/app/src/main/java/” folder
based on your new package name e.g "com/companyName/appName"
Update package name inside MainActivity.java file
Update package name inside MainApplication.java file
Update package name inside /android/app/src/main/AndroidManifest.xml
file
Update package name inside /android/app/BUCK file
Update package name inside /android/app/build.gradle file
Here's my solution without adding some external packages.
Just run npx react-native-rename <newName> -b <bundleIdentifier> inside your project root directory.
https://github.com/junedomingo/react-native-rename
Edit the PRODUCT_BUNDLE_IDENTIFIER associated with the project in ios/project.pbxproj. It is much safer to use XCode.
I know that the question asked to do it without XCode, for people keen on using Xcode, when inside your react native project:
xed ios Open the ios folder in xcode
Click the top left icon (project navigator)
Click the root item in the left panel ProjectName
In the center view, click General
Under identity, change the Bundle identifier
I have a more lowkey solution that I have been using. This is not a replacement for the above solutions, but simply, one more way to do it. I have only tested this on iOS but I assume it would work for Android as well.
I noticed that in most cases, the project created would have a com.xyz.something which is something like this.
org.reactjs.native.example.abcyourprojectname-extras
I realised, instead of checking each and every folder (and not having to use Xcode), I simply do a search for (in Visual Studio Code, with the project folder open)
org.reactjs.native.example
This would list all the files with the bundle identifier. Just change it your preferred bundle identifier, and thats about it. This way, even if tomorrow, there are any file changes or format changes or whatever, searching will still be consistent way of doing things.
(again, this is a low key solution, but it seems to work for me)
If you want to change bundle identifier in react-native project. You must have to change app identifier separately for both side android and ios.
ios
Select root project in xcode, select General tab, You can see Bundle
identifier into identity section and change your new bundle identifier
for ios application
android
Goto your AndroidManifest.xml.
Just place your cursor in the package name, don't select it just place it.
Then press shift+F6(window)/F6 (mac) you will get a popup window, fill new identifier and select Rename package. It will change
from everywhere in android studio.
Even with react-native-app-id you must move the files to the new folder
I ended using a npm task for upgrading, first upgrade then run the command for rename, move the android files to the correct path and re-link just in case
Unfortunately not. In fact we were just discussing this today in the react Native Facebook group.
https://m.facebook.com/groups/586400221495560?view=permalink&id=738954276240153&comment_id=739065029562411¬if_t=group_comment_reply&ref=m_notif
The best plan right now is to choose the 'd' option when upgrading to verify the files before allowing then to be overridden.
Related
TLDR;
Assets(storyboards, images) not updating unless clean build with Swift package manager local dependency.
Explanation:
I use Swift package manager and have a local dependency (module) that has storyboards, image assets etc. However, if I make any change on them and just cmd+r to run the app, changes are not shown; for example, if I change label text on the storyboard, it won't show the updated text if I just run cmd+r.
To make them appear, I have to clean the build folder and re-run the app again.
But if I change any swift file it works fine.
Try just going to file>Packages>Update Packages To Latest Version
I had a similar behavior with one of my projects. Changes to the storyboard wouldn't be reflected in the simulator if I chose the new build system.
I know that the legacy build system is now deprecated, but you can still try to build with it and see if it is a bug of the new build system.
File > Project settings (or Workspace settings) > Build System > Legacy Build System
Try Updating the packages and also delete your derived Data and archives and give it a go. Seems more of a Xcode bug /cashe issue . Are you using Xcode 13?
It's difficult to find the exact reason because it could depend on several factors. When you open your storyboard file, go to Editor->Automatically Refresh Designable Views and be sure it's checked.
Check also Xcode->Preferences->General->Issues and be sure the check below called "Show Live Issues" is flagged as this picture:
Another reason about your assets refresh failure could depend by the missing resources inside the list: Targets->Build Phases->Copy Bundle Resources
Check also if your resources are shared with a file hosting service like Dropbox, it could be have a local cache which keeps the old version.
When I created my project, I called it "Project1". Then, later I've changed it to "Project2" from the Xcode. I changed all "Project1" to "Project2", but now, when I compile my project, it looks for files in Project2/Project1/myFile.swift and I get the next error:
<unknown>:0: error: no such file or directory: '/Users/myusername/Copy/Projects/Project2/Project1/myFile.swift'
I need to make that it will look at
/Users/myusername/Copy/Projects/Project2/myFile.swift
without Project1 in the path.
How can I solve this problem? Also, I changed from Xcode Identity and Type section Location of my project.
Today I had the same problem when I renamed the folder containing the Xcode project and some parent folders of it.
In my case there where a .swift file shown with it's name in red in the list of files of Xcode (Navigator area). I think that this means that Xcode was not capable to find that file.
I selected that file (actually it's not a real file but a representation of it).
Then, in the File Inspector (Utility area), I clicked on the Folder icon and chose the file on Finder.
This worked for me.
Renaming projects in xcode in one of the most annoying things in iOS development. I assume you want to rename your app. I faced this problem once and figured out a simple, clean way to do it.
Go back to the point where everything worked.
Open project in xcode and click on the project icon in the project structure( first file)
Go to the info tab
Search for Bundle Name. Most probably it will automatically be set to $(PRODUCT_NAME) which is a shell variable that will set your app name the same as the project name.
Set it to whatever you want your app name to be
Done
Note : If you use custom URL Schemes this might produce an error when redirecting.
ALWAYS use git or some other SVN in your projects. This will come in handy in this kind of situations
Change you folder name in you finder "Project1" to "Project2"
Remove "myFile.swift" file from project (copy on Desktop)
Restart Xcode. Copy "myFile.swift" in project select "Copy file to folder" hope this will help.
Okay, here's a little bit of context:
I have just added a Mac OS Core Data Command Line Tool target to my iOS project. It's purpose is to simply use my iOS app's Core Data model and a JSON file (which I am adding default data to as I go) to create an SQLite database which I am going to use as the default database for my iOS app. The idea is to have this command line tool ready in my project so that when I add some default data to my JSON file, I just:
Run the command line tool
Go to products in the file navigator on the left
Control click the command line tool product and hit show in finder
Drag the .sqlite database that has been displayed along with all the other bundled files for my command line tool and drop it into my iOS app's resources
But, I can't do this because the command line tool product is showing red in the navigator window because Xcode is looking for it at this path:
/Users/kylejm/Library/Developer/Xcode/DerivedData/MyiOSApp-ggjlxrqiijmbqkgkucdargamkwld/Build/Products/Debug-iphoneos/
Where as the it is actually in:
/Users/kylejm/Library/Developer/Xcode/DerivedData/MyiOSApp-ggjlxrqiijmbqkgkucdargamkwld/Build/Products/Debug/
I have been inspecting the Build Locations in the Build Settings but all the resolved paths are correct for both my iOS app and the command line tool respectively.
What do I need to do to make Xcode look in the right place?
Thanks so much for any help in advance.
I just clarified my scenario/problem for the answer by bauerMusic like so:
Thanks for your answer but I don't think you quite understand my scenario or problem. The Command Line Tool (CLT) target is a part of my project, and therefore has a executable product in the product folder (shown in red until first build and run). When I run this command line tool, it's product in the products folder remains red because Xcode is looking for the product in the wrong place for it.
I've put it in the description so you all understand my question as clearly as possible.
You usually never add files to a project outside of Xcode, (meaning, simply place it in the folder) unless you want to have these sort of issues.
Try to remove it, restart the project (build and see that it has no broken links warnings), and drag the file to the navigator's folder in your open Xcode project.
Edit: Just to be clear, add through Xcode, not the Finder. Xcode should prompt you to either copy resource or not (check box).
I was going to suggest you Clean the project, but I then noticed how you actually added the file.
I have created a Phone Gap based application on iPhone. After the first run, I have dragged my www folder, containing index.html into the project, but still I am getting the following error in the simulator:
ERROR: Start Page at www/index.html was not found.
Do I have to mention the name of index.html in a plist file or anywhere else? How can I resolve this; can any one help me?
It's an incompatibility between PhoneGap and XCode 4. To resolve:
right click on your project and choose "Add files to [project
name]...";
choose the www folder from your curent project's folder (it's
included in there, but not added as a reference);
when you select the folder, make sure you choose "Copy items into
destination group's folder" as well as "Create folder references for
any added folders".
Note: if you choose "Create groups for any added folders", the app will still fail at runtime.
For those who are as silly as me...
I had forgotten to run cordova build.
Quit XCode and apply below command in terminal, its work for me
ionic cordova prepare ios
Try removing the reference, and adding it again. Did you add it as a "Reference"? The icon should be in blue. Then clean and rebuild.
I had the same problem where it worked in the simulator but not a device. My issue was case sensitivity. My file was Index.html instead of lower case index.html.
You could also just drop the www folder w/Finder into the Xcode Nav tab (root), after that just check dialog checkboxes "Copy items into destination group's folder" and "Create folder references for any added folders".
What versions of Xcode and PhoneGap are you using?
If you're using the older Xcode 3 and are creating a new project using the PhoneGap template... it should automatically create a www folder for you, along with a generic index.html file. If you've dragged your folder and index file into the project, then you should have been overwriting the existing files.
If you're using Xcode 4, there's a known issue with getting a PhoneGap project set up. It would be helpful to know what tutorial/guide you are following (assuming you are using a guide).
In very random cases, changes you make to your files/folders directly (via Finder) might not be picked up immediately by Xcode. You could always try quitting out of Xcode and re-opening your project, to ensure Xcode is pulling the latest files.
Well cordova build ios android was the only thing that worked for me, and cordova build didn't cut it.
in xcode target - Copy Bundle Resource
add www folder
You can fix this issue by adding www to Targets > Build Phases > Copy Bundle Resources
I have a BlackBerry project named "A". This means the build produces artifacts named A.alx, A.cod and all that.
Now I want to change the application name to "B". I tried changing the output file name to "B" and built the project. I get the output B.COD, B.alx etc. But when I try to install B.alx onto the BlackBerry device with the Desktop manager, it does not install, saying "this is not compatible application". This happens even though I can install A.alx successfully.
I made sure I am using 4.7 JDE to install on 4.7 device. I know I am doing something wrong when renaming the application in the project files. What is the problem?
You can't use a dash or space character in an application output filename. Make sure your "B" name does not include one.
edit
If you want to use those characters, edit the application title in the app descriptor. That is what the user sees when your app is installed.
I have encountered the same problem. I think you need to rename your whole project to B so that its output would be B.cod.
Here's some steps for changing project settings within the JDE:
Right click on the project and choose "Properties". A properties dialog will open.
In the "General" tab, you can edit the title of the project (This is what will be displayed on the ribbon), the version and some other stuff.
In the "Build" tab you can change the name of the output files.
Hope this helps.