I am trying to load custom fonts in my React Native App. However, I am using version 0.69 and I don't know how to add them anymore, because:
link and unlink commands have been removed in the favour of autolinking
Removed assets and hooks from react-native.config.js – you'll need to remove these properties from your config
So how can this now be done in Android and iOS now?
You can add your font files to the project's main assets folder, it should automatically link for you but you should still run the following command from your terminal: npx react-native-asset.
Afterwards, you would be able to use your font like normal: fontFamily: 'Awesome-Font'
Related
We were working on a react native project. One of my team members added some native modules on Linux and linked android. By then I am trying to link things in iOS but the build is always failing with this kind of error trace. The Android project is building normally.
I deleted xyz.xcworkspace and Podfile.lock then tried pod install.
Also, I tried to delete my node_modules and then yarn install followed by yarn link.
react-native-cli: 2.0.1
react-native: 0.61.4
yarn 1.19.1
Pod 1.8.4
XCode Version 11.2.1 (11B500)
macOS Catalina 10.15.1 (19B88)
xyz warning
duplicate output file '/Users/user/Library/Developer/Xcode/DerivedData/xyz-hhesslamjsqmbobykhskliclusph/Build/Products/Debug-iphonesimulator/xyz.app/AntDesign.ttf' on task: PhaseScriptExecution [CP] Copy Pods Resources /Users/faisal/Library/Developer/Xcode/DerivedData/xyz-hhesslamjsqmbobykhskliclusph/Build/Intermediates.noindex/xyz.build/Debug-iphonesimulator/xyz.build/Script-47F818C57EEC47EA3303EA1B.sh
xyz workspace errors
Multiple commands produce '/Users/user/Library/Developer/Xcode/DerivedData/xyz-hhesslamjsqmbobykhskliclusph/Build/Products/Debug-iphonesimulator/xyz.app/Zocial.ttf':
1) Target 'xyz' (project 'xyz') has copy command from '/Users/user/Desktop/xyz/native/node_modules/react-native-vector-icons/Fonts/Zocial.ttf' to '/Users/user/Library/Developer/Xcode/DerivedData/xyz-hhesslamjsqmbobykhskliclusph/Build/Products/Debug-iphonesimulator/xyz.app/Zocial.ttf'
2) That command depends on command in Target 'xyz' (project 'xyz'): script phase “[CP] Copy Pods Resources”
There are multiple errors and warnings like this but have same format with different file names.
The problem is you have duplicate resources due to RN auto-linking.
To fix this
Click Your Xcode project Name on project files
Navigate to Build Phases tab
Scroll down to Copy Bundle Resources drop down to expand
Scroll down to Copy Pod Resources and compare the duplicates with the ones on Copy Bundle Resources
Delete the duplicates on Copy Bundle Resources not on Copy Pod Resources
Rebuild your project.
Also refer to this issue
The problem seems to be caused by the new autolinking feature in React Native 0.60 - the line use_native_modules! in ios/Podfile means when you do pod install, any pods found in node_modules are automatically linked. This means that links to all font files are added to [CP] Copy Pods Resources when you do pod install.
Please see this image.
Open Your iOS project in Xcode.
Then follow these steps in the image.
You will see input Files and output files under Copy Pod Resource. Remove the duplicate ones listed here from the above list in Copy Bundle Resources.
Run react-native run-ios
For the xCode 11+ and react-native 0.60+,
The answer is copied from this GitHub issue answer
The problem seems to be caused by the new autolinking feature in
React Native 0.60 - the line use_native_modules! in ios/Podfile
means when you do pod install, any pods found in node_modules are
automatically linked. This means that links to all font files are
added to [CP] Copy Pods Resources when you do pod install.
If you previously installed react-native-vector-icons manually by
adding the font files to Copy Bundle Resources, you then get a
"Multiple commands produce..." fatal build error.
So to fix the problem, just remove the font files from Copy Bundle
Resources, so that they are only in [CP] Copy Pods Resources.
So the official documentation on the repository of the library is outdated and does not mention it. You should follow installation steps up to adding the fonts list to info.plist, and DO NOT create Fonts folder-group and copy-paste the fonts into that folder.
You need to delete this manually from Copy Bundle resource.
Else You need to change build setting to build using legacy build.
You will find the Copy Bundle resource under build phases.
I am able to solve the issue by following this step.
All you have to do is open your project folder -> go to /ios and open file YourProjectName.xcodeproj then follow this https://lifesaver.codes/answer/error-multiple-commands-produce-in-xcode-10, then you just need to delete all fonts there and run npx react-native run-ios
I follow this to install custom in RN.
It works in Android but not in ios.
When running on ios, is shows error with font not found.
How do I make it work for both ios and Android?
Simply create an 'assets' folder in the root of your project (or wherever you want), drop in your font files, and define it in your project's package.json.
"rnpm": {
"assets": ["assets"]
},
Then, run react-native link and besides linking 3rd party modules, it will now also link any fonts you put in there with the respective project files.
from
React Native: Things I wish I knew before starting out.
Whenever I execute phonegap build android/ios, my asset folder is getting reset to sample folder and source code.
Because of this , whatever the code I am copying into the asset/www it is being overwritten by sample codes of phonegap
Does anybody come across this issue.
What could be the reason.?
This is the correct behavior of cordova/phonegap project.
Under yourProjectRoot/platforms/android/assets/www there are the source copied in build phase from the yourProjectRoot/www directory, you must implement your HTML5/js code in this folder, this is the entry point for you source.
I suggest you to take a look here: Build the App before start the development.
Help of PhoneGap build command says:
Builds your application for one or more specified platforms. When no
platforms are specified, all installed platforms will be built.
The build task will first prepare and then compile your application.
If you want more control, you can individually prepare and compile
your application with the commands.
Your platform specific www folder is overwritten because prepare command is fired.
If you preparing your entire project in platform specific folder like ${PROJECT_ROOT}/platforms/android and you want to compile it than you have to run phonegap compile your_platform. It will bypass prepare and go straight to compile.
I'm using a 3rd party library that is for an Android app, but I need to use it in a Cordova plugin (Phonegap) and after I build/run debug running on the device, the logger is throwing an error about not being able to find the .so file. They use this file with JNI. How can I ensure that the files are being added to apk? Their documentation states that the files need to go in the libs directory like:
/libs/armeabi-v7a/<filename>.so
I've added them to this directory and it seems that only jar files are being added to the plugin. How can I get this file to load onto the device when building the plugin? I'm using Android Studio 0.3.6 with Android API level 19. ( I can't change the versions because that's what we currently support in our app)
Android studio opens by default in "Android view" wich can be quite confusing.
To change the view you click on the down arrow at the right of the word android just above your project content. If you switch to the project view, you will see something that will be less confusing for you and where what's displayed matches the file system structure.
Then you can copy your .so files in the libs/something folder (something being the name of the processor architecture).
If you switch back to the android view, you will see the file inside jniLibs.
Please pay attention to that topic How to include *.so library in Android Studio?. You need put the files into "app\src\main\jniLibs". In plugin.xml that looks like
<source-file src="src/android/armeabi-v7a/some_file.so" target-dir="app\src\main\jniLibs\armeabi-v7a" />
I have an existing native Android app to which I'm adding a cordova webview.
This is in the new gradle project format with Intellij.
I've successfully gotten the cordova activity loaded, and opens as expected.
I added the webview by following the cordova docs.
Now I'd like to use some of the plugins available but can't find a way to add them to the project.
Since this isn't a cordova generated project, plugman doesn't work. I've tried copying the JS and Java files for the plugins I'm interested in to my source dir but that results in various errors.
e.g. require is undefined, when this happened, I added requirejs to the webview's index.html
and it moved on to
Uncaught Error: Module name "cordova/exec" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded cordova.js:8
Failed to load resource file:///android_asset/www/scripts/cordova_plugins.js
deviceready has not fired after 5 seconds. cordova.js:1191
Channel not fired: onDOMContentLoaded
How do I get a plugin working with this?
EDIT:
I am manually moving stuff around.
This has to be put into an existing project which uses gradle for building.
Using cordova create generates a project in the old ANT format.
I followed the docs on embedding a WebView in an existing project (see the link above), but it doesn't mention any of the JavaScript files. So I just copied cordova.js from the android platform directory.
Like wise, I download the plugins I wanted, copied their JavaScript files, added the feature to build.xml and copied their Java files to my src directory.
I didn't know about cordova_plugins.js or that cordova prepare generates them.
You have to use Plugman to manage your plugins in the custom built Cordova WebView.
Please remove all your existing plugins and read them using plugman.
plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts
where the <proj> is the folder where you main project is created,
Alternatively you could use --www parameter which allows you to specify where root of web application is stored. Example:
plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts
Plugman reference
EDIT
If you have highly customized project, you could create empty Cordova project where you add
plugins, and copy cordova_plugins.js from this project to assets\www\scripts, Cordova should pickup these files. If you have your plugins JS files not in the assets\www\scripts\plugins\ folder, but instead of that in assets\www\plugins you have to modify content of cordova_plugins.js like that
module.exports = [
.....
{
"file": "../plugins/org.apache.cordova.inappbrowser/www/InAppBrowser.js",
"id": "org.apache.cordova.inappbrowser.InAppBrowser",
"clobbers": [
"window.open"
]
},
...
]
Here is some input on how I came though,
I am in a similar position like the OP, embedding a Cordova Web View in my Native Android Application.
After executing
plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts
What happens is you get a new 'Cordova' folder in your original 'main' Folder, (Where your AndroidManifest.xml is). Besides that, there is the 'src' folder with the code you actually need generated.
What I did, was copying the org folder from src to the 'java' folder. And everything worked.