react-native build-android:“找不到react-native.jar”

时间:2019-08-21 12:52:35

标签: react-native react-native-android expo

我目前正在尝试在运行Mojave的Mac上为Android构建我的React Native项目(使用ExpoKit和几个本机模块)。在iOS上运行正常。但是,我在运行react-native run-android时得到Could not find react-native.jar。它正在react-native-33.0.0.jar中寻找file:/Users/username/Documents/Projekte/appname/app/node_modules/expokit/maven/com/facebook/react/react-native/33.0.0/文件,但是它不存在。

这是react-native信息的输出:

  React Native Environment Info:
    System:
      OS: macOS 10.14.6
      CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
      Memory: 312.45 MB / 8.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.15.1 - /usr/local/bin/node
      npm: 6.4.1 - /usr/local/bin/npm
    SDKs:
      iOS SDK:
        Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
      Android SDK:
        API Levels: 28, 29
        Build Tools: 28.0.3, 29.0.2
        System Images: android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.5 AI-191.8026.42.35.5791312
      Xcode: 10.3/10G8 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz => 0.59.8
    npmGlobalPackages:
      react-native-cli: 2.0.1

还有我在android / app中的build.gradle文件:

buildscript {
  repositories {
    google()
    maven { url 'https://maven.fabric.io/public' }
  }

  dependencies {
    classpath 'io.fabric.tools:gradle:1.26.1'
  }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'devicefarm'

repositories {
  maven { url 'https://maven.fabric.io/public' }
}

def safeExtGet(prop, fallback) {
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
  compileSdkVersion safeExtGet("compileSdkVersion", 28)

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  defaultConfig {
    applicationId 'de.teledoctor24.android'
    minSdkVersion safeExtGet("minSdkVersion", 21)
    targetSdkVersion safeExtGet("targetSdkVersion", 28)
    versionCode 1
    versionName '1.0.2'
    ndk {
      abiFilters 'armeabi-v7a', 'x86'
    }
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    // Deprecated. Used by net.openid:appauth
    manifestPlaceholders = [
        'appAuthRedirectScheme': 'host.exp.exponent'
    ]
  }
  dexOptions {
    javaMaxHeapSize System.getenv("DISABLE_DEX_MAX_HEAP") ? null : "8g"
  }

  signingConfigs {
    debug {
      storeFile file('../debug.keystore')
    }
    release {
      storeFile file(System.getenv("ANDROID_KEYSTORE_PATH") ?: "release-key.jks")
      storePassword System.getenv("ANDROID_KEYSTORE_PASSWORD")
      keyAlias System.getenv("ANDROID_KEY_ALIAS")
      keyPassword System.getenv("ANDROID_KEY_PASSWORD")
    }
  }
  buildTypes {
    debug {
      debuggable true
      ext.enableCrashlytics = false
    }
    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      signingConfig signingConfigs.release
    }
  }
  lintOptions {
    abortOnError false
  }
  packagingOptions {
    pickFirst "**"
  }
}

devicefarm {
  projectName System.getenv("DEVICEFARM_PROJECT_NAME")
  devicePool System.getenv("DEVICEFARM_DEVICE_POOL")
  executionTimeoutMinutes 40
  authentication {

    accessKey System.getenv("AWS_ACCESS_KEY_ID")
    secretKey System.getenv("AWS_SECRET_ACCESS_KEY")
  }
}

configurations.all {
  resolutionStrategy {
    force 'org.webkit:android-jsc:r241213'
  }
}

// WHEN_PREPARING_SHELL_REMOVE_FROM_HERE

apply from: 'expo.gradle'

// WHEN_PREPARING_SHELL_REMOVE_TO_HERE

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

