Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-android-env

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-android-env

React Native bridge to Android build configs set in Gradle

  • 0.0.6
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Fork of depricated react-native-android-config with fix for iOS

the original package had no index.ios.js so iOS was choking.

Usage

Declare config variables in Gradle, under android/app/build.gradle:

android {
    defaultConfig {
      buildConfigField "String",  "API_URL",     '"https://myapi.com"'
      buildConfigField "Boolean", "SHOW_ERRORS", "true"
      ...

Then access those from javascript:

var Config = require('react-native-android-config');
 
Config.API_URL     // "https://myapi.com" 
Config.SHOW_ERRORS // true 

More on Gradle and configs

n case you're wondering how to keep secrets outside your source: create android/config.properties:

API_URL="https://:secret@myapi.com"

Then load it from build.gradle like:

defaultConfig {
    def props = new Properties()
    props.load(new FileInputStream(rootProject.file('config.properties')))
    props.each { key, val -> buildConfigField "String", key, val }
}

You can do something similar under release in buildTypes to read a different set of credentials from another file.

Setup

Include this module in android/settings.gradle:

include ':react-native-android-config'
include ':app'
 
project(':react-native-android-config').projectDir = new File(rootProject.projectDir,
  '../node_modules/react-native-android-config/android')

Add a dependency to your app build in android/app/build.gradle:

dependencies {
    ...
    compile project(':react-native-android-config')
}

Change your main activity to add a new package, in android/app/src/main/.../MainActivity.java:

import com.lugg.ReactConfig.ReactConfigPackage; // add import 
 
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
 
    private ReactInstanceManager mReactInstanceManager;
    private ReactRootView mReactRootView;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mReactRootView = new ReactRootView(this);
 
        // initialize our PhotoRequest handler 
        mPhotoRequest = new ReactPhotoRequestPackage(this);
 
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
                .addPackage(new ReactConfigPackage()) // add the package here 

see react-native-android-config for usage.

Keywords

FAQs

Package last updated on 08 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc