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

Network request failed error in real android device once Register using API

$
0
0

** I am trying to build a registration page in react-native which sends the data to an API. Whenever I try filling the form and sending the request, the emulator works fine but real android device shows a Network Request Failed error. I have read almost all related answers but none of them seem to help me. I am working with Android 7.0 API level 24. The code attached below.I have enabled internet permission in manifest file.**

fetchRegister(){
    var object = {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body:JSON.stringify( {
        "phone_number": this.state.contactNumber,
        "password": this.state.password,
      })
  };


  fetch('https://example.com/chatapp/web/registrations.php',object)
    .then((response) => response.json())
    .then((responseText) => {


        if(responseText.status == '200'){
              this.setState({
                registrationSuccessfull:true
              })

            var { navigate} = this.props.navigation;
            setTimeout(() => {
              navigate("Login",{screen: "Login"});
            }, 3000);
        }else if(responseText.status == '405'){
            this.setState({
              registeredAlready:true,
            });
        }
    })
    .catch((error) => {
        console.error(error);
    });
  }

React-Native :java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so

$
0
0

I have just updated my project to use react-native version 0.60.2 . But when I am trying to run an application on Android device it gets crashed after launch screen. I got the following error logs :

E/AndroidRuntime: FATAL EXCEPTION: create_react_context
    Process: com.tjspeed, PID: 3909
    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
        at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
        at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:27)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:949)
        at java.lang.Thread.run(Thread.java:760)

Few suggestions available here : https://github.com/facebook/react-native/issues/25601 but unfortunately none of them worked for me. Please suggest the workaround.

Process 'command 'node'' finished with non-zero exit value 1 linux whien generating signed apk

$
0
0
Process 'command 'node'' finished with non-zero exit value 1

In Android Studio 3.4 using Ubuntu 16.04 when i generating Signed APK this error is coming . But when i am generating debug apk it is ok. I have tried many solutions from SO itself,i haven't find any solution yet. Any one please know about this ? Thanks in Advance

"Error using newLatLngBounds(LatLngBounds, int): Map size can't be zero...." using react-native-maps on Android

$
0
0

I get an error: "Error using newLatLngBounds(LatLngBounds, int): Map size can't be zero. Most likely layout has not yet occured for the map view. Either wait until layout has occurred or use newLatLngBounds(LatLngBounds, int, int, int) which allows you to specify the map's dimensions".

But I set up an alert for getCurrentPosition and I'm receiving coordinates from getCurrentPosition().

import React, { Component } from 'react';
import { View, Dimensions } from 'react-native';
import MapView from 'react-native-maps';


const {width, height} = Dimensions.get('window')

const SCREEN_HEIGHT = height
const SCREEN_WIDTH = width
const ASPECT_RATIO = width / height
const LATITUDE_DELTA = 0.0922
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO


class Map extends Component {
	
	constructor(props) {
		super(props)

		this.state = {
			isMapReady: false,
			initialPosition: {
				longitude: 0,
				latitude: 0,
				longitudeDelta: 0,
				latitudeDelta: 0
			},

			markerPosition: {
				longitude: 0,
				latitude: 0
			}

		}
	}

	watchID: ?number = null

	componentDidMount() {
		navigator.geolocation.getCurrentPosition((position) => {

			alert(JSON.stringify(position))

			var lat = parseFloat(position.coords.latitude)
			var long = parseFloat(position.coords.longitude)

			var initialRegion = {
				latitude: lat,
				longitude: long,
				latitudeDelta: LATITUDE_DELTA,
				longitudeDelta: LONGITUDE_DELTA
			}

			this.setState({initialPosition: initialRegion})
			this.setState({markerPosition: initialRegion})			
		},

		(error) => alert(JSON.stringify(error)))

		this.watchID = navigator.geolocation.watchPosition((position) => {
			var lat = parseFloat(position.coords.latitude)
			var long = parseFloat(position.coords.longitude)
			var lastRegion = {
				latitude: lat,
				longitude: long,
				longitudeDelta: LONGITUDE_DELTA,
				latitudeDelta: LATITUDE_DELTA
			}

			this.setState({initialPosition: lastRegion})
			this.setState({markerPosition: lastRegion})
		})

	}

	componentWillUnmount() {
		navigator.geolocation.clearWatch(this.watchID)
	}

	onMapLayout = () => {
    this.setState({ isMapReady: true });
  }

	render() {

		return (

			<View style={styles.containerStyle}><MapView style={styles.mapStyle} initialRegion={this.state.initialPosition} onLayout={this.onMapLayout}>
					{ this.state.isMapReady &&<MapView.Marker coordinate={this.state.markerPosition}></MapView.Marker>
					}</MapView></View>

			)

	}

}

const styles = {
	containerStyle: {
		flex:1,
		justifyContent: 'center',
		alignItems: 'center',
		backgroundColor: 'lightblue'
	},

	mapStyle: {
		left: 0,
		right: 0,
		top: 0,
		bottom: 0,
		position: 'absolute'
	}

}

export default Map;

I have no idea what's going wrong to be honest... would really appreciate some help! Thank you!!

Hiding RefreshControl in Android React Native

$
0
0

I have a requirement where I want to hide the refresh indicator completely of Refresh Control for Android. I already set most of the color properties to transparent by still see gray circular indicator. Is there any way to completely hide this circular indicator. Link to gif about what is hapenning: http://imgur.com/dkAmkC6

This is my code:

import React, {Component} from 'react';
import {
  StyleSheet,
  Text,
  TextInput,
  View,
  FlatList,
  Dimensions,
  RefreshControl,
  ToastAndroid,
} from 'react-native';


import Constants from './Constants';



export default class TestList extends Component {

  constructor(props) {
    super(props);
    this.rows =[{id: 1},{id: 2},{id: 3},{id: 4}];
    this.state = {
      refreshing: false,
    }
  }


  renderItem(row) {
    return (
      <Text style={{fontSize: 20, borderBottomWidth: 1, borderColor: 'red', color: 'blue', height:80}}>{row.item.id}</Text>
      )
    }
  render() {
    return (
      <View style={[styles.container]}>
        <FlatList
          data={this.rows}
          renderItem={this.renderItem.bind(this)}
          overScrollMode='always'
          style={{flex: 1}}
          keyExtractor={(item) => item.id}
          removeClippedSubviews={false}
          keyboardShouldPersistTaps='always'
          refreshControl={
            <RefreshControl
              colors={['transparent']}
              style={{backgroundColor: 'transparent'}}
              progressBackgroundColor='transparent'
              refreshing={this.state.refreshing}
              onRefresh={() =>
              ToastAndroid.show('Refresh completed with short duration', ToastAndroid.SHORT)}/>}
          ref="FlatList"/>
      </View>
    )
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
})


  [1]: http://imgur.com/dkAmkC6

Getting library "libjsc.so" not found after upgrading React Native to 0.60-RC2

$
0
0

I have updated React Native to 0.60-RC2, migrated to AndroidX using the Android Studio refractor and used the jetifier mentioned here: https://github.com/react-native-community/discussions-and-proposals/issues/129

After doing this, I get the error library "libjsc.so" not found when running react-native run-android. i get the same error when running a release APK.

The stacktrace is:

06-24 15:55:01.823  8579  8656 E SoLoader: Error when loading lib: dlopen failed: library "libjsc.so" not found lib hash: 83f1717c1dc187d9f252a9f1fc66d430 search path is /data/app/com.jtv.testapp-4hvCKbqEmbyyOPykuQhm4Q==/lib/arm
06-24 15:55:01.823  8579  8656 E SoLoader: couldn't find DSO to load: libjscexecutor.so caused by: dlopen failed: library "libjsc.so" not found
06-24 15:55:01.825  8579  8656 E AndroidRuntime: FATAL EXCEPTION: create_react_context
06-24 15:55:01.825  8579  8656 E AndroidRuntime: Process: com.jtv.testapp, PID: 8579
06-24 15:55:01.825  8579  8656 E AndroidRuntime: java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libjscexecutor.so caused by: dlopen failed: library "libjsc.so" not found
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.react.jscexecutor.JSCExecutor.<clinit>(JSCExecutor.java:19)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.react.jscexecutor.JSCExecutorFactory.create(JSCExecutorFactory.java:29)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:949)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at java.lang.Thread.run(Thread.java:764)

