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

How to show alert popup only inside specific screen using react native?

$
0
0

In My case, I have implemented alert popup within a function and the function will call from componentDidMount(). Now the problem is the alert implemented inside the home screen but I am getting alert in other screen also. I want to show alert only when I am in home screen.

If user in other screen alert should not show.

My Code: (Home.tsx)

componentDidMount = async () => {    this.showAlert();}async showAlert() {Alert.alert(‘Hello’,          [            {              text: "ok",              onPress: () => {              },              style: 'cancel',            },            {              text: "goodbye",              onPress: () => {                  this.props.navigation.navigate(‘details);              },            },          ],          { cancelable: false },        );}

How to handle back button behavior in bottom tabs in React Native?

$
0
0

I have a @react-navigation/bottom-tabs navigator when my app opens whose contents are like:

<Tab.Navigator        tabBarOptions={{            activeTintColor: '#77dd77',            inactiveTintColor: 'gray',        }}        tabBar={props => <MyTabBar {...props} />}        backBehavior={"history"}><Tab.Screen            name="Home"            component={Home}            options={{ title: 'Home' }}        /><Tab.Screen            name="Orders"            component={Orders}            options={{ title: 'Orders' }}        /><Tab.Screen            name="Profile"            component={Profile}            options={{ title: 'Profile' }}        /></Tab.Navigator>

I have a BackHandler in my code that makes the app exit when back button is pressed from the home page. Everything is fine and I have checked that the backhandler gets called when back button is pressed.

But when I switch to any other tab and then return to the homepage and press back to exit the app, backhandler stops working and the app shows error "The action 'GO_BACK'was not handled by any navigator. Is there any screen to go back to?"

This is a development-only warning but in the signed version, the app doesn't show any error and doesn't even exit.

How can I address this 'GO_BACK' action?

React Native Android Native Module Works Well on Debug but Doesn't Work on Release

$
0
0

I've created an Android Native Module in my React Native App to get User Installed Apps List. it works well on Debug but doesn't work on Release.

*Note : I've also tried to use a npm package called react-native-android-installed-apps, but itdoesn't work, so I decided to created a Native Module.

I don't know what's wrong that caused my Native Module works on Debug but doesn't work on Release. It will be great and I'll really appriciate it if anyone can point out to me what's wrong.

Here's my code:

