简体   繁体   English

使用 react-native run-android 运行时出现 React-Native 错误

[英]React-Native error when running with react-native run-android

I have some problems with React-Native.我对 React-Native 有一些问题。 I tried to change react-native version or edit build.gradle moving google() or jcenter(), but the error still persist.我尝试更改 react-native 版本或编辑 build.gradle 移动 google() 或 jcenter(),但错误仍然存在。

Can someone help me?有人能帮我吗? I think it's a problem of build.gradle, but I'm not sure.我认为这是build.gradle的问题,但我不确定。

Environment:环境:

React-Native : "^0.59.10" React-Native :“^0.59.10”

NodeJS : "v10.16.3" NodeJS :“v10.16.3”

project/android/build.gradle :项目/android/build.gradle

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

buildscript {
    ext {
        buildToolsVersion = "28.0.2"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "27.1.1"
    }
    repositories {
        jcenter()
        google()

        maven {
           url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        //classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.android.tools.build:gradle:3.4.1'

        // Check for v3.1.2 or higher
        classpath 'com.google.gms:google-services:4.3.0'  // Google Services plugin

        // Add dependency
        classpath 'io.fabric.tools:gradle:1.31.0'  // Crashlytics plugin

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

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

        //google()
    }
}


wrapper {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

project/android/app/src/build.gradle :项目/android/app/src/build.gradle

apply plugin: "com.android.application"
apply plugin: 'io.fabric'

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

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

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


project.ext.vectoricons = [
    iconFontNames: [ 'MaterialIcons.ttf', 'EvilIcons.ttf' ] // Name of the font files you want to copy
]

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "xxx"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        multiDexEnabled true
        versionCode 5
        versionName "1.0.4"
        ndk {
            abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_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 ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            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
            }
        }
    }
}

configurations.all { resolutionStrategy { force 'com.facebook.android:facebook-android-sdk:4.34.0' } }
dependencies {
    implementation project(':@react-native-community_async-storage')
    implementation project(':react-native-firebase')
    implementation project(':react-native-sensitive-info')
    implementation project(':react-native-iap')
    implementation project(':react-native-exit-app')
    implementation project(':react-native-splash-screen')
    implementation project(':@react-native-community_netinfo')
    implementation project(':react-native-android-location-enabler')
    implementation project(':lottie-react-native')
    implementation project(':react-native-restart')
    implementation project(':react-native-linear-gradient')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-android-location-services-dialog-box')
    implementation project(':react-native-geocoder')
    implementation project(':react-native-navigation')
    implementation project(':react-native-firebase')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation 'com.android.support:design:27.1.0'
    implementation "com.facebook.react:react-native:+"  // From node_modules

    implementation "com.google.android.gms:play-services-base:16.1.0"
    implementation "com.google.firebase:firebase-core:17.0.1"
    implementation 'com.google.firebase:firebase-auth:18.0.0'
    implementation 'com.google.firebase:firebase-database:18.0.0'

    // (Recommended) Add Analytics
    implementation 'com.google.firebase:firebase-analytics:17.0.1'

    // Add dependency
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'

    implementation 'androidx.multidex:multidex:2.0.0'


    //FOR GIF
    implementation 'com.facebook.fresco:fresco:2.1.0'

    // For animated GIF support
    implementation 'com.facebook.fresco:animated-gif:1.+'

    // For WebP support, including animated WebP
    implementation 'com.facebook.fresco:animated-webp:1.+'
    implementation 'com.facebook.fresco:webpsupport:1.+' 



}

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

configurations.all {
    resolutionStrategy {
        force "com.airbnb.android:lottie:2.5.5"
      }
    }

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

Here's the output of the error:这是错误的output:

