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

How to set ENVFILE in Terminal to generate Android Release APK?

$
0
0

I'm trying to build APK from command line in my React Native project. I've used react-native-config plugin to define my API URLs based on selected environment.

When I try to launch the app on emulator with the command (from Terminal), ENVFILE=.env.dev react-native run-android, app builds and launches properly.

But when I try to generate Release build using the command (from Terminal), ENVFILE=.env.dev && cd android && ./gradlew clean build, command fails with the log:

> Configure project :app
Reading env from: .env
**************************
*** Missing .env file ****
**************************

Question: How to build Release APK using ENVFILE from Terminal?


The library com.google.firebase:firebase-iid is being requested by various other libraries at [[17.0.0,17.0.0]], but resolves to 16.2.0

$
0
0

I started to get this error today, yesterday everything worked fine, there was no changes in gradle or firebase version

The library com.google.firebase:firebase-iid is being requested by various other libraries at [[17.0.0,17.0.0]], but resolves to 16.2.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

I saw that yesterday was update in google-services plugin, probably that is causing the problem.

How to fix this problem?

Can't build my android project after move it to another computer

$
0
0

I can't build my android project in react native project, i just used this project in my old computer and it built fine, but after i clone it from my new macbook i get error.

i tried to delete the cache folder and nothing doesn't work

The error that i get

FAILURE: Build failed with an exception.

  • What went wrong: Could not open settings remapped class cache for espedq8f7vbnwrshulq11juyl (/Users/(UserName)/.gradle/caches/5.0/scripts-remapped/settings_3tlaqtt0fziq08p73u9gmyutn/espedq8f7vbnwrshulq11juyl/settingsa9190c3ddc71e1450eb3f3e7bc6a334f).

  • Could not open settings generic class cache for settings file '/Users/(UserName)/Desktop/MyApp/friendsapp/client/android/settings.gradl' (/Users/(UserName)/.gradle/caches/5.0/scripts/espedq8f7vbnwrshulq11juyl/settings/settingsa9190c3ddc71e1450eb3f3e7bc6a334f).

  • BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 57

Change color of statusBar in splashScreen react-native android

$
0
0

enter image description here

I try to add a splash screen to a RN app. As you can see in the gif the status bar color is changing to black while the splash screen is on, but i can't find the problem exactly. I have followed this tutorial to implement the splash screen: Add splash screen to RN app Please find here the code i added to android studio:

in AndroidManifest.xml =>

<activity
            android:name="MainActivity"
            android:label="@string/app_name"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:windowSoftInputMode="adjustResize"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:exported="true"
            />

        <activity
            android:name=".SplashActivity"
            android:theme="@style/SplashTheme"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
            </intent-filter>
        </activity>

in styles.xml =>

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->

    <!-- Add the following line to set the default status bar color for all the app. -->
    <item name="android:statusBarColor">@color/mdcGreen</item>
    <!-- Add the following line to set the default status bar text color for all the app
    to be a light color (false) or a dark color (true) -->
    <item name="android:windowLightStatusBar">false</item>
    <!-- Add the following line to set the default background color for all the app. -->
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

<!-- Adds the splash screen definition -->
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:statusBarColor">@color/mdcGreen</item>
    <item name="android:background">@drawable/background_splash</item>
</style>

</resources>

in drawable/background_splash.xml =>

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/mdcGreen"/>

    <item
        android:width="200dp"
        android:height="200dp"
        android:drawable="@mipmap/mdc"
        android:gravity="center" />

</layer-list>

in layout/launch_screen.xml =>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:background="@drawable/background_splash"
    android:statusBarColor="@color/mdcGreen">

</LinearLayout>

THANKS!

Please help, error: Unable to determine the current character, it is not a string, number, array, or object in react-native for android

$
0
0

Whenever I run react-native run-android while keeping the emulator running, I get this error. react-native run-ios wroks completely fine.

Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
:ReactNative:Failed to parse React Native CLI configuration: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