dependencies {
    implementation project(':tipsi-stripe')
    implementation project(':react-native-twilio-video-webrtc')
    implementation project(':react-native-onesignal')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-randombytes')
  implementation fileTree(dir: 'libs', include: ['*.jar'])

  implementation 'com.android.support:multidex:1.0.1'

  // Our dependencies
  implementation "com.android.support:appcompat-v7:$supportLibVersion"

  // Our dependencies from ExpoView
  // DON'T ADD ANYTHING HERE THAT ISN'T IN EXPOVIEW. ONLY COPY THINGS FROM EXPOVIEW TO HERE.
  implementation "com.android.support:appcompat-v7:$supportLibVersion"
  implementation 'com.facebook.android:facebook-android-sdk:5.0.1'
  implementation('com.facebook.android:audience-network-sdk:5.1.1') {
    exclude module: 'play-services-ads'
  }
  compileOnly 'org.glassfish:javax.annotation:3.1.1'
  implementation 'com.jakewharton:butterknife:9.0.0'
  implementation 'de.greenrobot:eventbus:2.4.0'

  implementation 'com.squareup.picasso:picasso:2.5.2'
  implementation 'com.google.android.gms:play-services-gcm:15.0.1'
  implementation 'com.google.android.gms:play-services-analytics:16.0.1'
  implementation 'com.google.android.gms:play-services-maps:15.0.1'
  implementation 'com.google.android.gms:play-services-auth:15.0.1'
  implementation 'com.google.android.gms:play-services-location:15.0.1'
  implementation 'com.google.android.gms:play-services-ads:15.0.1'
  annotationProcessor 'com.raizlabs.android:DBFlow-Compiler:2.2.1'
  implementation "com.raizlabs.android:DBFlow-Core:2.2.1"
  implementation "com.raizlabs.android:DBFlow:2.2.1"
  implementation "com.madgag.spongycastle:core:1.53.0.0"
  implementation "com.madgag.spongycastle:prov:1.53.0.0"
  debugImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
  // debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
  releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
  implementation 'com.facebook.device.yearclass:yearclass:2.1.0'
  implementation 'commons-io:commons-io:1.4'
  implementation 'me.leolin:ShortcutBadger:1.1.4@aar'
  implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
  implementation 'commons-codec:commons-codec:1.10'
  implementation 'com.segment.analytics.android:analytics:4.3.0'
  implementation 'com.google.zxing:core:3.3.3'
  implementation 'net.openid:appauth:0.4.1'
  implementation 'com.airbnb.android:lottie:2.5.6'
  implementation('io.nlopez.smartlocation:library:3.2.11') {
    transitive = false
  }
  implementation "com.android.support:exifinterface:${safeExtGet("supportLibVersion", "28.0.0")}"
  implementation 'com.squareup.okio:okio:1.9.0'
  implementation 'com.facebook.soloader:soloader:0.6.0'

  // expo-file-system
  implementation 'com.squareup.okhttp3:okhttp:3.10.0'
  implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.10.0'

  // Testing
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
  // We use a modified build of com.android.support.test:runner:1.0.1. Explanation in maven-test/README
  androidTestImplementation 'com.android.support.test:runner:1.0.1'
  androidTestImplementation "com.android.support:support-annotations:${safeExtGet("supportLibVersion", "28.0.0")}"
  androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.0'
  androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
  androidTestImplementation 'com.azimolabs.conditionwatcher:conditionwatcher:0.2'

  testImplementation 'junit:junit:4.12'
  testImplementation 'org.mockito:mockito-core:1.10.19'
  testImplementation 'org.robolectric:robolectric:3.8'
  testImplementation 'com.android.support.test:runner:1.0.2-alpha1'
  testImplementation 'com.android.support.test:rules:1.0.2-alpha1'


  implementation('host.exp.exponent:expoview:33.0.0@aar') {
    transitive = true
    exclude group: 'com.squareup.okhttp3', module: 'okhttp'
    exclude group: 'com.squareup.okhttp3', module: 'okhttp-urlconnection'
  }




  api 'org.webkit:android-jsc:r241213' // needs to be before react-native
  api 'com.facebook.react:react-native:33.0.0'




  addUnimodulesDependencies([
      modulesPaths : [
        '../../node_modules'
      ],
      configuration: 'api',
      target       : 'react-native',
      exclude      : [
        // You can exclude unneeded modules here.
        // By default we exclude FaceDetector
        // and Stripe payments APIs.
        'unimodules-face-detector-interface',
        'expo-face-detector',
        'expo-payments-stripe'

        // Adding a name here will also remove the package
        // from auto-generated BasePackageList.java
      ]
  ])

}

// This has to be down here for some reason
apply plugin: 'com.google.gms.google-services'

在构建react-native-randombytes模块时会发生问题。如果我将此模块注释掉,则其他错误(例如react-native-twilio-video-webrtc)也会发生相同的错误。这是确切的错误:

> Task :react-native-randombytes:javaPreCompileDebug FAILED

> Task :app:exponentPrebuildStep
Opening `/dev/tty` failed (6): Device not configured

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':react-native-randombytes:debugCompileClasspath'.
> Could not find react-native.jar (com.facebook.react:react-native:33.0.0).
  Searched in the following locations:
      file:/Users/username/Documents/Projekte/appname/app/node_modules/expokit/maven/com/facebook/react/react-native/33.0.0/react-native-33.0.0.jar

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

请在您的React-native文件中设置package.json版本。

package.json

"dependencies": {
...
"react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",

并删除npm.lock

然后rm -rf node_modules && npm install => expo start =>打开Android Studio =>构建