标签: react-native-android

在 React-Native AndroidManifest.xml 中访问环境变量

我是 React Native 的新手。手头的任务是在推送到 GitHub 时在 AndroidManifest.xml 中设置我的 Google API 密钥而不暴露它。我设置了一个名为 API_KEY的环境变量,但是我想在 .xml 中访问它,在尝试启动开发服务器时出现错误。

到目前为止,我尝试过:

android:value=${env.API_KEY}
android:value="${env.API_KEY}"
android:value="${API_KEY}"
Run Code Online (Sandbox Code Playgroud)

谢谢!

android react-native react-native-android

1
推荐指数
2
解决办法
2779
查看次数

在本机反应中未授予位置权限

我在寻找位置时遇到了一个小问题,这是我的代码

export default class  App extends React.Component{
  state = {
        location: null
    };

    findCoordinates = () => {
        Geolocation.getCurrentPosition(
            position => {
                const location = JSON.stringify(position);
                this.setState({ location });
            },
      error => Alert.alert(error.message),
      { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
    );
    };
  render(){
    return (
      <View style={styles.container}>
                <TouchableOpacity onPress={this.findCoordinates}>
                    <Text style={styles.welcome}>Find My Coords?</Text>
                    <Text>Location: {this.state.location}</Text>
                </TouchableOpacity>
            </View>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

他们显示未授予位置许可

react-native react-native-android

1
推荐指数
2
解决办法
5228
查看次数

使用多个帐户 React Native Google Signin

我有一个使用谷歌登录的本机应用程序。目前,我可以使用我的手机登录的谷歌帐户之一登录,但我需要为我的谷歌帐户堆栈中的另一个谷歌帐户执行OAuth,这是为了获取 API 访问权限 我需要二级帐户的 serverAuthToken

我用于谷歌登录的库 - https://github.com/react-native-community/google-signin

到目前为止我所做的:

const firebaseGoogleLogin = async () => {
    try {
      await GoogleSignin.hasPlayServices();
      const userInfo = await GoogleSignin.signIn();
      if (userInfo) {
        await storeToken(userInfo);
        // eslint-disable-next-line no-console
        console.log('User info retrieved during login', userInfo);
      }
      // create a new firebase credential with the token
      // eslint-disable-next-line max-len
      const credential = firebase.auth.GoogleAuthProvider.credential(userInfo.idToken, userInfo.accessToken);
      // login with credential
      // eslint-disable-next-line no-unused-vars
      const firebaseUserCredential = await firebase.auth().signInWithCredential(credential);
      console.log('Logged in')
    } catch (error) {
      if (error.code === …
Run Code Online (Sandbox Code Playgroud)

android google-signin react-native-android react-native-ios react-native-firebase

1
推荐指数
1
解决办法
2030
查看次数

错误:找不到符号 BuildConfig.DEBUG

我已经从世博会管理的项目退出到裸露的工作流项目。但是当我尝试运行该项目时,它会出错

E:\Mnor Project 1\ejected\android\app\src\main\java\com\minorproject\MainApplication.java:40: error: cannot find symbol
      return BuildConfig.DEBUG;
Run Code Online (Sandbox Code Playgroud)

这是我在 MainAplication.java 中的导入

package com.minorproject;

import android.app.Application;
import android.content.Context;
import android.net.Uri;

import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.minorproject.generated.BasePackageList;

import org.unimodules.adapters.react.ReactAdapterPackage;
import org.unimodules.adapters.react.ModuleRegistryAdapter;
import org.unimodules.adapters.react.ReactModuleRegistryProvider;
import org.unimodules.core.interfaces.Package;
import org.unimodules.core.interfaces.SingletonModule;
import expo.modules.constants.ConstantsPackage;
import expo.modules.permissions.PermissionsPackage;
import expo.modules.filesystem.FileSystemPackage;
import expo.modules.updates.UpdatesController;
Run Code Online (Sandbox Code Playgroud)

这是我在 MainActivity.java 中的输入

package com.minorproject;

import android.os.Bundle;

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

import expo.modules.splashscreen.SplashScreen;
import expo.modules.splashscreen.SplashScreenImageResizeMode;
Run Code Online (Sandbox Code Playgroud)

这是我的 package.json

{
  "expo": {
    "name": …
Run Code Online (Sandbox Code Playgroud)

android reactjs react-native react-native-android expo

1
推荐指数
1
解决办法
2130
查看次数

如何在 Actions.SCENE_KEY 中使用变量(反应本机路由器通量)

如果这是我忽略的简单事情,请原谅我。我对编程还很陌生,对 React 和 React Native 比较陌生。

我正在构建一个简单的导航抽屉。

抽屉显示一个 Menu 组件,该组件具有renderMenuItem(item)返回以下内容的函数。

<Button onPress={() => this._onItemSelect(item)} style={styles.navItem} >{item}</Button>
Run Code Online (Sandbox Code Playgroud)

它负责将正确标记的按钮返回给渲染函数。

我遇到的问题是当它发挥作用时onItemSelect

_onItemSelect(item) {
    //  handle action to render the new page!

    Actions.item      // Won't work
    //Actions.Page2     // Hardcoding the scene here won't work either
    );
Run Code Online (Sandbox Code Playgroud)

当按下按钮时,我无法让它实际显示新场景。如果我将场景硬编码到onPress()按钮中的函数中,我可以让它工作。例如:

<Button onPress={Actions.Page2} style={styles.navItem} >{item}</Button>
Run Code Online (Sandbox Code Playgroud)

显然,这行不通。我需要的是能够在任何一个函数、函数或函数中使用itemrenderMenuItem(item)onItemSelect(item)

谢谢你。自从昨晚试图弄清楚这个问题以来,我一直在绞尽脑汁。

react-native react-native-android react-native-router-flux

0
推荐指数
1
解决办法
1799
查看次数

react-native-maps 标记抛出和 IndexOutofBoundsException:索引 1 无效,大小为 0

我正在尝试让 react-native-maps 标记显示在我的 Android 设备上(它在 iOS 上运行良好)但它向我抛出 IndexOutofBoundsException: Invalid index 1, size is 0 error at render time。

http://i.imgur.com/owletnw.png

render() {
    const INITIAL_REGION = { latitude: 52.221835, longitude: 21.000896, latitudeDelta: 0.0922, longitudeDelta: 0.0421 };
    return (
        <MapView ref="map"
            showsUserLocation = { true }
            loadingEnabled = { true }
            showsTraffic = { false }
            showsBuildings = { false }
            style = { styles.map, {flex: 1} }
            initialRegion = { INITIAL_REGION }
        >
            <View style={{flex: 0.1, flexDirection: 'row', position: 'absolute', justifyContent: 'space-between', …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-android react-native-maps

0
推荐指数
1
解决办法
1659
查看次数

React Native 0.47删除了createJSModules方法的retrocompatibility

我有一个我编码的React Native原生桥接模块,正如您所知,React Native 版本0.47对这些进行了重大改变:

Remove unused createJSModules calls (ce6fb33, 53d5504) - @javache
Run Code Online (Sandbox Code Playgroud)

问题是,现在使用RN 0.47(或将来更高)的项目将不会编译,如果这个不赞成的overriden方法在MainApplication.javaAndroid模块的文件中,并且使用较低版本的项目如果不存在则不会编译.

如何使用我自己的本机模块与0.47以上的旧版本和新版本兼容?

javascript compatibility android react-native react-native-android

0
推荐指数
1
解决办法
345
查看次数

运行android时反应本机错误

当我第一次运行时,react-native run-android我得到了这个错误

Execution failed for task ':app:mergeDebugResources'.
> Error: java.util.concurrent.ExecutionException: java.lang.RuntimeException: AAPT process not ready to receive commands
Run Code Online (Sandbox Code Playgroud)

这是我的aapt错误与上面这样的日志

app:mergeDebugResources
AAPT err(Facade for 806023675): /usr/Android/Sdk/build-tools/23.0.1/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
AAPT err(Facade for 320379832): /usr/Android/Sdk/build-tools/23.0.1/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
AAPT err(Facade for 1789437959): /usr/Android/Sdk/build-tools/23.0.1/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: …
Run Code Online (Sandbox Code Playgroud)

aapt react-native-android

0
推荐指数
1
解决办法
644
查看次数

在linux中运行react-native-android时出错

在linux系统中工作时,在android上运行react-native时出现以下错误:

Error:java.util.concurrent.ExecutionException: java.lang.RuntimeException: AAPT process not ready to receive commands

Error:Execution failed for task ':app:mergeDebugResources'.
 Error: java.util.concurrent.ExecutionException: java.lang.RuntimeException: AAPT process not ready to receive commands
Run Code Online (Sandbox Code Playgroud)

我提到了所有的解决方案,但无法从中得到任何帮助

这是我的build.gradle(Project:newApp)文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // …
Run Code Online (Sandbox Code Playgroud)

java linux android react-native react-native-android

0
推荐指数
1
解决办法
660
查看次数

不变违规:requireNativeComponent:在UIManager中找不到“ RCTView”

当我从开发菜单启动远程js调试并在android模拟器中重新加载我的react-native应用时,会出现此错误:

Invariant Violation: requireNativeComponent: "RCTView" was not found in the UIManager.

This error is located at:
    in RCTView
    in Root
    in Styled(Root)
    in _default
    in Provider
    in StyleProvider
    in App
    in RCTView
    in RCTView
    in AppContainer
getNativeComponentAttributes
    43f126e6-e124-4b3e-b0e6-b141bfd6e007:28263:5
<unknown>
    43f126e6-e124-4b3e-b0e6-b141bfd6e007:13523:14
Object.exports.get
    43f126e6-e124-4b3e-b0e6-b141bfd6e007:21438:20
completeUnitOfWork
    43f126e6-e124-4b3e-b0e6-b141bfd6e007:20492:64
performUnitOfWork
    43f126e6-e124-4b3e-b0e6-b141bfd6e007:20598:30
renderRoot
    43f126e6-e124-4b3e-b0e6-b141bfd6e007:20618:28
performWorkOnRoot
    43f126e6-e124-4b3e-b0e6-b141bfd6e007:21020:268
performWork
    43f126e6-e124-4b3e-b0e6-b141bfd6e007:20995:7
requestWork
    43f126e6-e124-4b3e-b0e6-b141bfd6e007:20940:95
Run Code Online (Sandbox Code Playgroud)

react-native react-native-android

0
推荐指数
1
解决办法
855
查看次数