My package.json is:

{
  "name": "TestApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.2.0",
    "@react-native-community/blur": "^3.3.1",
    "@react-native-community/netinfo": "^1.2.3",
    "@react-native-community/slider": "^1.0.4",
    "axios": "^0.18.0",
    "jetifier": "^1.4.0",
    "native-base": "^2.10.0",
    "prop-types": "^15.6.2",
    "qs": "^6.6.0",
    "react": "^16.8.6",
    "react-native": "^0.60.0-rc.2",
    "react-native-appsee": "^2.6.21",
    "react-native-device-info": "^0.24.3",
    "react-native-dialog": "^5.5.0",
    "react-native-draggable-flatlist": "^1.1.7",
    "react-native-elements": "^0.19.1",
    "react-native-email": "^1.0.2",
    "react-native-fast-image": "^5.1.2",
    "react-native-gesture-handler": "^1.0.12",
    "react-native-iap": "^2.4.0",
    "react-native-image-picker": "^0.28.0",
    "react-native-iphone-x-helper": "^1.2.0",
    "react-native-keyboard-aware-scroll-view": "^0.8.0",
    "react-native-kochava-tracker": "^1.1.0",
    "react-native-linear-gradient": "^2.5.3",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-modal": "^9.0.0",
    "react-native-orientation": "^3.1.3",
    "react-native-scrollable-tab-view": "^0.10.0",
    "react-native-snap-carousel": "^3.7.5",
    "react-native-super-grid": "^2.4.4",
    "react-native-tab-view": "^1.3.1",
    "react-native-underline-tabbar": "^1.3.6",
    "react-native-vector-icons": "^6.1.0",
    "react-native-video": "^4.3.1",
    "react-native-webview": "^5.12.0",
    "react-navigation": "^3.0.9",
    "react-navigation-backhandler": "^1.2.0",
    "react-redux": "^6.0.1",
    "redux": "^4.0.1",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0"
  },
  "devDependencies": {
    "@babel/core": "^7.4.0",
    "@babel/runtime": "^7.4.2",
    "@react-native-community/eslint-config": "^0.0.3",
    "babel-jest": "^24.5.0",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "eslint": "^5.15.3",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-react-hooks": "^1.5.1",
    "jest": "^24.5.0",
    "metro-react-native-babel-preset": "^0.53.1",
    "react-devtools-core": "^3.6.0",
    "react-test-renderer": "^16.8.6",
    "remote-redux-devtools": "^0.5.16"
  },
  "jest": {
    "preset": "react-native"
  }
}

My build.gradle is:

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
        entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

project.ext.vectoricons = [
    iconFontNames: [ 'MaterialIcons.ttf', 'FontAwesome.ttf', 'MaterialCommunityIcons.ttf' ]
]
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.jtv.testapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 29
        versionName "0.0.1"
        multiDexEnabled true
        renderscriptTargetApi 29
        renderscriptSupportModeEnabled true
        ndk {
            abiFilters "arm64-v8a", "x86_64","armeabi-v7a", "x86"
        }
        packagingOptions {
            pickFirst 'lib/x86_64/libjsc.so'
            pickFirst 'lib/arm64-v8a/libjsc.so'
            exclude "lib/arm64-v8a/libimagepipeline.so"
            exclude "lib/arm64-v8a/librealm-jni.so"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('RELEASE_STORE_FILE')) {
                storeFile file(RELEASE_STORE_FILE)
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }
    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"
            signingConfig signingConfigs.release
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            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
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation project(':react-native-webview')
    implementation project(':react-native-jtv-comic-reader')
    //implementation project(':@react-native-community_slider')
    implementation project(':@react-native-community_blur')
    implementation project(':@react-native-community_async-storage')
    implementation project(':@react-native-community_netinfo')
    implementation project(':react-native-appsee')
//    implementation project(':react-native-tune-sdk')
    implementation project(':react-native-iap')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-video')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-orientation')
    implementation project(':react-native-linear-gradient')
    implementation project(':react-native-kochava-tracker')
