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

Cannot set true value for I18nManager.allowRTL

$
0
0

I would like to enable RTL on my iOS project using EXPO.

Then I tried to enable like

I18nManager.allowRTL(true); 

It cannot be set to true.I checked the value by using the following code

console.log('Value is: '+I18nManager.isRTL);//This always retuns FALSE

Please help me how to solve this issue


Is there a way to detect whether the app was opened via push notification? (React-native)

$
0
0

I am building react-native application using OneSignal library. When the app is opened via push notification, I want to make some additional steps before all of the app's logic: I don't want to render initial screen, I want to delay hiding splash screen, etc. That is why I need to detect whether the app was opened via push notification or not. So I could behave in a different ways. Push notification libraries provide callbacks that fire when notifications are opened, but there is no way to detect when they are called: by that time my initial screen can be already rendered, splash screen can be already hidden, etc.

I'm building both iOS and Android apps. I've found a similar question, but it covers only iOS case.

Understanding android DownloadManager (Status Code = 16)

$
0
0

I'm trying to use the library rn-fetch-blob to download a file from a response from my api. I want to use the android download manager so the user can access the file outside of the app.

if (granted === PermissionsAndroid.RESULTS.GRANTED) {   let DownloadDir = fs.dirs.DownloadDir //android only directory   let options = {       fileCache: true,       addAndroidDownloads: {          useDownloadManager: true,          notification: true,          path: DownloadDir +"/"+ name,          description: 'Downloading image.'          }        }        try {             config(options).fetch('POST', `${apiBaseUrl}/document/download/requirement`,             {                Authorization: "Bearer "+ this.props.userDetails.token,'Content-Type': "application/json"             },             data             ).then((res) => {                            console.log("TEST")                            console.log(res);                        }).catch((error) => {                            console.error('Error:', error);                        });                    }         catch (err) {           console.log(err)           }}

When this runs, the response block is being skipped and the line console.error('Error:', error); is returning the following error: 'Error:', { [Error: Download manager failed to download from https://myurl.com/api/document/download. Status Code = 16]

When I comment out the line useDownloadManager, I get a successful response from the api, so I know that's working. I believe a status code 16 refers to a problem with the android file path, but after hours of research I'm unable to determine what could be wrong in regard to that.

React Native - TypeError: null is not an object (evaluating' t.preventAutoHide')

$
0
0

I have a problem exporting my application written in React Native to a working apk file.I use gradlew assembleDebug for export, the command itself works and the apk is created in the folder android \ app \ build \ outputs \ apk \ debug but after installation on the phone / emulator there is an error as in the screenshot

screenshot with error

the application launched in yarn start (expo) works without errors

Versions of my packages

"dependencies": {"@react-native-community/netinfo": "5.0.0","axios": "^0.19.2","expo": "~37.0.3","react": "16.8.3","react-devtools": "3.6.3","react-dom": "~16.9.0","react-native": "0.59.10","react-native-gesture-handler": "~1.3.0","react-native-gradient-buttons": "^2.0.1","react-native-netinfo": "^1.0.0","react-native-reanimated": "~1.4.0","react-native-screens": "~2.2.0","react-native-swipe-gestures": "^1.0.5","react-native-unimodules": "0.6.0","react-native-web": "~0.11.7","react-navigation": "^4.0.10","react-navigation-drawer": "^2.3.1","react-navigation-stack": "^1.10.3","react-scripts": "2.1.8"  },"devDependencies": {"@babel/core": "^7.8.6","babel-jest": "24.9.0","babel-preset-expo": "~8.1.0","jest": "24.9.0","jetifier": "^1.6.4","metro-react-native-babel-preset": "0.56.0","react-test-renderer": "16.9.0"  },

Java jdk-14.0.1
Gradle 4.10.1

stuck with this for last 3 days.What can be the solution?

$
0
0

npm version 6.14.4

FAILURE: Build failed with an exception.

  • What went wrong:Could not determine the dependencies of task ':app:preDebugBuild'.

    Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'. Could not resolve project :react-native-camera. Required by: project :app Unable to find a matching configuration of project :react-native-camera: None of the consumable configurations have attributes.

Can't build or install React Native app after installing React Navigation

$
0
0

I've just started building my first React Native app with minimal success. I've built my boilerplate code but now I want to add a separate screen to it. Cue React Navigation.

Having tried twice to install the module, I've not had much luck. I used both Facebook's documentation and the Getting Started guide from React Navigation themselves. Still no luck.

The error I get is something to do with the build.gradle file in my android folder. As per the Getting Started guide, I did add two lines into my dependencies area but this doesn't appear to have had any effect.

The error message is as follow:

Could not compile build file: 'C:\Users\USERNAME\Documents\ReactNative\WasteAway\android\app\build.gradle\'> startup failedGeneral error during semantic analysis: Unsupported class file major version 57

My dependencies in the build.gradle file are as follows:

dependencies {    implementation fileTree(dir: "libs", include: ["*.jar"])    implementation "com.facebook.react:react-native:+"  // From node_modules    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'    if (enableHermes) {        def hermesPath = "../../node_modules/hermes-engine/android/";        debugImplementation files(hermesPath +"hermes-debug.aar")        releaseImplementation files(hermesPath +"hermes-release.aar")    } else {        implementation jscFlavor    }}

Am I missing something obvious here or have I skipped a step on the tutorials? I can't see where I'm going wrong here, folks. Any help is greatly appreciated.

(React-Native 0.62.0) Getting Unable to find a matching variant of project :react-native-community_async-storage (same for other libs too)

$
0
0

My project was working perfectly but it stops building after upgrading to RN 0.62.0 from RN 0.59.5 (debug build is working fine, it happens only for assembleRelease)

I did a bit of google search and came across using macthingFallback, but that doesn't worked too.

missingDimensionStrategy can be a solution, but adding it for every library used can't be optimised option.

Please help, if anyone-else had came across same or similar issue.

my android/app/build.gradle have

  1. Two items in signingConfigs i.e. prod and stage that contains infoabout .keystore

  2. Four items in productFlavors (i.e. dev, beta, prod,qa)

  3. Three items in buildTypes i.e.
   debug {        applicationIdSuffix = ".dev"    }
release {    minifyEnabled enableProguardInReleaseBuilds    proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"    productFlavors.beta.signingConfig signingConfigs.stage    productFlavors.prod.signingConfig signingConfigs.prod    productFlavors.qa.signingConfig signingConfigs.stage    matchingFallbacks = ['release']}packagingOptions {    pickFirst "lib/armeabi-v7a/libc++_shared.so"    pickFirst "lib/arm64-v8a/libc++_shared.so"    pickFirst "lib/x86/libc++_shared.so"    pickFirst "lib/x86_64/libc++_shared.so"}

android/build.gradle have

dependencies{   classpath('com.android.tools.build:gradle:3.6.3')}repositories {        google()        jcenter()        maven { url 'https://maven.fabric.io/public' }    }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 {            // Android JSC is installed from npm            url("$rootDir/../node_modules/jsc-android/dist")        }        maven { url "https://www.jitpack.io" }    }}

my gradle-wrapper.properties have

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

my gradle.properties

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8android.useAndroidX=trueandroid.enableJetifier=trueFLIPPER_VERSION=0.33.1

settings.gradle have

rootProject.name = 'APPNAME'include ':react-native-config'project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)include ':react-native-sound'project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')include ':app', ':react-native-code-push'project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')

Error logs after running ./gradlew assembleRelease (giving error only for release build)

React-Native: Go back on android hardware back button pressed

$
0
0

I am trying to add going back on webview when the android backbutton was pressed and I still couldn't manage to make it work.

This is my code:

<WebView    ref={WEBVIEW_REF}    source={source}    domStorageEnabled={true}    onNavigationStateChange={this.onNavigationStateChange}/>componentDidMount() {    BackAndroid.addEventListener('hardwareBackPress', function() {        if(this.state.backButtonEnabled) {            this.refs[WEBVIEW_REF].goBack();            return true;        }    });};onNavigationStateChange = (navState) => {    this.setState({        backButtonEnabled: navState.canGoBack,    });};

With the code above I'm getting the error undefined is not an object this.state.backButtonEnabled (which is set in the state).

Than I just wanted to see if the goBack works so I removed the if statement and than I was getting the error undefined is not an object this.refs[WEBVIEW_REF].

What is the best solution for this?


How to get current route name in react-navigation?

$
0
0

I want the name of the current route or screen in react-navigation which I want to use inside if condition to make some changes.

How to restart react native app after deep linking

$
0
0

I have an app that I want to do payment with deep linking. I have some apis that are called at the start of the app so after getting back from payment I want to start app again this is my linking throw the url

const goToFeedback = () => {    setLoading(true);    sendTransactionPay({      walletUrl,      walletId,      callback: id => {        Linking.canOpenURL(`${paymentUrl}\/${id}`).then(supported => {          if (supported) {            Linking.openURL(`${paymentUrl}\/${id}`);          } else {            changeEvent({              showModal: false,              modalMessage: 'error',              info: false,            });          }        });      },    });  };

unfortunately after return from payment url the current component has shown. this is my manifest

<activity            android:name=".MainActivity"            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"            android:label="@string/app_name"            android:excludeFromRecents="true"            android:alwaysRetainTaskState="true"            android:launchMode="singleTask"            android:windowSoftInputMode="adjustResize"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter><intent-filter android:label="@string/app_name"><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><data android:scheme="app" android:host="avachain" /></intent-filter></activity>

react-native :app:installDebug FAILED

$
0
0

Install APK debug to my device failed.

jianglinghuadeMacBook-Pro:hello jianglinghua$ react-native run-androidJS server already running.Building and installing the app on the device (cd android && ./gradlew installDebug...WARNING [Project: :app] Current NDK support is deprecated.  Alternative will be provided in the future.:app:preBuild UP-TO-DATE......:app:assembleDebug UP-TO-DATE:app:installDebugInstalling APK 'app-debug.apk' on 'MI NOTE LTE - 6.0.1'Unable to install /Users/jianglinghua/Desktop/hello/android/app/build/outputs/apk/app-debug.apkcom.android.ddmlib.InstallException: Failed to establish session    at com.android.ddmlib.Device.installPackages(Device.java:894)    ........    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61):app:installDebug FAILEDFAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':app:installDebug'.> com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Failed to establish session* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.BUILD FAILEDTotal time: 13.945 secs

Could not install the app on the device, read the error above for details. Make sure you have an Android emulator running or a device connected and have set up your Android development environment:https://facebook.github.io/react-native/docs/android-setup.html

I look at my devices

jianglinghuadeMacBook-Pro:hello jianglinghua$ adb devicesList of devices attached98333978    device

React Native Error: Unable to resolve module `./index` from `` - index.js missing

$
0
0

I nearly got React Native working on my Android device. But somehow it fails in the last step because it does not find an index.js file. But that file is located in my project.

project structure

So when I now run this in src/

yarn react-native run-android

this is the Node CLI window:

node cli window

So my issue is:

Error: Unable to resolve module `./index` from ``:None of these files exist:  * index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)

From the console itself I cannot see any issue:

terminal command

So somehow it does not find the index.js file for some reason.

I already tried yarn react-native start -- --reset-cache but it did not change anything

3D Animations on View with React Native

$
0
0

I want to implement a flip effect in my React Native app, similar like described here:

https://www.codementor.io/reactjs/tutorial/building-a-flipper-using-react-js-and-less-css

My question is. Can I achieve it somehow with the help of some library like 'Animations'https://facebook.github.io/react-native/docs/animations.html or I have to play with 'plain' CSS styles.

What is the 'good practive' for such animations in React Native?

class CardBack extends Component {  render() {    return (<TouchableOpacity onPress={this.flip}><View style={styles.scrumCardBorder}><View style={styles.cardBack}></View></View></TouchableOpacity>    );  }  flip() {    this.setState({flipped: !this.state.flipped})  }}class CardFront extends Component {  render() {    return (<TouchableOpacity><View style={styles.scrumCardBorder}><View style={styles.cardFront}><Text style={styles.cardValue}>5</Text></View></View></TouchableOpacity>    );  }}

Stacked TouchableOpacity inside another TouchableOpacity is not clickable

$
0
0

Even though this document (https://facebook.github.io/react-native/docs/gesture-responder-system.html) states, that touch events are passed down to the children and are only consumed by a parent, if the child doesn't react on the event, I face the issue, that a TouchableOpacity nested inside another TouchableOpacity doesn't react properly on touches.

My structure is like follows

<ScrollView><TouchableOpacity onPress={() => console.log('This is printed always')}><View><Text>I can click here</Text><TouchableOpacity onPress={() => console.log('This is printed never')}><Text>I can click here but the outer onPress is called instead of the inner one</text></TouchableOpacity></View></TouchableOpacity></ScrollView>

The same happens for Buttons inside TouchableOpacitys: Clicking the Buttons calls the onPress method of the parent TouchableOpacity

Am I overseeing something?

React Native - TouchableOpacity not working inside an absolute positioned View

$
0
0

I've got an absolute positioned View that holds 3 TouchableOpacity components and the 3 fail to respond they are just not working at all, what is going wrong here please help me :)

Code

<View style={[styles.highNormalLowDocListHeaderStateContainer, {width: this.windowWidth, height: this.headerSmallHeight, position: 'absolute', left: 0, top: floatedHeaderTitleTop, elevation: 2}]}><TouchableOpacity onPress={() => this.getDocuments('high')} style={[styles.highNormalLowDocListHeaderStateTextContainer, highSelected.borderStyle]}><Text style={[styles.highNormalLowDocListHeaderStateText, highSelected.textStyle]}>HIGH</Text></TouchableOpacity><TouchableOpacity onPress={() => this.getDocuments('normal')} style={[styles.highNormalLowDocListHeaderStateTextContainer, normalSelected.borderStyle]}><Text style={[styles.highNormalLowDocListHeaderStateText, normalSelected.textStyle]}>NORMAL</Text></TouchableOpacity><TouchableOpacity onPress={() => this.getDocuments('low')} style={[styles.highNormalLowDocListHeaderStateTextContainer, lowSelected.borderStyle]}><Text style {[styles.highNormalLowDocListHeaderStateText, lowSelected.textStyle]}>LOW</Text></TouchableOpacity></View>

Screenshot

enter image description here


react-native run-android is unrecognized

$
0
0

I've installed react-native-cli globally:

npm install -g react-native-cli

Then run:

react-native init AwesomeProjectcd AwesomeProject

I got the following structure:

-- AwesomeProject   ---- node_modules      ------ react-native    

When I run react-native run-android I get an error:
Command run-android unrecognized. Did you mean to run this inside a react-native project?

When I run react-native start I get the same.

react-native -v
prints:
react-native-cli: 0.2.0
react-native: n/a - not inside a React Native project directory

What I'm doing wrong?

Error ':expo-permissions:debugCompileClasspath': recyclerview-1.0.0.jar not found

$
0
0

I'm having issues with react-native run android. Here's my build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {    ext {        buildToolsVersion = "28.0.3"        minSdkVersion = 21        compileSdkVersion = 28        targetSdkVersion = 28    }    repositories {        google()        jcenter()        mavenCentral()                mavenLocal()        maven {            url "https://dl.google.com/dl/android/maven2"            name 'Google'        }         maven {            url "D:/maven"            name 'LocalRepo'        }        maven {            url "https://mvnrepository.com/artifact/com.android.tools.lint/lint-gradle-ap"            name 'lint'        }    }    dependencies {        classpath("com.android.tools.build:gradle:3.5.3")        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle fSiles    }}allprojects {    repositories {        google()        jcenter()        mavenCentral()        maven {            url "https://mvnrepository.com/"            name 'lint'        }        mavenLocal()         maven {            url "D:/maven"            name 'LocalRepo'        }    }}

I'm getting this error:

* What went wrong:Execution failed for task ':expo-permissions:compileDebugKotlin'.> Could not resolve all artifacts for configuration ':expo-permissions:debugCompileClasspath'.> Could not find recyclerview-1.0.0.jar (androidx.recyclerview:recyclerview:1.0.0).       Searched in the following locations:            https://dl.google.com/dl/android/maven2/androidx/recyclerview/recyclerview/1.0.0/recyclerview-1.0.0.jar

The URL provided returns 404. I've tried it with three different VPNs and four different proxies. I don't know what I should do. It's not even looking n my other repositories. And I can't find a trace of this file on the internet. I found it on a Github repo, but I don't now where to put it.

What could be wrong? I have the latest version of expo, react and react-native.

Make an React Native app to open another app and click a button on that app

$
0
0

I want to make an android app which can open the given app using intent and click a particular button on the app and exit that app.

Can someone help me in this function. It has been over 6 months I have been trying to figure this out.

How to make Alert work on android/emulator? (react-native)

$
0
0

my package.json

Trying to run on expo cli with expo start -c. Usual alert() works, but not Alert from react-native

{"name": "my-app","version": "0.1.0","private": true,"dependencies": {"@testing-library/jest-dom": "^4.2.4","@testing-library/react": "^9.4.1","@testing-library/user-event": "^7.2.1","axios": "^0.19.2","json-server": "^0.16.1","react": "^16.12.0","react-dom": "^16.12.0","react-scripts": "3.4.0" },"scripts": {"start": "react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject","server": "json-server -p3001 db.json" },"eslintConfig": {"extends": "react-app" },"browserslist": {"production": [">0.2%","not dead","not op_mini all" ],"development": ["last 1 chrome version","last 1 firefox version","last 1 safari version" ]}}

How do I send data from server to an app?

$
0
0

I want to send some data:Database ==> server ==> app

I don't know what type of communication to use.Restful api ? Tcp ? or just get request ?App will get the data and display it in form of individual posts.

Viewing all 28479 articles
Browse latest View live


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