The current character read is 'E' with an int value of 69
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
Error: Invalid attribute nameLine: 16Column: 18Char: .    at error (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/sax/lib/sax.js:651:10)    at strictFail (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/sax/lib/sax.js:677:7)    at SAXParser.write (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/sax/lib/sax.js:1313:13)    at new XmlDocument (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/xmldoc/lib/xmldoc.js:261:15)    at readManifest (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/@react-native-community/cli-platform-android/build/config/readManifest.js:38:10)    at Object.projectConfig (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/@react-native-community/cli-platform-android/build/config/index.js:59:46)    at Object.get project [as project] (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/config/index.js:114:50)    at /Users/yashatreya/Desktop/Realyze/Realyze/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/config/config.js:8:452    at Array.forEach (<anonymous>)    at _objectSpread (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/config/config.js:8:392)
^

FAILURE: Build failed with an exception.

* Where:
Script '/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 201

* What went wrong:
A problem occurred evaluating script.
> Failed to parse React Native CLI configuration. Expected running 'npx --quiet --no-install react-native config' command from '/Users/yashatreya/Desktop/Realyze/Realyze' directory to output valid JSON, but it didn't. This may be caused by npx resolving to a legacy global react-native binary. Please make sure to uninstall any global 'react-native' binaries: 'npm uninstall -g react-native react-native-cli' and try again

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

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

As indicated in the error message, I tried running npm uninstall -g react-native react-native-cli but it didn’t work.

Info about my environment:

System:
    OS: macOS 10.15
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 29.68 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.13.0 - /usr/local/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.12.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5977832
    Xcode: 11.0/11A420a - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: ^0.61.4 => 0.61.4 
  npmGlobalPackages:
    react-native-cli: 2.0.1

android/app/build.gradle below:

apply plugin: "com.android.application"

import com.android.build.OutputFile
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 = false

def jscFlavor = 'org.webkit:android-jsc:+' 

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.realyze"
        minSdkVersion 21 
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }
    // rootProject.ext.minSdkVersion
    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"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            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
            }

        }
    }
}

dependencies {
    implementation project(':react-native-push-notification')
    implementation project(':react-native-sound')
    implementation project(':react-native-audio')
    implementation 'com.android.support:multidex:2.0.1'
    implementation project(':react-native-gesture-handler')
    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'
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation 'com.google.firebase:firebase-auth:19.1.0'
    implementation project(path: ":@react-native-firebase_auth")
    implementation project(path: ":@react-native-firebase_messaging")
    implementation project(path: ":@react-native-firebase_database")
    implementation project(':react-native-datetimepicker')
    implementation project(path: ":@react-native-firebase_firestore")
    implementation project(path: ":@react-native-firebase_functions")
}

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
// }

// 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 from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'

android/build.gradle below :


buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.4.2"
        classpath 'com.google.gms:google-services:4.3.2'
    }
}

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

Initially I was getting this error: react-native build error: Could not find method implementation() for arguments [jscFlavor] on project ':app' of type org.gradle.api.Project but now I am getting the above.

Please help me, I am trying to solve this error for a week now. If any other file is required, please let me know I'll add it.

Open specific file extention with the app

$
0
0

I have an app that create a custom file, when open the file in the device file manager it should run the app and the file should be copied to the bundle directory. I followed this tutorial: https://dev-yakuza.github.io/en/react-native/open-file-with-app/

everything work fine on the emulator (android version 9), but it doesn't work on my device (with android version 6.0.1), it just open the app but doesn't copy the file.

my AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />                                               
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />                                              
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />

<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:roundIcon="@mipmap/ic_launcher_round"
  android:allowBackup="false"
  android:theme="@style/AppTheme">
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/> 
    </intent-filter>
    <!-- custom file start -->
    <intent-filter
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name">
        <action android:name="android.intent.action.VIEW" />
        <action android:name="android.intent.action.EDIT" />
        <category android:name="android.intent.category.DEFAULT" />
        <!-- change custom file extension -->
        <data
          android:mimeType="*/*"
          android:host="*"
          android:pathPattern=".*\\.wallkami"
        />
    </intent-filter>
    <!-- custom file end -->
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

MainActivity.java:

package com.wallkami;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

