Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all 30345 articles
Browse latest View live

How to dynamically include a module in React Native

$
0
0

I am trying to dynamically do a dynamic import import (this.props.myImportModulePath) but I get :

Error: TrasformError index.js: index.js:Invalid call at line 12: import(_this.props.myImportModulePath), js engine: hermes  

I am not sure that this is the way to go about it, but what I am trying to get is to get import ToastExample from './ToastExample'; dynamically.

Below is how I go about it.

Thank you all in advance.

import React, {Component} from 'react';
import {AppRegistry, Text} from 'react-native';

import {name as appName} from './app.json';

class HelloWorld extends Component {

    constructor(props) {
        super(props);

        this.state = {
            OtherComponent: React.lazy(() => import (this.props.myImportModulePath))
        }
    }

    render() {
        return (
            <Text>HELLO World</Text>
        );
    }
}
AppRegistry.registerComponent(appName, () => HelloWorld);  

Please note that this works when I change

OtherComponent: React.lazy(() => import (this.props.myImportModulePath))

into

OtherComponent: React.lazy(() => import ('./myImportModule')),

that is, passing the path directly as a string './myImportModule' instead of passing it as a prop value this.props.myImportModulePath

Thank you all in advance.


Hi, I am facing this error after running React Native Project, Is there anyone have idea about why this happening often?

$
0
0

Atempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.Resources)' on a null object reference

Expo React-Native: Deep linking is not working on android

$
0
0

Deep linking is not working on android when the app is on background or foreground state, but if it's closed it works perfectly fine. Only in android but in iOS it works both even if it's in background or closed app state.

I have these methods, but it doesn't work on android when it's on background or foreground

1. Linking.addEventListener('url', callback)
2. Linking.getInitialURL -- it returns a Promise that resolves to the url, if there is one.

React Native update version in existing app

$
0
0

I have very large app on play store with very complicated code on React Native and Android. Most android library code is customized as per requirement in this app. Now I want to update my app on play store but for that I need to make my app compatible with 64 bit as Google Play is not accepting my app as per new policies.

I googled it and find that I need to update React Native version to 0.59.0. I just changed React Native version in my package.json file from 0.57.7 to 0.59.8. and added below piece of code in my app level build.gradle file:

ndk {
            abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }

splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

But here after adding above code when I run app its being crash on start with below error message:

java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libreactnativejni.so caused by: couldn't find DSO to load: libglog_init.so caused by: couldn't find DSO to load: libglog.so caused by: couldn't find DSO to load: libgnustl_shared.so caused by: dlopen failed: "/data/data/com.m_naira/lib-main/libgnustl_shared.so" is 32-bit instead of 64-bit
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:703)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:564)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:500)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:455)
        at com.facebook.react.bridge.ReactBridge.staticInit(ReactBridge.java:18)
        at com.facebook.react.bridge.NativeMap.<clinit>(NativeMap.java:19)
        at com.facebook.react.bridge.JSCJavaScriptExecutorFactory.create(JSCJavaScriptExecutorFactory.java:21)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:917)
        at java.lang.Thread.run(Thread.java:764)

Here is a piece of code from my package.json:

"dependencies": {
    "axios": "^0.18.0",
    "moment": "^2.22.2",
    "react": "16.6.3",
    "react-image-mapper": "0.0.14",
    "react-native": "^0.59.8",

    "react-native-animatable": "^1.3.0",
    "react-native-autocomplete-input": "^3.6.0",
    "react-native-camera": "^1.9.2",
    "react-native-contacts": "^2.2.4",
    "react-native-customized-image-picker": "^0.1.4",
    "react-native-datepicker-dialog": "0.0.9",
}

I don't know how to go with react native update process as it is harmful for existing app. Please let me know what is the feasible solution for this. Any help will be appreciated.

How To Enable Proguard with react native?

$
0
0

I want to reduce my APK Size I followed these https://facebook.github.io/react-native/docs/signed-apk-android
and run ./gradlew bundleRelease instead of assembleRelease But I Got Error

Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'. Job failed,

So how can I solve it, I'm Google it but the issue is still! But without Enable Proguard it's work very well and I got (Aab & .Apk ) SO How To Solve it!

I think the issue with this file but I don't know how to configure that!

proguard-rules.pro


# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

Package.json

