gpt4 book ai didi

android - react-native 链接导致 Android settings.gradle 中的重复导入

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:26 25 4
gpt4 key购买 nike

出于某种原因,当我调用 react-native link , 它将重复包含添加到 android/settings.gradle这又将重复导入添加到 android/app/src/main/com/<projectName>/MainApplication.java .

它并不总是这样做。当我手动添加一个特定的包时它开始这样做,因为有些东西不起作用,但我不记得是哪个。

我的直觉是react-native link假定包以某种顺序列出——它看起来像反向字母顺序——但由于 npm 包名称不一定与 settings.gradle 中的包含项目名称匹配这与 MainApplication.java 中的导入名称不匹配, 我很难弄清楚如何在 settings.gradle 中重新排序它们为了阻止这种行为。或者它可能完全是其他东西。

package.json

{
// ...
"dependencies": {
"events": "^1.1.1",
"flux": "^3.1.2",
"react": "~15.4.1",
"react-native": "0.42.0",
"react-native-datepicker": "^1.4.4",
"react-native-fs": "^2.1.0-rc.1",
"react-native-navigation": "^1.0.30",
"react-native-push-notification": "^2.2.1",
"react-native-sound": "^0.9.1",
"react-native-vector-icons": "^4.0.0",
"redux": "^3.6.0"
},
"devDependencies": {
"babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "19.0.2",
"react-test-renderer": "~15.4.1"
},
"jest": {
"preset": "react-native"
}
}

文件应该是这样的...

android/settings.gradle

rootProject.name = // <projectName>
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-sound'
project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
include ':react-native-push-notification'
project(':react-native-push-notification').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-push-notification/android')
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app')
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android')

include ':app'

android/app/src/main/com/[项目名称]/MainApplication.java

package // com.<projectName>;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.oblador.vectoricons.VectorIconsPackage;
import com.zmxv.RNSound.RNSoundPackage;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import com.reactnativenavigation.RnnPackage;
import com.rnfs.RNFSPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VectorIconsPackage(),
new RNSoundPackage(),
new ReactNativePushNotificationPackage(),
new RnnPackage(),
new RNFSPackage(),
);
}
};

@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}

@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}

在我运行 react-native link 之后,文件更改为:

android/settings.gradle

rootProject.name = // <projectName>
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-sound'
project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
include ':react-native-push-notification'
project(':react-native-push-notification').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-push-notification/android')
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app')
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android')
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-sound'
project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
include ':react-native-push-notification'
project(':react-native-push-notification').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-push-notification/android')
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app')
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android')

include ':app'

android/app/src/main/com/[项目名称]/MainApplication.java

// ...
import com.facebook.react.ReactApplication;
import com.oblador.vectoricons.VectorIconsPackage;
import com.zmxv.RNSound.RNSoundPackage;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import com.reactnativenavigation.RnnPackage;
import com.rnfs.RNFSPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.zmxv.RNSound.RNSoundPackage;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import com.reactnativenavigation.RnnPackage;
import com.rnfs.RNFSPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VectorIconsPackage(),
new RNSoundPackage(),
new ReactNativePushNotificationPackage(),
new RnnPackage(),
new RNFSPackage(),
new VectorIconsPackage(),
new RNSoundPackage(),
new ReactNativePushNotificationPackage(),
new RnnPackage(),
new RNFSPackage(),
);
}
};

// ...

如果我运行 react-native-link再次,它添加了包的第三个副本。

有没有人知道如何react-native link有用吗?

最佳答案

这是 React Native 上的一个已知错误。目前有一个 PR 正在等待此错误:https://github.com/facebook/react-native/pull/18131

更新:错误已修复!

要解决此问题,您只需在运行 react-native-link 时手动梳理依赖项。我发现在运行它之前拥有一个干净的 git status 是很有帮助的,然后在之后使用 git diff 检查更改的文件。

关于android - react-native 链接导致 Android settings.gradle 中的重复导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43032841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com