import android.content.ContentResolver;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class MainActivity extends ReactActivity {

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
    return "wallkami";
  }

 @Override
 protected ReactActivityDelegate createReactActivityDelegate() {
   return new ReactActivityDelegate(this, getMainComponentName()) {
     @Override
     protected ReactRootView createRootView() {
      return new RNGestureHandlerEnabledRootView(MainActivity.this);
     }
   };
 }

    @Override
    protected void onResume() {
        super.onResume();
        Uri data = getIntent().getData();
        if(data != null) {
            try {
                importData(data);
            }catch (Exception e) {
                Log.e("File Import Error", e.getMessage());
            }
        }
    }

    private void importData(Uri data) {
        final String scheme = data.getScheme();

        if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
            try {
                ContentResolver cr = getApplicationContext().getContentResolver();
                InputStream is = cr.openInputStream(data);
                if(is == null) return;

                String name = getContentName(cr, data);

                PackageManager m = getPackageManager();
                String s = getPackageName();
                PackageInfo p = m.getPackageInfo(s, 0);
                s = p.applicationInfo.dataDir;

                InputStreamToFile(is, s + "/files/opened.wallkami");
            } catch (Exception e) {
                Log.e("File Import Error", e.getMessage());
            }
        }
    }

    private String getContentName(ContentResolver resolver, Uri uri){
        Cursor cursor = resolver.query(uri, null, null, null, null);
        cursor.moveToFirst();
        int nameIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
        if (nameIndex >= 0) {
            return cursor.getString(nameIndex);
        } else {
            return null;
        }
    }

    private void InputStreamToFile(InputStream in, String file) {
        try {
            OutputStream out = new FileOutputStream(new File(file));

            int size = 0;
            byte[] buffer = new byte[1024];

            while ((size = in.read(buffer)) != -1) {
                out.write(buffer, 0, size);
            }

            out.close();
        }
        catch (Exception e) {
            Log.e("MainActivity", "InputStreamToFile exception: " + e.getMessage());
        }
    }
}

NOTE: I'm not good with native code XD

Xcode Conflicting with React Native Module for Android

$
0
0

I'm developing an React Native App for both iOS and Android and I've just finished implementing a React Native Module only for Android. The issue is, when I try to build the app on XCode I get this error:

ld: library not found for -lRNOpenAppSettings clang: error: linker command failed with exit code 1 (use -v to see invocation)

Does anyone know how to make XCode ignore this?

programmatically retrieve Header component height - React Native

$
0
0

Using NativeBase, I added a Header component. Now, I want to programmatically retrieve the height of the header. How can I do this. The code for adding the Header is given below:

I tried using Dimensions.get('window') but it gives me the height of the entire view.

The code:

import React, {Component} from 'react-native';
import {Container, Header, Button, Title, Icon} from 'native-base';
​
export default class ThemeHeaderExample extends Component {
    render() {
        return (
                <Header>
                    <Button transparent />

                    <Title>Header</Title>

                </Header>
        );
    }
}

Execution failed for task ':react-native-camera:compileDebugJavaWithJavac'

$
0
0

I am creating app using React-Native and testing it on Android device. After adding react-native-camera module, the following error occurs:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':react-native-camera:compileDebugJavaWithJavac'. at "Build->Run Tasks" (Android Studio).

Concerning the Java compiler, there are about 20-30 errors, all of which show the following: error: package android.support.annotation does not exist, error: package android.support.v4.util does not exist, error: package android.support.media does not exist, etc. OR error: cannot find symbol class SparseArrayCompat, error: package Pools does not exist, error: cannot find symbol variable ExifInterface, which when checked in the error file has to do with import android.support.v4.util.ArrayMap;-import kind of statements.

My android/build.gradle file:

buildscript {
    ext {
        minSdkVersion = 26
        compileSdkVersion = 28
        targetSdkVersion = 27
        supportLibVersion = 28
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
    }
}

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

tasks.withType(Wrapper) {
    gradleVersion = "4.10.1"
    distributionUrl = distributionUrl.replace("bin", "all")
}

My app/build.gradle file:

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
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.helloworld"
        minSdkVersion 26
        targetSdkVersion 28
        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"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3]
            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
            }
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation (project(':react-native-camera')) {
        exclude group: 'com.google.android.gms'
        exclude group: "com.android.support"
        implementation 'com.android.support:exifinterface:28.0.0'
        implementation ('com.google.android.gms:play-services-vision:12.0.1') {
            force = true
        }
    }
    implementation project(':react-native-orientation')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-linear-gradient')
    implementation project(':react-native-spinkit')
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation ('com.facebook.react:react-native:0.58.3')
    implementation "com.android.support:support-v4:28.0.0"
    //implementation "androidx.legacy:legacy-support-v4:1.0.0"
}

My attempt at solution:

  • I added android-support-v4.jar file to the ./libs folder.
  • I added "google()" or maven links to the dependencies.
  • I tried changing minSdkVersion, compileVersion, etc, didn't help, but I guess this might be the main problem.
  • Rebuilding the project didn't work too.
  • Migrating project to Android X.

My SDK version: 28

Gradle version: 4.10.1

classpath 'com.android.tools.build:gradle:3.3.1' (Downgrading gradle version to 3.1.0 didn't work).

How can i conditionally add any specific React Package at runtime?

$
0
0

I have a few existing React Packages which are added as library to my current react native app.

Now, one of the packages, needs to be added only if certain condition follows:

Condition : If 'isXPackageRequired' is true, then only it should be added as list of react packages. But this property is in javascript code and should only be read from redux store.

Following is the code where i am adding react packages:

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() {
      List<ReactPackage> reactPackages = Arrays.<ReactPackage>asList(
              new MainReactPackage(),
              ...,// Some other Packages
             );
     // Here how can i get that redux variable to conditionally include myXPackage
      if(**CONDITION WITH JAVASCRIPT VARIABLE:isXPackageRequired**){
         reactPackageList.add(new MyXPackage());
      }
   }
}

OR, is there any other place where i can remove this package if already added and how?

I could have read from buildConfig if it would have been static or environment based, but the ask is at the runtime and if we have the desired property in our redux-store.

I have researched a lot but with no luck. Any elegant solution will be much appreciated.

Thanks in advance.

IllegalStateExceptioncom.swmansion.gesturehandler.GestureHandler in prepare

$
0
0

I'm facing some random crash in production on Android. Here is the logcat give me that:

2019-11-20 15:00:09.752 3248-3248/? E/InputEventReceiver: Exception dispatching input event.
2019-11-20 15:00:09.752 3248-3248/? E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
2019-11-20 15:00:09.774 3248-3248/? E/MessageQueue-JNI: java.lang.IllegalStateException: Already prepared or hasn't been reset
        at com.swmansion.gesturehandler.GestureHandler.prepare(GestureHandler.java:178)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.recordHandlerIfNotPresent(GestureHandlerOrchestrator.java:379)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.recordViewHandlersForPointer(GestureHandlerOrchestrator.java:389)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:466)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:403)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.onTouchEvent(GestureHandlerOrchestrator.java:97)
        at com.swmansion.gesturehandler.react.RNGestureHandlerRootHelper.dispatchTouchEvent(RNGestureHandlerRootHelper.java:121)
        at com.swmansion.gesturehandler.react.RNGestureHandlerRootView.dispatchTouchEvent(RNGestureHandlerRootView.java:36)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
        at com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView.dispatchTouchEvent(RNGestureHandlerEnabledRootView.java:39)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dis
2019-11-20 15:00:09.776 3248-3248/? D/AndroidRuntime: Shutting down VM
2019-11-20 15:00:09.783 3248-3248/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.evolum, PID: 3248
    java.lang.IllegalStateException: Already prepared or hasn't been reset
        at com.swmansion.gesturehandler.GestureHandler.prepare(GestureHandler.java:178)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.recordHandlerIfNotPresent(GestureHandlerOrchestrator.java:379)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.recordViewHandlersForPointer(GestureHandlerOrchestrator.java:389)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:466)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:422)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:464)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:403)
        at com.swmansion.gesturehandler.GestureHandlerOrchestrator.onTouchEvent(GestureHandlerOrchestrator.java:97)
        at com.swmansion.gesturehandler.react.RNGestureHandlerRootHelper.dispatchTouchEvent(RNGestureHandlerRootHelper.java:121)
        at com.swmansion.gesturehandler.react.RNGestureHandlerRootView.dispatchTouchEvent(RNGestureHandlerRootView.java:36)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
        at com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView.dispatchTouchEvent(RNGestureHandlerEnabledRootView.java:39)