{
  "name": "APP_NAME",
  "version": "1.12.3",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.4.2",
    "@turf/distance": "^6.0.1",
    "@turf/helpers": "^6.1.4",
    "@turf/invariant": "^6.1.2",
    "@turf/turf": "^5.1.6",
    "firebase-admin": "^8.1.0",
    "firebase-functions": "^3.0.1",
    "lodash": "^4.17.11",
    "moment": "^2.24.0",
    "react": "16.8.6",
    "react-moment": "^0.9.2",
    "react-native": "0.59.8",
    "react-native-app-intro-slider": "^3.0.0",
    "react-native-datepicker": "^1.7.2",
    "react-native-fcm": "^16.2.4",
    "react-native-firebase": "5.3.1",
    "react-native-gesture-handler": "1.2.1",
    "react-native-image-picker": "^0.28.0",
    "react-native-linear-gradient": "^2.5.4",
    "react-native-maps": "^0.24.2",
    "react-native-stars": "^1.1.5",
    "react-native-svg": "^9.3.3",
    "react-native-vector-icons": "^6.4.2",
    "react-navigation": "3.11.0"
  },
  "devDependencies": {
    "@babel/parser": "^7.4.4",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "24.8.0",
    "jest": "24.8.0",
    "metro-react-native-babel-preset": "0.54.1",
    "react-devtools": "^3.6.1",
    "react-test-renderer": "16.8.6"
  },
  "jest": {
    "preset": "react-native"
  }
}

Error when trying to dynamically load a React module

$
0
0

I am trying to dynamically include modules but I keep getting the error :

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `HelloWorld`.

This error is located at:
    in HelloWorld (at renderApplication.js:40)
    in RCTView (at AppContainer.js:101)
    in RCTView (at AppContainer.js:119)
    in AppContainer (at renderApplication.js:39)

This is how I approach it :

index.js

import React from 'react';
import {AppRegistry} from 'react-native';

import {name as appName} from './app.json';

import Components from './ComponentIndex';

class HelloWorld extends React.Component {

    render() {
        const myComponentPath = this.props.myModulePath;
        console.log(">>> Path " + myComponentPath)

        const ComponentToRender = Components[myComponentPath];
        return <ComponentToRender/>
    }
}

AppRegistry.registerComponent(appName, () => HelloWorld);  

ComponentIndex.js

let Components = {};

Components['./MyBaseComponent'] = require('./MyBaseComponent').default;

export default Components  

console.log(">>> Path : " + this.props.myModulePath) prints out the intended passed path, for example ./MyBaseComponent, meaning that it is not empty. The error only comes about whenever I try setting the path from this.props.myModulePath as shown above. It however works fine whenever I set it manually const myComponentPath = "./MyBaseComponent";

What am I doing wrong?

Thank you all in advance.

ScrollView is snapping back?

$
0
0

I am using paging on Scrollview. I have an element which take 1/4th of the screen size. So when the number of elements is greater than 4, scroll sets in. The problem is if the number of elements is in (4n + 1) form i.e 5,9,13... The scrollview snaps back when I take it to last element. It is sort of like this in the gif.

I've tried snapToStart={false} snapToEnd={false}. but it's not working. How to go about this problem

renderSpacesCol () {
   var col = []
   this.state.data.map(something => {
      col.push(
        <Col style={styles.containerColSpaces}>
         <Element data={something.someData}/>
        </Col>
      )
   })
   return col
}

render () {
    return ( 
      <View style={styles.containerScrollViewSpaces}>
        <ScrollView contentContainerStyle={styles.containerScrollView} horizontal={true} pagingEnabled={true} showsHorizontalScrollIndicator={false} snapToStart={false}>
          <Grid>
            <Row style={styles.containerRowSpace}>
            {
              this.renderSpacesCol()
            }
            </Row>
          </Grid>
        </ScrollView>
      </View>
    )
}

const styles = StyleSheet.create({
  containerColSpace: {
    flex: 0,
    width: screenWidth/4,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#FFFFFF',
  },
  containerRowSpace: {
    flex: 0,
    height: 100,
    flexDirection: 'row',
    justifyContent: 'flex-start',
    alignItems: 'center'
  },
containerScrollViewSpaces: {
    flex: 0,
    height: 100,
    justifyContent: 'flex-start',
    alignItems: 'flex-start'
  },
  containerScrollView: {
    flexGrow: 1,
    flexDirection: 'row',
    justifyContent: 'flex-start',
    alignItems: 'flex-start',
  },
})

gif.

How to fix Execution failed for task ':app:processDebugManifest' in React Native?

$
0
0

I find an error when run the project, I try to look for many examples but fail all, this is the detail of error:

D:\myApp\android\app\src\debug\AndroidManifest.xml:22:18-91 Error:
        Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:7:5-117 to override.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.


> Task :app:processDebugManifest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:7:5-117 to override.

Please anyone help me to solve this problem.

Thanks


Project#afterEvaluate(Closure) on project ':app' cannot be executed in the current context. React native

$
0
0