@ReactMethodpublic void getUserInstalledApps(Callback successCallback) throws JSONException { PackageManager pm = reactContext.getPackageManager(); WritableArray array = new WritableNativeArray(); List<AppList> apps = new ArrayList<AppList>(); Gson g = new Gson(); List<PackageInfo> packs = reactContext.getPackageManager().getInstalledPackages(0); for (int i = 0; i < packs.size(); i++) {   PackageInfo p = packs.get(i);     if ((!isSystemPackage(p))) {       String appName = p.applicationInfo.loadLabel(reactContext.getPackageManager()).toString();       String packages = p.applicationInfo.packageName;       apps.add(new AppList(appName, packages));     }   }   for (AppList co : apps) {     JSONObject jo = new JSONObject(g.toJson(co));     WritableMap wm = convertJsonToMap(jo);     array.pushMap(wm);   }   successCallback.invoke(array);}private boolean isSystemPackage(PackageInfo pkgInfo) {  return (pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;}public class AppList { private String name; private String packages; public AppList(String name, String packages) {   this.name = name;   this.packages = packages; } public String getName() {   return name; } public String getPackages() {   return packages; }}

Is the project structure different in Windows and MacOS for a react native project?

$
0
0

I could not find the MacOS folder in my project structure and I am working on Windows.

Also I want to use bitrise as CI/CD for my react native project but it is not detecting my project as a react native project as I'm guessing I need to manually configure it for macOS project directory path and all.

React Native unrecognized event and metro server not working

$
0
0

I am trying to set up Android Studio with expo on a linuxmint OS, though it has proven difficult since it has these issues.

First I get:

Unrecognized event: {"type":"client_log","level":"log","data":["Running \"main\" with {\"initialProps\":{\"exp\":{\"initialUri\":\"exp://jz-c4q.anonymous.exp.direct:80\",\"manifest\":{\"iconUrl\":\"http://packager.jz-c4q.anonymous.exp.direct:80/assets/./assets/images/icon.png\",\"version\":\"1.0.0\",\"xde\":true,\"updates\":{\"fallbackToCacheTimeout\":0},\"sdkVersion\":\"38.0.0\",\"platforms\":[\"android\",\"ios\"],\"hostUri\":\"jz-c4q.anonymous.exp.direct:80\",\"slug\":\"\",\"icon\":\"./assets/images/icon.png\",\"web\":{\"favicon\":\"./assets/images/favicon.png\"},\"loadedFromCache\":false,\"debuggerHost\":\"packager.jz-c4q.anonymous.exp.direct:80\",\"splash\":{\"resizeMode\":\"contain\",\"backgroundColor\":\"#ffffff\",\"image\":\"./assets/images/splash.png\",\"imageUrl\":\"http://packager.jz-c4q.anonymous.exp.direct:80/assets/./assets/images/splash.png\"},\"primaryColor\":\"#023C69\",\"orientation\":\"portrait\",\"isVerified\":true,\"env\":{},\"id\":\"@anonymous/-7a7930a8-81c8-493d-a666-abe1c7df80c5\",\"scheme\":\"myapp\",\"bundleUrl\":\"http://packager.jz-c4q.anonymous.exp.direct:80/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false\",\"packagerOpts\":{\"https\":false,\"dev\":true,\"lanType\":\"ip\",\"hostType\":\"tunnel\",\"minify\":false,\"urlRandomness\":\"jz-c4q\"},\"name\":\"\",\"ios\":{\"supportsTablet\":true},\"developer\":{\"tool\":\"expo-cli\",\"projectRoot\":\"/home/\"},\"mainModuleName\":\"node_modules/expo/AppEntry\",\"logUrl\":\"http://jz-c4q.anonymous.exp.direct:80/logs\",\"assetBundlePatterns\":[\"**/*\"],\"userInterfaceStyle\":\"automatic\"},\"shell\":false}},\"rootTag\":41}"]}

Then I get: Unrecognized event: {"type":"client_log","level":"log","data":["[Error: Network Error]"]}

When I ran it previously on a windows machine I didn't have this issue.

I also get an error regarding the metro server, when all errors have been presented: Cannot connect to the Metro server.

I tried as well setting up a new react native project, and it seemed to work fine there, might there be something wrong with the backend?

Any idea of what might be going wrong here, and what may fix the issues?

Run a App made in React native in a Emulator Android

$
0
0

S.O. Ubuntu: 20.04

I'm trying to run a app than I downloaded, but when I try to "yarn run android".

The next message

A problem occurred evaluating project ':react-native-community_async-storage'.> Plugin with id 'com.android.library' not found.* 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.orgBUILD FAILED in 1s

This is the code ofbuilScrip in file build.gradle.

buildscript {

if (project == rootProject) {    repositories {        google()        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:3.5.0'    }}

}

please, help!!

Task :unimodules-react-native-adapter:compileReleaseKotlin FAILED

$
0
0

When i try to convert react native app to apk, I can create output folder but then I get this error:

Task :unimodules-react-native-adapter:compileReleaseKotlin FAILED

FAILURE: Build failed with an exception.

  • What went wrong:Execution failed for task ':unimodules-react-native-adapter:compileReleaseKotlin'.

Could not resolve all artifacts for configuration ':unimodules-react-native-adapter:releaseCompileClasspath'.Could not download nativeloader-0.8.0.jar (com.facebook.soloader:nativeloader:0.8.0)> Could not get resource 'https://jcenter.bintray.com/com/facebook/soloader/nativeloader/0.8.0/nativeloader-0.8.0.jar'.> Could not GET 'https://jcenter.bintray.com/com/facebook/soloader/nativeloader/0.8.0/nativeloader-0.8.0.jar'.> jcenter.bintray.comCould not download okhttp-urlconnection-3.12.1.jar (com.squareup.okhttp3:okhttp-urlconnection:3.12.1)> Could not get resource 'https://jcenter.bintray.com/com/squareup/okhttp3/okhttp-urlconnection/3.12.1/okhttp-urlconnection-3.12.1.jar'.> Could not GET 'https://jcenter.bintray.com/com/squareup/okhttp3/okhttp-urlconnection/3.12.1/okhttp-urlconnection-3.12.1.jar'.> jcenter.bintray.comCould not download okhttp-3.12.1.jar (com.squareup.okhttp3:okhttp:3.12.1)> Could not get resource 'https://jcenter.bintray.com/com/squareup/okhttp3/okhttp/3.12.1/okhttp-3.12.1.jar'.> Could not GET 'https://jcenter.bintray.com/com/squareup/okhttp3/okhttp/3.12.1/okhttp-3.12.1.jar'.> jcenter.bintray.com

Run an App made in React native in an Emulator Android

$
0
0

S.O. Ubuntu: 20.04

I'm trying to run a app than I downloaded, but when I try to "yarn run android".

The next message

A problem occurred evaluating project ':react-native-community_async-storage'.> Plugin with id 'com.android.library' not found.* 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.orgBUILD FAILED in 1s

This is the code ofbuilScrip in file build.gradle.

buildscript {

if (project == rootProject) {    repositories {        google()        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:3.5.0'    }}

}

please, help!!


Android build doesn't work (Duplicate class com.google.android.gms.internal.measurement.zzbt found in modules)

$
0
0

It worked fine until a week ago, but this week the build didn't work and I got the following error.I tried the following, but I haven't solved it yet.Any small thing is fine, so if anyone knows any hints or solutions, please let me know.

■What I tried

  • Downgrade classpath ("com.google.gms: google-services: 4.3.3")
  • Specify the versions of com.google.android.gms: play-services-measurement-sdk-api and com.google.android.gms: play-services-measurement
  • Gradle version upgrade, downgrade

■Development environmentreact:16.9.0react-native:0.61.5Android Gradle:4.0.0Firebase(google-services):4.3.4

> Task :app:checkDebugDuplicateClasses FAILED> Transform artifact play-services-measurement.aar (com.google.android.gms:play-services-measurement:17.4.4) with DexingWithClasspathTransform> Transform artifact play-services-measurement-impl.aar (com.google.android.gms:play-services-measurement-impl:17.4.4) with DexingWithClasspathTransformReactNativeFirebase WARNING: NPM package '@react-native-firebase/auth' depends on '@react-native-firebase/app' v8.3.1 but found v8.4.0, this might cause build issues or runtime crashes.501 actionable tasks: 7 executed, 494 up-to-dateD8: Type com.google.android.gms.internal.measurement.zzig is referenced as an interface from `com.google.android.gms.internal.measurement.zzby`.D8: Interface `com.google.android.gms.measurement.internal.zzhd(classpath class)` used as super class of `com.google.android.gms.measurement.AppMeasurement$UserProperty`.FAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':app:checkDebugDuplicateClasses'.> 1 exception was raised by workers:  java.lang.RuntimeException: Duplicate class com.google.android.gms.internal.measurement.zzbt found in modules jetified-play-services-measurement-17.4.4-runtime.jar (com.google.android.gms:play-services-measurement:17.4.4) and jetified-play-services-measurement-sdk-api-17.5.0-runtime.jar (com.google.android.gms:play-services-measurement-sdk-api:17.5.0)  Duplicate class com.google.android.gms.internal.measurement.zzbu found in modules jetified-play-services-measurement-17.4.4-runtime.jar (com.google.android.gms:play-services-measurement:17.4.4) and jetified-play-services-measurement-sdk-api-17.5.0-runtime.jar (com.google.android.gms:play-services-measurement-sdk-api:17.5.0)  Duplicate class com.google.android.gms.internal.measurement.zzfw found in modules jetified-play-services-measurement-base-17.5.0-runtime.jar (com.google.android.gms:play-services-measurement-base:17.5.0) and jetified-play-services-measurement-impl-17.4.4-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.4)  Duplicate class com.google.android.gms.internal.measurement.zzfy found in modules jetified-play-services-measurement-base-17.5.0-runtime.jar (com.google.android.gms:play-services-measurement-base:17.5.0) and jetified-play-services-measurement-impl-17.4.4-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.4)  Duplicate class com.google.android.gms.internal.measurement.zzfz found in modules jetified-play-services-measurement-base-17.5.0-runtime.jar (com.google.android.gms:play-services-measurement-base:17.5.0) and jetified-play-services-measurement-impl-17.4.4-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.4)  Duplicate class com.google.android.gms.internal.measurement.zzga found in modules jetified-play-services-measurement-base-17.5.0-runtime.jar (com.google.android.gms:play-services-measurement-base:17.5.0) and jetified-play-services-measurement-impl-17.4.4-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.4)  Duplicate class com.google.android.gms.internal.measurement.zzgb found in modules jetified-play-services-measurement-base-17.5.0-runtime.jar (com.google.android.gms:play-services-measurement-base:17.5.0) and jetified-play-services-measurement-impl-17.4.4-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.4)  Duplicate class com.google.android.gms.measurement.internal.zzgz found in modules jetified-play-services-measurement-base-17.5.0-runtime.jar (com.google.android.gms:play-services-measurement-base:17.5.0) and jetified-play-services-measurement-impl-17.4.4-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.4)  Duplicate class com.google.android.gms.measurement.internal.zzik found in modules jetified-play-services-measurement-base-17.5.0-runtime.jar (com.google.android.gms:play-services-measurement-base:17.5.0) and jetified-play-services-measurement-impl-17.4.4-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.4)  Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.

