简体   繁体   中英

react-native run-android fails

Since I've upgraded to react-native 0.42.0, I can't run my app anymore.

I've got a weird issue where instead of getting react-native from node_modules, gradle will get the old version 0.21 from maven repository. I've tried freezing the version, suppressing everything build or cache related and I've even start fresh by copying only js files. But I still encounter errors related to gradle not looking in node_modules for react-native.

Here's my settings.gradle :

rootProject.name = 'My App'

include ':app'
include ':react-native-google-analytics-bridge'
project(':react-native-google-analytics-bridge').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-analytics-bridge/android')

and my app's build.gradle dependencies :

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:0.42.0"  // From node_modules
    compile "com.facebook.fresco:animated-gif:0.11.0"
    compile project(':react-native-google-analytics-bridge')
}

and finally the project build.gradle:

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

allprojects {
    repositories {
        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 "http://private-repos"
        }
    }
}

Any clue ?

Try to check the package.json and see what's in there.

If you find the old version there, you can change it then run npm install or just run npm install --save react-native@<the-desired-version>

If you get an error that you need to upgrade react then run npm install --save react@<needed-version>

In my case I had to use this alternative because the standard one(based on git) didn't work.

More details about this alternative and the standard one here: https://facebook.github.io/react-native/docs/upgrading.html

Found out the problem :

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

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

You have to create a maven section for each url you want to add. It never even throws an error when you specify it like I did first, it simply ignores the first url.
Hours lost because of improper logging ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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