//    implementation project(':react-native-flurry-analytics')
    implementation project(':react-native-device-info')
//    implementation project(':react-native-fbsdk')
    implementation project(':react-native-fast-image')
    implementation project(':react-native-image-picker')
    implementation fileTree(dir: "libs", include: ["*.jar"])

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.facebook.fresco:fresco:1.13.0'
    implementation 'com.facebook.fresco:animated-gif:1.13.0'
    implementation 'androidx.mediarouter:mediarouter:1.0.0'

    implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.11.2'
    implementation 'com.google.android.gms:play-services-ads:18.0.0'
    implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
    implementation 'androidx.multidex:multidex:2.0.1'

    implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
    implementation 'com.android.installreferrer:installreferrer:1.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.facebook.android:facebook-android-sdk:4.36.1'
    implementation 'com.swrve.sdk.android:swrve-firebase:6.0.1'
    implementation 'com.google.firebase:firebase-core:17.0.0'
    implementation 'com.google.firebase:firebase-messaging:19.0.0'

    implementation 'androidx.mediarouter:mediarouter:1.0.0'
    implementation 'com.google.android.gms:play-services-cast:17.0.0'
    implementation 'com.googlecode.android-query:android-query:0.25.9'
    implementation 'com.google.android.gms:play-services-cast-framework:17.0.0'
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}
apply plugin: 'com.google.gms.google-services'

What is the libjsc.so file and how do I solve this error?

Accessing Nearby State ; React Native

$
0
0

If I were to have

function a(){
     ...
}

export default class App extends React.Component{
     constructor(props){
          this.state={
               var b: "value"
          }
     }
}

Would there be a way to directly access the state within App out of the nearby non-class function? I'm thinking of something similar to App.setState({}) or anything like that

With function a and class App being written in the same file, but with a just scoped outside of the class.

Firebase cloud mesaging - vibration and led notification lights not working on android

$
0
0

I have been using firebase cloud messaging to send push notifications on my android app. Below is the object I am using:

 android: {
    priority: 'HIGH',
    notification: {
      sound: 'default',
      notification_priority: 'PRIORITY_MAX',
      default_vibrate_timings: true,
      default_light_settings: true,
    },
  },

However, the phone does not vibrate or show led notifications. I have also added the vibration permission to the manifest file.


Unable to integrate java code to my react native project - error: incompatible types: ReactApplicationContext cannot be converted to Activity

$
0
0

I am trying to bridge java code with my react native project.

My flow is this - when the user clicks on my pay button in react native, it routes to a page (which is a payment gateway) written in java and then when the user is done with the payment process it routes back to the initial page in react native. I am getting the error below:

HelloWorldModule.java:56: error: incompatible types: ReactApplicationContext cannot be converted
    to Activity
                                    new RavePayManager((Activity)reactContext).setAmount(Double.parseDouble(String.valueOf(amount)))

Please see below my code: //React native code to connect to java

// We are importing the native Java module here
import {NativeModules} from 'react-native';
var HelloWorld = NativeModules.HelloWorld;

// type Props = {};
export default class App extends Component {

  // async function to call the Java native method
  async sayHiFromJava() {
    HelloWorld.sayHi( (err) => {console.log(err)}, (msg) => {console.log(msg)} );
  }

  render() {
    return (
      <View style={styles.container}>
        <TouchableOpacity onPress={ this.sayHiFromJava }>
              <Text>Invoke native Java code</Text>
         </TouchableOpacity>
      </View>
    );
  }
}

// MainApplication.java

package com.packagename;

import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.RNFetchBlob.RNFetchBlobPackage;
import com.reactnativecommunity.geolocation.GeolocationPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import com.facebook.react.bridge.Callback;



public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
          return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
          @SuppressWarnings("UnnecessaryLocalVariable")
          List<ReactPackage> packages = new PackageList(this).getPackages();
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // packages.add(new MyReactNativePackage());
          packages.add(new HelloWorldPackage(MainApplication.this)); ---- // added payment gateway
          return packages;
        } 

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }
      };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }


  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    initializeFlipper(this); // Remove this line if you don't want Flipper enabled
  }

  /**
   * Loads Flipper in React Native templates.
   *
   * @param context
   */
  private static void initializeFlipper(Context context) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
        Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
        aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
}

// HelloWorldModule.java - payment gateway code

package com.packagename;

import com.facebook.react.bridge.ReactApplicationContext;
import android.content.Context;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.uimanager.IllegalViewOperationException;
import com.flutterwave.raveandroid.RaveConstants;
import com.flutterwave.raveandroid.RavePayActivity;
import com.flutterwave.raveandroid.RavePayManager;
import android.app.Activity;

public class HelloWorldModule extends ReactContextBaseJavaModule {
    Context context;

 ReactApplicationContext reactContext;
    public HelloWorldModule(ReactApplicationContext reactContext,Context context) {
        super(reactContext); //required by React Native
        this.reactContext= reactContext;
          this.context= context;


    }

    @Override
    //getName is required to define the name of the module represented in JavaScript
    public String getName() { 
        return "HelloWorld";
    }

    @ReactMethod
    public void sayHi(Callback errorCallback, Callback successCallback) {
    //     try {
    //        System.out.println("Greetings from Java");

    //        successCallback.invoke("Callback : Greetings from Java");
    //    } catch (IllegalViewOperationException e) {
    //         errorCallback.invoke(e.getMessage());
    //     }
        try{
            int amount = 100;//call.argument("amount");
                        String narration = "Payment for soup";//call.argument("nara");
                        String countryCode = "NG"; //call.argument("countryCode");
                        String currency =  "NGN"; //call.argument("currency");
                        String amountText = "100";//call.argument("amountText");
                        String email = "haha@gmail.com";//call.argument("email");
                        String name = "King John";//call.argument("name");
                        String paymentId = "a98sjkhdjdu";//call.argument("paymentId");



                        String key ="*********-***********-X";
                         String secret = "*********-*********-X";

                                new RavePayManager((Activity)reactContext).setAmount(Double.parseDouble(String.valueOf(amount)))
                                .setCountry(countryCode)
                                .setCurrency(currency)
                                .setEmail(email)
                                .setfName(name)
                                .setlName("")
                                .setNarration(narration)
                                .setPublicKey(key)
                                .setTxRef(paymentId)
                                .acceptMpesaPayments(false)
                                .acceptAccountPayments(true)
                                .acceptCardPayments(true)
                                .acceptGHMobileMoneyPayments(false)
                                .onStagingEnv(false)
                                .initialize();
        } catch (IllegalViewOperationException e) {
            errorCallback.invoke(e.getMessage());
        }                  

    }

}

// HelloWorldPackage.java

package com.packagename;

import com.facebook.react.ReactPackage;
import android.content.Context;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.visioncapitaleye.HelloWorldModule;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class HelloWorldPackage implements ReactPackage {
Context context;

    HelloWorldPackage(Context context) {
        this.context = context;
    }

    @Override
    public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
        return Collections.emptyList();
    }

    @Override
    public List<NativeModule> createNativeModules(
            ReactApplicationContext reactContext) {
        List<NativeModule> modules = new ArrayList<>();
        //this is where you register the module
        modules.add(new HelloWorldModule(reactContext,context)); // added HelloWorldModule
        return modules;
    }
}

I am new to java and cant seem to figure out what I am doing wrong. Please assist.

create the project after getting an error while run already created project

$
0
0

create the project after getting an error while run already created project

enter image description here

Socket on React-Native

$
0
0

i'm looking for a code which works on React Native to use Sockets. I found this page https://www.npmjs.com/package/react-native-sockets where is explained all steps to follow. I need to make a client, who sends messages to an IP address in a specific port. I wrote the code, following this guide, but despite i follow all steps, compiler give me a problem when i call the function Sockets.startClient(config); The error is "null is not an object". Anyone could help me?

How can I integrate an existing Android app into React Native?

$
0
0

so my problem is that on my side I have an Android App that consists of two services and a React Native App on the other side. So my question is how can I glue them together. I've seen the documentation but it's quite confusing for me because I have no experience with React Native and a limited amount of time. Plus there are some specific changes in the android code, but I would like to avoid making any if possible as there will be no interaction between the android app and react native. I just need to run the Android App as part os the React Native one. Thank you in advance.

Integrate Native android sdk into React-Native app

$
0
0

I have some native android sdk code and willing to integrate sdk into react-native app.

I am looking wrapper of android sdk for react-native.

Allow creating windows in lock task mode

$
0
0

I'm using lock-task mode in my react native app which has "device owner".

Activity mActivity = reactContext.getCurrentActivity();

if (mActivity != null) {
  DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) mActivity.getSystemService(Context.DEVICE_POLICY_SERVICE);

  ComponentName mDPM = new ComponentName(mActivity, MyAdmin.class);

  if (myDevicePolicyManager.isDeviceOwnerApp(mActivity.getPackageName())) {
    String[] packages = {mActivity.getPackageName()};
    myDevicePolicyManager.setLockTaskPackages(mDPM, packages);
    mActivity.startLockTask();
  } else {
    mActivity.startLockTask();
  }
}

Lock-task mode works great, user cannot leave the app but problem is that I have functionality which requires connecting to a BLE printer. One part of the connection process is that user has to type PIN code to system prompt. Since he's in the lock-task mode, the alert is automatically dismissed.

I'v tried whitelist the com.android.systemui via setLockTaskPackages() but it didn't help. Any suggestions on what to try next?

Also, as I mentioned, it's react native app, but the code should be pretty much same as any other java app.

What is "native" and what is not in a React Native project?

$
0
0

I'm still very confused on how React Native works. Maybe because I don't have a decent background on Mobile Development (I have tried native Android once or twice though).

If I'm not wrong, hybrid frameworks like Phonegap or Ionic will run the entire project (or most of it) in a 'WebView', am I wrong?

Whereas native frameworks such as React Native is meant to use native resources instead of purely web technology.