I have tried the existing solutions in SO but nothing works.. Any guess where I am wrong. I just updated the gradle in gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

and here is my android/build.gradle

wrapper {
    gradleVersion = '5.1.1'
    distributionUrl = distributionUrl.replace("bin", "all")
}

My android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext {
    googlePlayServicesVersion = "+"
}
buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
        googlePlayServicesVersion = "15.0.1"
        googlePlayServicesAuthVersion = "15.0.1"
        firebaseVersion = "16.0.4"
    }
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        // classpath 'com.android.tools.build:gradle:3.1.2' // <--- use this version or newer
        classpath 'com.google.gms:google-services:4.2.0' // <--- use this version or newer
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven { url 'https://maven.google.com' }
        maven { url "https://jitpack.io" }
    }
}

subprojects {
  project.configurations.all {
      afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
  }
}

wrapper {
    gradleVersion = '5.1.1'
    distributionUrl = distributionUrl.replace("bin", "all")
}

configurations.all {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-gcm:12.0.1'
   }
}

Android studio gradle file sync

Here I attached through gist since we have character limitation in posting directly.

Gist

How to translate context menu in react native?

$
0
0

I am working on a project that requires to be translated on multiple languages. I am using Zanata to translate everything and it works except context menu. I can not find anything in official documentation how to translate it. Regardless of language that I set on the phone it will always show english language in context menu(copy, select all, paste..)

Example of untranslated context menu

I thought that it will be done automatically by operating system but it is not. Does anyone has the same problem and is there any solution for this?

Thank you.

