【问题标题】:Package is not running at xxx:yy React Native包未在 xxx:yy React Native 运行
【发布时间】:2018-01-23 21:19:49
【问题描述】:

在安装 react-native-fcm 后,我正在使用 react native 构建一个分离的 android 应用程序,但总是收到以下错误消息:

我的项目 gradle 如下所示:

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

buildscript {
  repositories {
    jcenter()
    google()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath 'com.google.gms:google-services:3.1.2'

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

allprojects {
  repositories {
    mavenLocal()
    jcenter()
    maven {
      // Point to local maven repository
      url "$rootDir/../.expo-source/android/maven"
    }
    maven { url "https://jitpack.io" }
    maven { url "https://maven.google.com" }
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
}

虽然我的 app/build.gradle 看起来像:

apply plugin: 'com.android.application'

android {
  compileSdkVersion 26
  buildToolsVersion '26.0.2'

  defaultConfig {
    applicationId "fi.x.y"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 2
    versionName "1.0.2"
    multiDexEnabled true
    ndk {
      abiFilters 'armeabi-v7a', 'x86'
    }
    manifestPlaceholders = [
      'appAuthRedirectScheme': 'fi.x.y'
    ]
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  dexOptions {
    javaMaxHeapSize "8g"
  }
  lintOptions {
    abortOnError false
  }
}

task exponentPrebuildStep(type: Exec) {
  workingDir '../../'

  if (System.getProperty('os.name').toLowerCase().contains('windows')) {
    commandLine 'cmd', '/c', '.\\.expo-source\\android\\detach-scripts\\prepare-detached-build.bat'
  } else {
    commandLine './.expo-source/android/detach-scripts/prepare-detached-build.sh'
  }
}
preBuild.dependsOn exponentPrebuildStep

repositories{
  flatDir{
    dirs "../../node_modules/react-native-background-geolocation/android/libs"
  }
  mavenLocal()
  maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile(project(':react-native-firebase')) {
        transitive = false
    }
    compile project(':react-native-vector-icons')
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:multidex:1.0.2'

  compile 'com.google.android.gms:play-services:11.8.0'
  compile 'com.google.android.gms:play-services-location:11.8.0'
  compile 'com.google.android.gms:play-services-places:11.8.0'
  compile 'com.google.android.gms:play-services-maps:11.8.0'
  compile 'com.google.android.gms:play-services-ads:11.8.0'

  compile('host.exp.exponent:expoview:22.0.0@aar') {
    exclude group: 'com.facebook.android', module: 'facebook-android-sdk'
    exclude group: 'com.facebook.android', module: 'audience-network-sdk'
    exclude group: 'io.nlopez.smartlocation', module: 'library'
    transitive = true
  }

  compile ('com.facebook.android:facebook-android-sdk:4.+')
  compile('com.facebook.android:audience-network-sdk:4.+') {
    exclude module: 'play-services-ads'
  }
  compile('io.nlopez.smartlocation:library:3.2.11') {
    transitive = false
  }
  compile(project(':react-native-background-geolocation')) {
    exclude group: 'com.google.android.gms', module: 'play-services-location'
  }
  compile(name: 'tslocationmanager', ext: 'aar') {
    exclude group: 'com.google.android.gms'
  }
  compile project(':react-native-fcm')
  compile 'com.google.firebase:firebase-core:11.8.0' //this decides your firebase SDK version

}

apply plugin: 'com.google.gms.google-services'

主要应用:

// Needed for `react-native link`
  public List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        // Add your own packages here!
        // TODO: add cool native modules
            new RNBackgroundGeolocation(),
            // Needed for `react-native link`
        // new MainReactPackage(),
            new RNFirebasePackage(),
            new VectorIconsPackage(),
            new RNFirebaseMessagingPackage(),
            new FIRMessagingPackage()

    );
  }

我正在点击此链接为 react native android 安装推送通知:https://github.com/evollu/react-native-fcm

我没有看到任何日志进入控制台日志,项目正在成功构建,但是当启动应用程序时出现带有错误消息的白屏 Package is not running at xxx:yy。

我之前没有这个问题,因为安装fcm库时出现冲突,我也不得不将所有google服务包都更改为11.8.0!

知道它会导致什么导致我无法打开我的应用程序!

【问题讨论】:

    标签: javascript android reactjs react-native firebase-cloud-messaging


    【解决方案1】:

    我之前也遇到过这个问题,试试这个:

    1. 确保您的笔记本电脑和手机在同一个 Wi-Fi 网络上。
    2. 在您的设备上打开您的 React Native 应用程序。你会看到一个红屏 出现错误打开应用内开发者菜单。(您所说的那个)

    3. 转到开发设置 → 调试设备的服务器主机。 (摇动设备)

    4. 输入您机器的 IP 地址和本地开发者的端口 服务器(例如 10.0.1.1:8081)。返回开发人员菜单并 选择重新加载 JS。

    我使用ipconfig查找我的IP并使用上述方法。

    我还建议转到您的平台工具并确保您已正确安装 adb。

    我实际上是通过创建一个新的 react native 项目发现它是这样的,并发现这解决了错误。

    注意:您可能会收到另一个错误,告诉您无法删除 x 文件路径。我在我的实践项目中进行了尝试,它奏效了。 * 风险自负。

    Debugging - React Native

    【讨论】:

    • 该应用程序根本没有打开,我无法摇晃,此时没有可用的菜单。我猜包有问题,我使用相同的网络 ip 都很好,在安装 fcm 库之前它可以正常工作
    • 出现红屏时,通常可以向下滚动并点击关闭按钮。你可以摇动屏幕,然后应该会出现菜单。您是否创建了一个新项目并检查您是否有同样的问题。当我尝试使用反应原生声音时,这也发生在我身上。有一些不兼容的问题,我通过卸载修复了它。重新安装。在我之后: cd android gradlew clean
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多