But we still write Javascript, and React Native does the job so quickly that it is probably still using the Javascript we just wrote (I mean, it's not parsing, translating to native code and recompiling).

The question that comes to my mind is, what exactly is a native resource and what is not in a React Native project? Where is the Javascript we write running if not in a 'webview'? There are native libraries that creates the interface of Javascript to Objective-C and Java for both platforms? In a web-solution it simply injects the entire code in the WebView?

Extra question : can we consider React Native an hybrid framework just because we write one code for many different platforms, or it is not the correct terminology?


How to get accessToken of React Native GoogleSignIn?

$
0
0

I am not able to get accessToken, i need it in my backend api.

When i try this,

googleLogin = () => {

  GoogleSignin.signIn()
    .then((data) => {
      console.log("TEST "+JSON.stringify(data));
      var postData = {
        access_token: data.accessToken,
        code: data.idToken,
      };

      let axiosConfig = {
        headers: {
            'Content-Type': 'application/json',
            "Accept": "application/json",
        }
      };
     ....
      //Backend api axios call
     ....

    })
    .then((user) => {
      console.log("TEST G LOGIN 1 "+JSON.stringify(user))
    })
    .catch((error) => {
      console.log("....."+JSON.stringify(error))
    });
}

got this response, it doesn't inculde

accessToken

{
    "scopes": ["https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/drive.readonly"],
    "serverAuthCode": "4/jwE5LLLLLLa7-f33333jmMD2V978oyp44444eb9yGe_qhHnkXXXXXXXLFXKZlQdDzlH-iIJx_gzqlLLLLLL3Q0PP0",
    "idToken": "...v65a4MCC-ZUQmys_wf_DoCOBJEMuI........",
    "user": {
        "photo": "https://lh3.googleusercontent.com/-tLLLLLyeS0KE/AAAMMMMAAAI/AAAAAAAAAAA/ACHi3reMhihoeTe_6NjL666666EUVU82Q/s96-c/photo.jpg",
        "email": "test@gmail.com",
        "familyName": "tech",
        "givenName": "test",
        "name": "testtech",
        "id": "11688888817288868"
    }
}

as per documentation

getTokens() Resolves with an object containing { idToken: string, accessToken: string, } or rejects with an error. Note that using accessToken is discouraged.

So, i tried this in

GoogleSignin.Sign({
....
 var gettoken =  GoogleSignin.currentUserAsync(data.user).then((token) => {
      console.log('USER token', token);
    }).done();
...
 })

it got error and also tried const token = GoogSignIn.getTokens(), it return null.

package.json info

{
...
    "react": "16.8.3",
    "react-native": "0.59.9",
    "react-native-firebase": "5.3.1",
    "react-native-google-signin": "^2.0.0"
...
}

Please suggest what would be procedure to get accessToken.

How to clear react-native cache?

$
0
0

In react-native development, there are multiple caches used when the app is built:

  1. React-native packager cache
  2. Emulator cache
  3. Java side cache (.gradle) folder (only in android)
  4. npm cache (if relevant?)

Am I missing something also? Because I'm trying to clear cache in react-native, to be able to repeat a bug that only occurs on first usage. But clearing those caches above did not help. This is on android. When the app is building, most of the rows DO NOT say UP-TO-DATE, as expected, because I cleared the cache.

But, there are still many rows where this text is printed. Like:

app:preBuild UP-TO-DATE

app:preDebugBuild UP-TO-DATE

:app:preReleaseBuild UP-TO-DATE

The question is, how can I clear the whole cache related to react-native development?

Android: React-native-share returning "error: failure from system" when attempting Share.open

$
0
0

I am working on a React Native app that takes pictures with the camera, stores the images, and then allows the user to save the image to their photo library, or share those images through SMS, email, social media, etc.

Among other things, I am using react-native-fs (https://github.com/itinance/react-native-fs) and react-native-share (https://github.com/react-native-community/react-native-share) to accomplish this. Everything works just fine on iOS. The problem occurs when I try to share the stored image on Android. I did some digging, and it looks like the image must be in Base64 in order to be shared on android. I am trying to convert the image to base64 in react-native-fs and then send it along to react-native-share, but when I try to share the base64 image I get the following unhelpful error:

error: Failure from system

Here is the relevant code:

RNFS.readFile(this.state.sourceURI, 'base64')
    .then((res) => { 

      this.setState({androidURI: res});
    })
    .then((res) => {
      const options = {
        title: 'Share',
        message: "test",
        type: "image/png",
        url: 'data:image/png;base64,' + this.state.androidURI,
    };

      Share.open(options)
        .then((res) => { console.log(res); })
        .catch((err) => {
          Alert.alert(
        'Alert',
        "Sharing Error: " + JSON.stringify(err),
        [
          {
            text: 'Cancel',
            onPress: () => console.log('Cancel Pressed'),
            style: 'cancel',
          },
        ],
        {cancelable: false},
      );
      });
    })
    .catch((err) => {
      Alert.alert(
      'Alert',
      "Error converting to base64: " + JSON.stringify(err),
      [
        {
          text: 'Cancel',
          onPress: () => console.log('Cancel Pressed'),
          style: 'cancel',
        },
      ],
      {cancelable: false},
      );
    });

The error is being caught at Share.open ('Sharing Error'). If anyone could give me some insight as to what I am doing wrong, I would greatly appreciate it. If you require more information from me, I would be happy to provide it.

Thanks!!

EDIT: To clarify, this.state.sourceURI contains the following string:

'file:///storage/emulated/0/Android/data/com.{my app name here}/files/Test.png'

React Native build fails on release/staging

$
0
0

I am trying to prepare a staging release build/ release build but in both cases by my build fails. It gives me a huge list of errors. I have modified my build.gradle to add a staging environment. I am not sure why this is happening as my debug build works fine.

I used yarn android --variant=stagingrelease to generate the build and run on my physical android device. Using React-Native: 0.61.5.

Some of the errors are as follows

FAILURE: Build failed with an exception.

* What went wrong: Could not determine the dependencies of task ':app:preStagingreleaseBuild'.
> Could not resolve all task dependencies for configuration ':app:stagingreleaseRuntimeClasspath'.
   > Could not resolve project :@react-native-community_masked-view.
     Required by:
         project :app
      > Unable to find a matching variant of project :@react-native-community_masked-view:
          - Variant 'debugApiElements' capability Furry:@react-native-community_masked-view:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'debugRuntimeElements' capability Furry:@react-native-community_masked-view:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'releaseApiElements' capability Furry:@react-native-community_masked-view:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'releaseRuntimeElements' capability Furry:@react-native-community_masked-view:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
   > Could not resolve project :react-native-bootsplash.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-bootsplash:
          - Variant 'debugApiElements' capability Furry:react-native-bootsplash:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'debugRuntimeElements' capability Furry:react-native-bootsplash:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'releaseApiElements' capability Furry:react-native-bootsplash:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'releaseRuntimeElements' capability Furry:react-native-bootsplash:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
   > Could not resolve project :react-native-config.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-config:
          - Variant 'debugApiElements' capability Furry:react-native-config:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'debugRuntimeElements' capability Furry:react-native-config:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'releaseApiElements' capability Furry:react-native-config:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'releaseRuntimeElements' capability Furry:react-native-config:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
   > Could not resolve project :react-native-gesture-handler.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-gesture-handler:
          - Variant 'debugApiElements' capability Furry:react-native-gesture-handler:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'debugRuntimeElements' capability Furry:react-native-gesture-handler:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'releaseApiElements' capability Furry:react-native-gesture-handler:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'releaseRuntimeElements' capability Furry:react-native-gesture-handler:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
   > Could not resolve project :react-native-reanimated.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-reanimated:
          - Variant 'debugApiElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'debugRuntimeElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'releaseApiElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'releaseRuntimeElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
   > Could not resolve project :react-native-safe-area-context.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-safe-area-context:
          - Variant 'debugApiElements' capability Furry:react-native-safe-area-context:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'debugRuntimeElements' capability Furry:react-native-safe-area-context:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'releaseApiElements' capability Furry:react-native-safe-area-context:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'releaseRuntimeElements' capability Furry:react-native-safe-area-context:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
   > Could not resolve project :react-native-screens.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-screens:
          - Variant 'debugApiElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'debugRuntimeElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'releaseApiElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'releaseRuntimeElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.

Snippets of android/app/build.gradle

project.ext.envConfigFiles = [
        debug: ".env",
        release: ".env.production",
        stagingrelease: ".env.staging",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = true

def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.furry"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
        stagingrelease {
            initWith release
        }
    }

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
    }
}


apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
project.ext.vectoricons = [
    iconFontNames: [ 'MaterialIcons.ttf', 'MaterialCommunityIcons.ttf' ]
]
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

android/build.gradle

allprojects {
    repositories {
        mavenLocal()
        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")
        }

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

proguard-rules.pro

# Add any project specific keep options here:
-keep class com.furry.BuildConfig { *; }

Dependencies in package.json

"dependencies": {
        "@react-native-community/masked-view": "^0.1.6",
        "@react-navigation/native": "^5.0.7",
        "@react-navigation/stack": "^5.0.8",
        "axios": "^0.19.2",
        "libphonenumber-js": "^1.7.44",
        "react": "16.9.0",
        "react-native": "0.61.5",
        "react-native-bootsplash": "^1.2.1",
        "react-native-config": "^0.12.0",
        "react-native-gesture-handler": "^1.6.0",
        "react-native-reanimated": "^1.7.0",
        "react-native-safe-area-context": "^0.7.3",
        "react-native-screens": "^2.0.0-beta.10",
        "react-native-sms-retriever": "^1.1.1",
        "react-native-svg": "^11.0.1",
        "react-native-vector-icons": "^6.6.0",
        "realm": "4.0.0-beta.0",
        "recyclerlistview": "2.0.13-alpha.1"
    },

Preventing hardware back button android for React Native

$
0
0

I want to prevent the user from going back to the previous screen. So I added code, but this does not work. Are there any solutions for this? The alert pop up is seen but "return false" does not work.

componentDidMount() {
   BackAndroid.addEventListener('hardwareBackPress', () => {
     Alert.alert("alert","alert")

      this.props.navigator.pop();

       return false;
   });
Viewing all 29506 articles
Browse latest View live


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