* What went wrong:
Could not determine the dependencies of task ':app:preReleaseBuild'.
> Could not resolve all task dependencies for configuration ':app:releaseRuntimeClasspath'.
   > Could not resolve com.facebook.fresco:fresco:2.1.0.
     Required by:
         project :app
      > Could not resolve com.facebook.fresco:fresco:2.1.0.
         > Could not get resource 'http://jcenter.bintray.com/com/facebook/fresco/fresco/2.1.0/fresco-2.1.0.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/facebook/fresco/fresco/2.1.0/fresco-2.1.0.pom'. Received status code 403 from server: Forbidden
   > Could not resolve com.facebook.fresco:animated-gif:1.+.
     Required by:
         project :app
      > Failed to list versions for com.facebook.fresco:animated-gif.
         > Unable to load Maven meta-data from http://jcenter.bintray.com/com/facebook/fresco/animated-gif/maven-metadata.xml.
            > Could not get resource 'http://jcenter.bintray.com/com/facebook/fresco/animated-gif/maven-metadata.xml'.
               > Could not GET 'http://jcenter.bintray.com/com/facebook/fresco/animated-gif/maven-metadata.xml'. Received status code 403 from server: Forbidden
   > Could not resolve com.facebook.fresco:animated-webp:1.+.
     Required by:
         project :app
      > Failed to list versions for com.facebook.fresco:animated-webp.
         > Unable to load Maven meta-data from http://jcenter.bintray.com/com/facebook/fresco/animated-webp/maven-metadata.xml.
            > Could not get resource 'http://jcenter.bintray.com/com/facebook/fresco/animated-webp/maven-metadata.xml'.
               > Could not GET 'http://jcenter.bintray.com/com/facebook/fresco/animated-webp/maven-metadata.xml'. Received status code 403 from server: Forbidden
   > Could not resolve com.facebook.fresco:webpsupport:1.+.
     Required by:
         project :app
      > Failed to list versions for com.facebook.fresco:webpsupport.
         > Unable to load Maven meta-data from http://jcenter.bintray.com/com/facebook/fresco/webpsupport/maven-metadata.xml.
            > Could not get resource 'http://jcenter.bintray.com/com/facebook/fresco/webpsupport/maven-metadata.xml'.
               > Could not GET 'http://jcenter.bintray.com/com/facebook/fresco/webpsupport/maven-metadata.xml'. Received status code 403 from 
server: Forbidden
   > Could not resolve com.android.billingclient:billing:1.1.
     Required by:
         project :app > project :react-native-iap
      > Could not resolve com.android.billingclient:billing:1.1.
         > Could not get resource 'http://jcenter.bintray.com/com/android/billingclient/billing/1.1/billing-1.1.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/android/billingclient/billing/1.1/billing-1.1.pom'. Received status code 403 from 
server: Forbidden
   > Could not resolve com.airbnb.android:lottie:2.5.5.
     Required by:
         project :app > project :lottie-react-native
      > Could not resolve com.airbnb.android:lottie:2.5.5.
         > Could not get resource 'http://jcenter.bintray.com/com/airbnb/android/lottie/2.5.5/lottie-2.5.5.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/airbnb/android/lottie/2.5.5/lottie-2.5.5.pom'. Received status code 403 from server: Forbidden
   > Could not resolve com.aurelhubert:ahbottomnavigation:2.0.6.
     Required by:
         project :app > project :react-native-navigation
      > Could not resolve com.aurelhubert:ahbottomnavigation:2.0.6.
         > Could not get resource 'http://jcenter.bintray.com/com/aurelhubert/ahbottomnavigation/2.0.6/ahbottomnavigation-2.0.6.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/aurelhubert/ahbottomnavigation/2.0.6/ahbottomnavigation-2.0.6.pom'. Received status code 403 from server: Forbidden
   > Could not resolve com.balysv.materialmenu:material-menu-toolbar:1.5.4.
     Required by:
         project :app > project :react-native-navigation
      > Could not resolve com.balysv.materialmenu:material-menu-toolbar:1.5.4.
         > Could not get resource 'http://jcenter.bintray.com/com/balysv/materialmenu/material-menu-toolbar/1.5.4/material-menu-toolbar-1.5.4.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/balysv/materialmenu/material-menu-toolbar/1.5.4/material-menu-toolbar-1.5.4.pom'. 
Received status code 403 from server: Forbidden
   > Could not resolve com.facebook.infer.annotation:infer-annotation:0.11.2.
     Required by:
         project :app > com.facebook.react:react-native:0.59.10
      > Could not resolve com.facebook.infer.annotation:infer-annotation:0.11.2.
         > Could not get resource 'http://jcenter.bintray.com/com/facebook/infer/annotation/infer-annotation/0.11.2/infer-annotation-0.11.2.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/facebook/infer/annotation/infer-annotation/0.11.2/infer-annotation-0.11.2.pom'. Received status code 403 from server: Forbidden
   > Could not resolve javax.inject:javax.inject:1.
     Required by:
         project :app > com.facebook.react:react-native:0.59.10
      > Could not resolve javax.inject:javax.inject:1.
         > Could not get resource 'http://jcenter.bintray.com/javax/inject/javax.inject/1/javax.inject-1.pom'.
            > Could not GET 'http://jcenter.bintray.com/javax/inject/javax.inject/1/javax.inject-1.pom'. Received status code 403 from server: Forbidden
   > Could not resolve com.facebook.fresco:fresco:2.1.0.
     Required by:
         project :app > com.facebook.react:react-native:0.59.10
      > Could not resolve com.facebook.fresco:fresco:2.1.0.
         > Could not get resource 'http://jcenter.bintray.com/com/facebook/fresco/fresco/2.1.0/fresco-2.1.0.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/facebook/fresco/fresco/2.1.0/fresco-2.1.0.pom'. Received status code 403 from server: Forbidden
   > Could not resolve com.facebook.fresco:imagepipeline-okhttp3:1.10.0.
     Required by:
         project :app > com.facebook.react:react-native:0.59.10
      > Could not resolve com.facebook.fresco:imagepipeline-okhttp3:1.10.0.
         > Could not get resource 'http://jcenter.bintray.com/com/facebook/fresco/imagepipeline-okhttp3/1.10.0/imagepipeline-okhttp3-1.10.0.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/facebook/fresco/imagepipeline-okhttp3/1.10.0/imagepipeline-okhttp3-1.10.0.pom'. Received status code 403 from server: Forbidden
   > Could not resolve com.facebook.soloader:soloader:0.6.0.
     Required by:
         project :app > com.facebook.react:react-native:0.59.10
      > Could not resolve com.facebook.soloader:soloader:0.6.0.
         > Could not get resource 'http://jcenter.bintray.com/com/facebook/soloader/soloader/0.6.0/soloader-0.6.0.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/facebook/soloader/soloader/0.6.0/soloader-0.6.0.pom'. Received status code 403 from server: Forbidden
   > Could not resolve com.google.code.findbugs:jsr305:3.0.2.
     Required by:
         project :app > com.facebook.react:react-native:0.59.10
      > Could not resolve com.google.code.findbugs:jsr305:3.0.2.
         > Could not get resource 'http://jcenter.bintray.com/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.pom'. Received status code 403 from server: Forbidden
   > Could not resolve com.squareup.okhttp3:okhttp:3.12.1.
     Required by:
         project :app > com.facebook.react:react-native:0.59.10
      > Could not resolve com.squareup.okhttp3:okhttp:3.12.1.
         > Could not get resource 'http://jcenter.bintray.com/com/squareup/okhttp3/okhttp/3.12.1/okhttp-3.12.1.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/squareup/okhttp3/okhttp/3.12.1/okhttp-3.12.1.pom'. Received status code 403 from server: Forbidden
   > Could not resolve com.squareup.okhttp3:okhttp-urlconnection:3.12.1.
     Required by:
         project :app > com.facebook.react:react-native:0.59.10
      > Could not resolve com.squareup.okhttp3:okhttp-urlconnection:3.12.1.
         > Could not get resource 'http://jcenter.bintray.com/com/squareup/okhttp3/okhttp-urlconnection/3.12.1/okhttp-urlconnection-3.12.1.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/squareup/okhttp3/okhttp-urlconnection/3.12.1/okhttp-urlconnection-3.12.1.pom'. Received status code 403 from server: Forbidden
   > Could not resolve com.squareup.okio:okio:1.15.0.
     Required by:
         project :app > com.facebook.react:react-native:0.59.10
      > Could not resolve com.squareup.okio:okio:1.15.0.
         > Could not get resource 'http://jcenter.bintray.com/com/squareup/okio/okio/1.15.0/okio-1.15.0.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/squareup/okio/okio/1.15.0/okio-1.15.0.pom'. Received status code 403 from server: 
Forbidden
   > Could not resolve com.google.auto.value:auto-value-annotations:1.6.3.
     Required by:
         project :app > com.google.firebase:firebase-auth:18.0.0 > com.google.firebase:firebase-common:18.0.0
      > Could not resolve com.google.auto.value:auto-value-annotations:1.6.3.
         > Could not get resource 'http://jcenter.bintray.com/com/google/auto/value/auto-value-annotations/1.6.3/auto-value-annotations-1.6.3.pom'.
            > Could not GET 'http://jcenter.bintray.com/com/google/auto/value/auto-value-annotations/1.6.3/auto-value-annotations-1.6.3.pom'. 
Received status code 403 from server: Forbidden

* 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.

The error clearly states that fresco library is missing in android, please add those in your gradle file manually https://github.com/facebook/fresco and your issue will be fixed, if you're adding any library do not forget to link it.该错误明确指出android中缺少 fresco 库,请在 gradle 文件中手动添加这些库它。 And one advice move to latest version of react-native.一个建议转移到最新版本的 react-native。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM