All Projects → csath → react-native-config-reader

csath / react-native-config-reader

Licence: MIT license
🛠 Easily access any of the build configs defined in build.gradle or info.plist from your JS code.

Programming Languages

objective c
16641 projects - #2 most used programming language
java
68154 projects - #9 most used programming language
C#
18002 projects
Starlark
911 projects
javascript
184084 projects - #8 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to react-native-config-reader

Asmresolver
A library for editing PE files with full .NET metadata support
Stars: ✭ 267 (+506.82%)
Mutual labels:  native, reader
dotfiles
Linux configuration files (dotfiles) and some useful scripts
Stars: ✭ 22 (-50%)
Mutual labels:  config
sconfig
Scala configuration library supporting HOCON for Scala, Java, Scala.js, and Scala Native
Stars: ✭ 99 (+125%)
Mutual labels:  config
hotstuff
🔥 Composable, incremental, turnkey document compiler
Stars: ✭ 19 (-56.82%)
Mutual labels:  native
v13-Discord-Bot
This is my V13 Discord Bot, it has around 95 commands, 17 events, and stores all kinds of data in an SQL database for ease of access. Not to mention a unique style and friendly help menu interface. Used by over 25 people in popular company based servers, this will bring you a professional look that tops your competition.
Stars: ✭ 38 (-13.64%)
Mutual labels:  config
plaster
Application config settings abstraction layer.
Stars: ✭ 19 (-56.82%)
Mutual labels:  config
ConfigAPI
GSON-like ORM for Bukkit YAML API's
Stars: ✭ 23 (-47.73%)
Mutual labels:  config
rust cms
使用Rust编写一个CMS(内容管理系统)可以做为个人博客,公司网站
Stars: ✭ 32 (-27.27%)
Mutual labels:  config
sitri
Sitri - powerful settings & configs for python
Stars: ✭ 20 (-54.55%)
Mutual labels:  config
binstruct
Golang binary decoder for mapping data into the structure
Stars: ✭ 67 (+52.27%)
Mutual labels:  reader
lwt-node-starter
A simple starter for lwt-node
Stars: ✭ 13 (-70.45%)
Mutual labels:  native
dotfiles
My personal monorepo: dotfiles, /etc-files, single-file scripts, vim plugins, webexts/userscripts, xmonad config, all that stuff…
Stars: ✭ 84 (+90.91%)
Mutual labels:  config
Ichaival
Android client for the LANraragi manga/doujinshi web manager.
Stars: ✭ 89 (+102.27%)
Mutual labels:  reader
prettier-config-solidity
Prettier config optimized to reduce AST churn & conform to solidity spec
Stars: ✭ 28 (-36.36%)
Mutual labels:  config
expenses-native
No description or website provided.
Stars: ✭ 90 (+104.55%)
Mutual labels:  native
dotfiles
My dotfiles based on Makefile
Stars: ✭ 150 (+240.91%)
Mutual labels:  config
dotfiles
My dotfiles (vim/conky/etc.)
Stars: ✭ 79 (+79.55%)
Mutual labels:  config
LANraragi cn
This repo is a fork of Difegue / LANraragi , those things i've done was to translate this repo into chinese ,and fix chrome browser js problem.
Stars: ✭ 147 (+234.09%)
Mutual labels:  reader
crab
Golang API Framework
Stars: ✭ 57 (+29.55%)
Mutual labels:  config
WebAppReader
基于 html5 、 Vue.js 、 Koa、Node.js 以及 EJS 的手机小说阅读器。使用 node.js 模拟后台数据,无实际后台,完全的前后端分离开发。
Stars: ✭ 15 (-65.91%)
Mutual labels:  reader

🛠 react-native-config-reader npm npm

A native library to access all the native code's build configurations from JS.

For [email protected]+ versions use [email protected]+ (autolinking support enabled now).

🚨 Seeking help maintaining react-native-windows compatibility. See below.

Installation

For rn 0.60+ Auto Linking will do things for you.

If not, follow these:

  1. $ npm install react-native-config-reader --save or $ yarn add react-native-config-reader

  2. $ react-native link react-native-config-reader

  3. Go to android/app/src/main/packageName/MainApplication.java and find line

    new RNConfigReaderPackage()

See manual installation below if you have issues with react-native link.

Usage

import RNConfigReader from 'react-native-config-reader';

// access any of the defined config variables in Android build gradle or iOS info.plist
const configValue = RNConfigReader.ANY_DEFINED_CONFIG_FIELD;

More examples

Create new build config field inside android build.gradle file (android/app/build.gradle)

android {

    defaultConfig {
        applicationId "com.react-native.react-native-config-reader"
        versionCode 1
        versionName "1.0"

        buildConfigField "String", "TEST_CONFIG_FIELD", "Hello I'm your test config value"
    }
}

Create new field inside ios info.plist file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">
<dict>
   <key>CFBundleDisplayName</key>
   <string>com.react-native.react-native-config-reader</string>

   <key>TEST_CONFIG_FIELD</key>
   <string>"Hello I'm your test config value"</string>
</dict>
</plist>

Now you can access them inside the JS code:

import { Platform } from 'react-native';
import RNConfigReader from 'react-native-config-reader';

if (Platform.OS === 'ios') {
  const iosBundleDisplayName = RNConfigReader.CFBundleDisplayName;
  const testConfigValue = RNConfigReader.TEST_CONFIG_FIELD;
}

if (Platform.OS === 'android') {
  const androidApplicationID = RNConfigReader.applicationId;
  const testConfigValue = RNConfigReader.TEST_CONFIG_FIELD;
}

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-config-reader and add RNConfigReader.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNConfigReader.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.reactlibrary.RNConfigReaderPackage; to the imports at the top of the file
  • Add new RNConfigReaderPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:

    include ':react-native-config-reader'
    project(':react-native-config-reader').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config-reader/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:

compile project(':react-native-config-reader')

Android advanced configurations with Multiple environments

If your app uses an applicationIdSuffix or a different applicationId depending on the build variants, you must append the following line inside the buildTypes block in your android/app/build.gradle file and specify your new package name.

  resValue "string", "rn_config_reader_custom_package", "com.yourNewPackage"

Example

buildTypes {
  ...
  debug {
    ...
    applicationIdSuffix ".dev"
    resValue "string", "rn_config_reader_custom_package", "com.yourNewPackage"
  }
}

Windows (Beta)

🚨 When this project was first created in early 2019, it offered support for a beta version of React Native for Windows. Since this time, many updates have been published to both react-native and react-native-windows, with no active updates in this project to ensure compatibility.

🙏 If you're interested in using this library with react-native-windows, and can offer assistance maintaining it, please reach out to the maintainers by filing an issue.

  1. In Visual Studio add the RNConfigReader.sln in node_modules/react-native-config-reader/windows/RNConfigReader.sln folder to their solution, reference from their app.

  2. Open up your MainPage.cs app

  • Add using Config.Reader.RNConfigReader; to the usings at the top of the file
  • Add new RNConfigReaderPackage() to the List<IReactPackage> returned by the Packages method

Troubleshooting

Problems with Proguard

When Proguard is enabled (which it is by default for Android release builds), it can rename the BuildConfig Java class in the minification process and prevent react-native-config-reader from referencing it. To avoid this, add an exception to android/app/proguard-rules.pro:

-keep class com.yourNewPackage.BuildConfig { *; }

com.yourNewPackage should match the package value in your app/src/main/AndroidManifest.xml file.

If using Dexguard, the shrinking phase will remove resources it thinks are unused. It is necessary to add an exception to preserve the build config package name.

-keepresources string/rn_config_reader_custom_package

License

MIT License

Copyright (c) 2019 Chanaka Athurugiriya

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].