简体   繁体   English

react-native运行android失败

[英]react-native run-android fails

Since I've upgraded to react-native 0.42.0, I can't run my app anymore. 由于我已经升级到react-native 0.42.0,因此无法运行我的应用程序。

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. 我有一个奇怪的问题,那就是gradle将从maven存储库中获取旧版本0.21,而不是从node_modules获得react-native。 I've tried freezing the version, suppressing everything build or cache related and I've even start fresh by copying only js files. 我尝试冻结该版本,禁止所有与构建或缓存相关的事情,甚至还只复制了js文件就重新开始了。 But I still encounter errors related to gradle not looking in node_modules for react-native. 但是我仍然遇到与gradle不在node_modules中寻找react-native相关的错误。

Here's my settings.gradle : 这是我的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 : 和我的应用程序的build.gradle依赖项:

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: 最后是项目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. 尝试检查package.json并查看其中的内容。

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> 如果在那里找到旧版本,则可以对其进行更改,然后运行npm install或仅运行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> 如果遇到需要升级的错误,请运行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. 在我的情况下,我不得不使用这种替代方法,因为标准的(基于git)无法使用。

More details about this alternative and the standard one here: https://facebook.github.io/react-native/docs/upgrading.html 有关此替代方法和标准替代方法的更多详细信息,请参见: 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. 您必须为要添加的每个URL创建一个Maven部分。 It never even throws an error when you specify it like I did first, it simply ignores the first url. 当像我一样指定它时,它甚至都不会抛出错误,它只会忽略第一个URL。
Hours lost because of improper logging ... 由于记录不当而浪费了数小时...

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

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