2019-11-20 15:00:09.785 3248-3248/? E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
        at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:440)
        at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1830)
        at android.app.Activity.dispatchTouchEvent(Activity.java:3400)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
        at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:398)
        at android.view.View.dispatchPointerEvent(View.java:12752)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5106)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4909)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4585)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4642)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7092)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7061)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7022)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7195)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:326)
        at android.os.Looper.loop(Looper.java:160)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Index.js:

import { AppRegistry, StatusBar, YellowBox } from 'react-native';
import { name as appName } from './app.json';
import App from './src/App';

StatusBar.setHidden(true);
YellowBox.ignoreWarnings(['-[RCTRootView cancelTouches]` is deprecated and will be deleted soon.']);
AppRegistry.registerComponent(appName, () => App);

App.js:

import React from 'react';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
...
export default gestureHandlerRootHOC(App);

My environment: react: 16.9.0 react-native: 0.61.4 react-native-gesture-handler: ^1.5.0

JS error:

enter image description here

If someone can help me to avoid this crash and the error message when I reload that can be really nice.

thanks, Youcef

TypeError: null is not an object (evaluating 'RNGestureHandlerModule.default.Direction')

$
0
0

I have problem with module 'react-navigation-stack' I've written the same code from https://facebook.github.io/react-native/docs/navigation#react-navigation. Platform: Android. OS: ubuntu

import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import SearchScreen from './scr/screen/SearchScreen';

const navigator = createStackNavigator(
    {
        Search: SearchScreen
    },
    {
        initialRouteName: 'Search',
        defaultNavigationOptions: {
            title: 'App'
        }
    }
);
const App = createAppContainer(navigator);
export default App;

enter image description here

React Native Facebook SDK Initialization on Android

$
0
0

I am integrating the Faecbook SDK into an existing react-native project and having the dreaded error: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.

I have followed the instructions carefully, so strings.xml contains:

<string name="facebook_app_id">xxxxx</string>

And in AndroidManifest.xml, inside the application element, I have

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

I've made the changes to settings.gradle and build.xml as described.

All the instructions say that I shouldn't need to call FacebookSdk.sdkInitialize() if I have done the above. I'm using react-native-fbsdk version 1.1.1 and react native 0.60.5

When I followed the instructions on a simple new react-native project it works, so I am wondering if it is a conflict with something in the app, but I'm not sure what to look for. Can anyone suggest how to debug?

Thanks.

React-native use react-native-vector-icons in android module

$
0
0

I'm writing a module for react-native that should run on android, I have to do so to take a react-native-vector-icons and switch it to the module to be able to use them as a Drawable image.

To use the type of icons: FontAwesome, Entypo, Ionicons, MaterialIcons and etc.

I found something like that, but I did not understand how it works or how to make it work in my case.

Link: here

@TargetApi(21)
  private Drawable generateVectorIcon(ReadableMap icon) {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    String family = icon.getString("family");
    String name = icon.getString("name");
    String glyph = icon.getString("glyph");
    String color = icon.getString("color");
    int size = icon.getInt("size");

    if (name != null && name.length() > 0 && name.contains(".")) {
      Resources resources = getReactApplicationContext().getResources();
      name = name.substring(0, name.lastIndexOf("."));

      final int resourceId = resources.getIdentifier(name, "drawable", getReactApplicationContext().getPackageName());
      return getReactApplicationContext().getDrawable(resourceId);
    }

    float scale = getReactApplicationContext().getResources().getDisplayMetrics().density;
    String scaleSuffix = "@" + (scale == (int) scale ? Integer.toString((int) scale) : Float.toString(scale)) + "x";
    int fontSize = Math.round(size * scale);

    Typeface typeface = ReactFontManager.getInstance().getTypeface(family, 0, getReactApplicationContext().getAssets());
    Paint paint = new Paint();
    paint.setTypeface(typeface);
    paint.setColor(Color.parseColor(color));
    paint.setTextSize(fontSize);
    paint.setAntiAlias(true);
    Rect textBounds = new Rect();
    paint.getTextBounds(glyph, 0, glyph.length(), textBounds);

    Bitmap bitmap = Bitmap.createBitmap(textBounds.width(), textBounds.height(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawText(glyph, -textBounds.left, -textBounds.top, paint);

    return new BitmapDrawable(getReactApplicationContext().getResources(), bitmap);
  }

Some advice?

React native, detect screen resume

$
0
0

Suppose you navigate like the following

screen-a (initial)
screen-b (push)
screen-a (pop)

I think in android, we could use onResume of an activity to track the screens

Is there something like onResume in react-native?

I'm not talking about application status, I'm after individual view (which would be something like Activity in android, ViewController in iOS)


How to deploy react-native application from Intellij IDEA (Ultimate) to Microsoft Emulator?

$
0
0

Android SDK emulator is not compatible with Hyper-V (which is required on Windows to run Docker). I have installed Microsoft Emulator instead as I do need Docker as well. When I start the emulator, and then run the project from Intellij, I end up with:

:app:installDebug Skipping device 'emulator-5580' (emulator-5580): Device is OFFLINE. :app:installDebug FAILED

BUILD FAILED

Total time: 2 mins 2.478 secs

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:installDebug'.

    com.android.builder.testing.api.DeviceException: No online devices found.

How do I deploy react-native app from Intellij to Microsoft Emulator?

USB Camera to conect in android phone

$
0
0

I need the development of an application mobile to take pictures. But the camera is external so that it will be connected by usb cable in the tablet android.

What the better technology to create this app?

I did not find the solution for this to react native and Cordova.

How do you debug React Native?

$
0
0

How does one debug their React code with React Native while the app is running in app simulator?

Change package name for Android in React Native

$
0
0

I used react-native init MyApp to initialise a new React Native app. This created among others an Android project with the package com.myapp.

What's the best way to change this package name, for example to: com.mycompany.myapp?

I tried changing it in AndroidManifest.xml but it created other errors, so I'm assuming it's not the way.

Any idea?

Image using uri as source not shown

$
0
0

I have a react native App which downloads images from external sources and saves them into dedicated local cache folder. Later they get displayed in different views. The images are initially not available in the app bundle.

<Image source={{uri: uri}} resizeMode="contain" style={style} />

I use the URI format for the source input parameter of Image component referring a local folder. I pass width and height as style as well, in fact the image size is always known before drawing. It works fine on iOS but not on Android.

As the documentation says, I should use require('') for local images on Android. This works for static images but not for downloaded on run time.

Has anybody idea how could I solve this issue?

Here is the code:

class CachedImage extends React.Component {
    state = {
        uri: null
    }

    async _handleCache(source) {        
        const path = `${RNFetchBlob.fs.dirs.CacheDir}${sha1(source.uri).toString()}.jpg`;        
        const exists = await RNFetchBlob.fs.exists(path);
        if (exists) {
            this.setState({uri: path});                
        } else {
            // encoding the file to preserve proper URL transmition
            await RNFetchBlob
                .config({path})
                .fetch("GET", source.uri, {});
            this.setState({uri: path});
        }
    }

    componentWillMount() {
        this._handleCache(this.props.source).done();
    }

    render() {
        const { style } = this.props;

        if (this.state.uri != null) {            
            return (                
                <Image source={{uri: this.state.uri}} resizeMode="contain" style={style} />
            );
        }
        return(
            <View style={style}/> //todo: display activity while loading ...
        );
    }
}

Usage:

<CachedImage
   style={{width: _width , height: _height}}
   source={{uri: 'http://...'}} />
Viewing all 28476 articles
Browse latest View live


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