How to solve the error, Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds` in React native?

$
0
0

I am creating react native app for mobile application. I am fully new in building react native app. I am using ubuntu for creating the app and following below link to create the app. https://facebook.github.io/react-native/docs/getting-started . Can anyone please solve the issue ?

At below stage I am getting error:

cd AwesomeProject
npx react-native run-android

Error in my command line:

All-Series:~/Projects_App/AwesomeProject$ npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
/bin/sh: 1: adb: not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
> Task :app:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
13 actionable tasks: 4 executed, 9 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /usr/lib/jvm/java-8-openjdk-amd64 contains a valid JDK installation.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /usr/lib/jvm/java-8-openjdk-amd64 contains a valid JDK installation.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s

    at checkExecSyncError (child_process.js:621:11)
    at execFileSync (child_process.js:639:15)
    at runOnAllDevices (/home/rupeevest/Projects_App/AwesomeProject/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Dual Sim: Automatic network data change

$
0
0

I've got more of a general question. I did some research but could not find anything that I would consider useful, maybe one of you could point me in the right direction or have some experience with this sort of issue.

I am currently using a dual sim phone(ANDROID), the mobile network is defaulted to SIM1. Is there a way to programatically allow mobile network data to change from SIM1 to SIM2 if the current-use-sim becomes unavailable or goes offline? I seem to have to go into the settings every single time in order to achieve the desired result.

I am currently using react-native and android 9.

Thanks in advance

React-Native-Navigation library missing iOS & android module

$
0
0

Version

 React Native version :  0.61.5
 React-native-cli: 2.0.1

Create new project with below command

npx react-native init AwesomeProject

Run project with below command and run successfully

npx react-native run-ios

When I am trying to add

npm install --save react-native-navigation

I have followed above command for adding react-native-navigation library in my project but when I opened node module folder inside my project but not able to find iOS or android project inside it

Can you please guide me ,

Please check attached image here.enter image description here

changes made in app.js file in react native project are not reflecting

$
0
0

I have created a React Native Project in windows system and able to launch the app on android device using react-native run-android. But when i edit the app.js file, the changes are not reflected in the mobile app. it always showing the below default text. Welcome to React Native! To get started, edit App.js Double tap R on your keyboard to reload,Shake or press menu button for dev menu. How to resolve the above issue.

Choose which android device (emulator or phone) will react-native run-android run on

$
0
0

I am developing a react-native application and every time I want to update the changes to either an actual phone or an emulator, I execute react-native run-android (Sometimes I use the reload functionality in the emulator).

My question is whether there is the possibility to specify in which device/emulator the command will run, since when I have both connected it will run and update the app in the most recently run/plugged.

So I would imagine something like this:

react-native run-android --device=XXXXXX

I have been doing some research and haven't found an answer so far, so I hope someone has a clue about it. Thanks!


React Native - Android: Why are online images (url) not showing only on Android RELEASE build?

$
0
0

I have an application that loads images from url with an https, all images are working fine on iOS, and it also works fine when run through react-native run-android (emulator or actual device). However when I try to run the release version through the apk or through react-native run-android --variant=release, the images doesn't show anymore. Is there any additionaal configuration that needs to be done on Android for it to work on release?

Sample code snippet of Image usage:

<Image source={props.image} style={styles.profile} />

P.S. I am using the latest version of React Native v0.61.5

Here are some sample screenshots:

Android Release Build: enter image description here

Test Build: enter image description here

React-Native Emulator Unable to Load script problem make sure you are either running a metro server

$
0
0

photo 1

photo 2

When I try to use react native via emulator, it errors like in first photo. After I push the button called dismiss second photo appears.

basic react native app not showing any text only white screen with app name on simulator

$
0
0

i am trying to run simple react native app. just text 'Hello World!', it's supposed to be my first app in react native. below is my simple app.js file

    /**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React from 'react';
import {
  SafeAreaView,
  StyleSheet,
  ScrollView,
  View,
  Text,
  StatusBar,
} from 'react-native';

import {
  Header,
  LearnMoreLinks,
  Colors,
  DebugInstructions,
  ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';

const App: () => React$Node = () => {
  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView>
        <ScrollView
          contentInsetAdjustmentBehavior="automatic"
          style={styles.scrollView}>
          <Header />
          {global.HermesInternal == null ? null : (
            <View style={styles.engine}>
              <Text style={styles.footer}>Engine: Hermes</Text>
            </View>
          )}
          <View style={styles.body}>
            <View style={styles.sectionContainer}>
              <Text style={styles.sectionTitle}>Step One</Text>
              <Text style={styles.sectionDescription}>
                Edit <Text style={styles.highlight}>App.js</Text> to change this
                screen and then come back to see your edits.
              </Text>
            </View>
            <View style={styles.sectionContainer}>
              <Text style={styles.sectionTitle}>See Your Changes</Text>
              <Text style={styles.sectionDescription}>
                <ReloadInstructions />
              </Text>
            </View>
            <View style={styles.sectionContainer}>
              <Text style={styles.sectionTitle}>Debug</Text>
              <Text style={styles.sectionDescription}>
                <DebugInstructions />
              </Text>
            </View>
            <View style={styles.sectionContainer}>
              <Text style={styles.sectionTitle}>Learn More</Text>
              <Text style={styles.sectionDescription}>
                Read the docs to discover what to do next:
              </Text>
            </View>
            <LearnMoreLinks />
          </View>
        </ScrollView>
      </SafeAreaView>
    </>
  );
};

const styles = StyleSheet.create({
  scrollView: {
    backgroundColor: Colors.lighter,
  },
  engine: {
    position: 'absolute',
    right: 0,
  },
  body: {
    backgroundColor: Colors.white,
  },
  sectionContainer: {
    marginTop: 32,
    paddingHorizontal: 24,
  },
  sectionTitle: {
    fontSize: 24,
    fontWeight: '600',
    color: Colors.black,
  },
  sectionDescription: {
    marginTop: 8,
    fontSize: 18,
    fontWeight: '400',
    color: Colors.dark,
  },
  highlight: {
    fontWeight: '700',
  },
  footer: {
    color: Colors.dark,
    fontSize: 12,
    fontWeight: '600',
    padding: 4,
    paddingRight: 12,
    textAlign: 'right',
  },
});

export default App;

i started with react-native cli, https://facebook.github.io/react-native/docs/getting-started (React-Native CLI Quickstart) trying to run app on simulator with npx react-native run-ios but i can see only blank screen with app name on it..

enter image description here

..this happened with other basic apps i had created... what wrong or i am missing...

Getting hardware issue Related to android Voice Button after Android update

$
0
0

So this is a new type of issue I am currently facing, Recently I ran an APK of React Native Application I recently built on my system. After running that APK successfully. I started facing some issues regarding my phone's ** sound key **.

I tried restarting the device [Samsung], So it stopped showing the 1st issue. But after a few days a 2nd issue arrives.

1st issue => The volume up button stops working manually and starts increasing the volume automatically.

2n issue => Now whenever I write a new Text Message to someone it automatically starts increasing the font size of the text.

I gave a reboot to the device and even formated it, but nothing helped. I want to know if it's a software side issue or hardware? So that before submitting the device to a Samsung store, If it's a software issue and if I can fix it. It will save me some bucks.

Deploying a react native project using fastlane

$
0
0

I don't usually deploy projects myself, but here I am in this situation where I need to deploy a project built in react native using fastlane.

I am having issue with the line below, any idea what's the --username $DELIVER_USERNAME" should be? is it my appleID or I need to create a fastlane account?

fastlane deliver --verbose --ipa "app.ipa" --skip_screenshots --skip_metadata --username $DELIVER_USERNAME"
Viewing all 30345 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>