keystore not found for signing config 'release'.-- React native

$
0
0

I'm trying to generate a Signed APK for react native project.Followed steps from android and react native documentation.

my Build.gradle file

android {compileSdkVersion 23buildToolsVersion '26.0.2'defaultConfig {    applicationId "com.appmobile"    minSdkVersion 16    targetSdkVersion 22    versionCode 1    versionName "1.0"    ndk {        abiFilters "armeabi-v7a", "x86"    }}signingConfigs {    release {        if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {            storeFile file(MYAPP_RELEASE_STORE_FILE)            storePassword MYAPP_RELEASE_STORE_PASSWORD            keyAlias MYAPP_RELEASE_KEY_ALIAS            keyPassword MYAPP_RELEASE_KEY_PASSWORD        }    }}buildTypes {    release {        signingConfig signingConfigs.release        // minifyEnabled enableProguardInReleaseBuilds        // proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"    }}splits {    abi {        reset()        enable enableSeparateBuildPerCPUArchitecture        universalApk false  // If true, also generate a universal APK        include "armeabi-v7a", "x86"    }}// buildTypes {//     release {//         minifyEnabled enableProguardInReleaseBuilds//         proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"//     }// }// applicationVariants are e.g. debug, releaseapplicationVariants.all { variant ->    variant.outputs.each { output ->        // For each separate APK per architecture, set a unique version code as described here:        // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits        def versionCodes = ["armeabi-v7a":1, "x86":2]        def abi = output.getFilter(OutputFile.ABI)        if (abi != null) {  // null for the universal-debug, universal-release variants            output.versionCodeOverride =                    versionCodes.get(abi) * 1048576 + defaultConfig.versionCode        }    }}

}

I have placed keystore file in Android/app directory

my grade.properties

    android.useDeprecatedNdk=trueMYAPP_RELEASE_STORE_FILE=sampleReleasekeyStore.jksMYAPP_RELEASE_KEY_ALIAS=*****MYAPP_RELEASE_STORE_PASSWORD=*****MYAPP_RELEASE_KEY_PASSWORD=*****

when executing cd android && ./gradlew assembleRelease.

Its throwing Build failed

Execution failed for task ':app:validateSigningRelease'. Keystore file /Users/username/Projects/appMobile/android/app/sampleReleasekeyStore.jks not found for signing config 'release'.

I'm using Mac environment. Please let me know where I'm going wrong.

Error Execution failed for task ':app:mergeReleaseResources' building APK

$
0
0

After trying to build APK once and fixing an error, I got an error executing ./gradlew assembleRelease again: Execution failed for task ':app:mergeReleaseResources' building APK

How to remove strings and special characters from string and show only numbers without comma using regex?

$
0
0

In My case I am using react native typescript, I want to get only numbers from group string without comma. How to get it using regex match or replace?

 taskname = TASK_XC0.0.0.0.89t_abc_test let task = taskname.match( /[0-9]+/g, ''); //0,0,0,0,89 

Actual output need to get 000089

image upload error on Android works fine on iOS, expo image picker

$
0
0

so im using expo and react native, its doing fine when fetching multipart-data to cloud on iOS, with uri: file:///

but on Android, the uri is file:/data ,

and show error https://i.stack.imgur.com/4bRiY.png

i already tried changing the uri on Android to file:///data but still showing network request failed

any ideas ?

react-native-maps blank on some android devices emulated

$
0
0

I'm trying to make an app with a google maps, the map is rendering well on an emulated device(Nexus 5 API 28), but it doesn't work on other emulated devices by Android Studio. On this photo both emulated devices have the same API, TARGET and CPU / API but on the second device(Pixel 3a API 28) the map is blank.

enter image description here

Update one APK from two projects

$
0
0

I'm developing an Android application using WLanguage (WinDev Mobile). Now, I would like to re-develop the application with another language/technology : React Native. I store my APK on a private server. To update the application the user open on his device the existing application, download the new APK, and the update start.

My question is : what do i have to do to be sure my APK created with React Native will be detected as an update from the one created with WinDev Mobile ?

I want the end-user to update the existing application and not install a new one.

Thanks


React Native APK installing and App Carshing problem

$
0
0

My phone is Samsung Galaxy J7 2017 when I try to install my react native app, I get this error: "APK not installed" and when I try to install in Samsung J2, I can. But When I open the app, app crashes.

react-native run-android command failed, but gradlew installDebug work

$
0
0

I'm using react-native 0.43.3 on OSX.I tried to running app on Android and get message

react-native run-androidScanning 568 folders for symlinks in /Users/ruci.k/project/mayacrew/supermembers/supermembers/node_modules (5ms)JS server already running.Building and installing the app on the device (cd android && ./gradlew installDebug)...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 haveset up your Android development environment:https://facebook.github.io/react-native/docs/android-setup.html

./gradlew installDebug gave me some errors and fixed it all.Finally build get successed and app is working on Android device.

But react-native run-android command still not work.Only ./gradlew installDebug command work.

Is there anything can I check to use react-native run-android command?

I can't understand how could it happened.

Is there a NPM package for instagram auth implimentation in react native?(Expo)

$
0
0

I have successfully integrated facebook and google authentication in my react native application.

I have not ejected the application its still running on Expo.

For Facebook i found expo-facebook NPM package and for google i found expo-google-app-auth NPM package and with the help of some blogs i successfully integrated the functionality.

But in case of Instagram i cant find any proper documentation or blogs for the auth implementation.

Do Instagram have an auth implementation for react native and if there is can it implemented in Expo and how ??

React Native Link for React Native .60 +

$
0
0

This is still something that is required, I see this message all the time, but it's completely invalid from what I have experienced. Almost every package I work with, I still have to run the react-native link.

enter image description here

Can anyone tell me what's up with this? Is it just particular packages, or why do I still need to run react-native link all the time, when it tells me I shouldn't run it. I mean, it's really just adding it to the pod file for iOS and gradle for Android.

Anyone else experiencing this?

To show this further, look at this, just ran the npm install for lottie, it will not work unless I run the link, should I add to my pod file manually? I don't get why React Native (Facebook) team is saying that it's no longer required, out of our team of 4 people, we have had it required always.

enter image description here

Android app error when use Promise while on background mode

$
0
0

My goal is to delay a method for 1s. The Promise works great while in the Foreground Mode. If used while in the background mode, it will throw an unhandled promise.

The code

const recorderStop = async () => {  await new Promise((resolve) => setTimeout(resolve, 1000)); // used to delay.  ... the code I wish to invoke...}

The expected behavior:

The code wait for 1s before invoking the rest of the code.

The acutal behavior:

The code freezes and waiting the await new Promise to return a promise until the app is in the Foreground Mode.

Viewing all 29603 articles
Browse latest View live


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