Skip to content

Instantly share code, notes, and snippets.

@gjhuerte
Created November 16, 2018 16:48
Show Gist options
  • Save gjhuerte/f9d262249f03fd645d0a8cff59144d75 to your computer and use it in GitHub Desktop.
Save gjhuerte/f9d262249f03fd645d0a8cff59144d75 to your computer and use it in GitHub Desktop.
android-development-fix
Open development menu: ctr: + m
https://stackoverflow.com/questions/44446523/unable-to-load-script-from-assets-index-android-bundle-on-windows
I've encountered the same issue while following the React Native tutorial (developing on Linux and targeting Android).
This issue helped me resolve the problem in following steps.
(in project directory) mkdir android/app/src/main/assets
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
react-native run-android
You can automate the above steps by placing them in scripts part of package.json like this:
"android-linux": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && react-native run-android"
@gjhuerte
Copy link
Author

gjhuerte commented Nov 17, 2018

Unable to connect with remote debugger

Link here

Solved the issue for me following:

Press Cmd + M on emulator screen
Go to Dev settings > Debug server host & port for device
Set localhost:8081
Rerun the android app: react-native run-android
Debugger is connected now!

@gjhuerte
Copy link
Author

TextInput Typed Text not appearing on android

Stack Overflow

For some reason the height style property needs to be double when on Android than iOS. There might be a cleaner way to do this but here is how we solved this.

<TextInput style={[styles.input, {height: Platform.OS == 'android' ? 40 : 20}]} ... />

Facebook React

Platform module

React Native provides a module that detects the platform in which the app is running. You can use the detection logic to implement platform-specific code. Use this option when only small parts of a component are platform-specific.

import {Platform, StyleSheet} from 'react-native'; 

const styles = StyleSheet.create({
  height: Platform.OS === 'ios' ? 200 : 100,
});

@gjhuerte
Copy link
Author

Warning: Failed child context type: Invalid child context virtualizedCell.cellKey of type number supplied to CellRenderer, expected string.

The value of keyExtractor must be a string。It works well.

failed child context type error

@gjhuerte
Copy link
Author

layoutanimation on android not work

import {UIManager} from 'react-native';

constructor() {
    super();

    if (Platform.OS === 'android') {
      UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true);
    }
  }

link

@gjhuerte
Copy link
Author

firebase.database is not a function

I ran into this with Ionic and it turned out that I wasn't including everything when using the latest Firebase Client. If you've included Firebase as firebase-app, then the Database and Auth pieces need to be required separately since they aren't bundled when including Firebase in this way.

Add the following to your index.html after you include firebase-app.js

<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-database.js"></script>
Obviously you don't need to use the CDN, you could use bower (probably the preferred way with Ionic) or NPM with Browserify.

// Browserify Setup
var firebase = require('firebase/app');
require('firebase/auth');
require('firebase/database');
Snippet below taken from the Firebase Web Setup Docs

You can reduce the amount of code your app uses by just including the features you need. The individually installable components are:

firebase-app - The core firebase client (required).
firebase-auth - Firebase Authentication (optional).
firebase-database - The Firebase Realtime Database (optional).
firebase-storage - Firebase Storage (optional).

From the CDN, include the individual components you need (include firebase-app first)

link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment