我从react原生导航v1切换到v2,在尝试与Android Studio同步文件时出现了这5个错误。
无法解析"的依赖项:app@debug/compileClasspath":无法解析项目:react本机导航。
无法解析"的依赖项:app@debugAndroidTest/compileClasspath":无法解析项目:react本机导航。
无法解析"的依赖项:app@debugUnitTest/compileClasspath":无法解析项目:react本机导航。
无法解析"的依赖项:app@release/compileClasspath":无法解析项目:react本机导航。
无法解析"的依赖项:app@releaseUnitTest/compileClasspath":无法解析项目:react本机导航。
我试图清除.iml文件和.inidea文件夹,使缓存无效并重新启动。
配置:天然反应:0.51.0,react本地导航:^2.4.0,安卓工作室:3.1.1
安卓build.gradle
buildscript {
repositories {
google()
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven { url 'https://jitpack.io' }
jcenter()
}
}
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 19
compileSdkVersion = 26
targetSdkVersion = 26
supportLibVersion = "26.1.0"
}
subprojects { subproject ->
afterEvaluate {
if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
android {
variantFilter { variant ->
def names = variant.flavors*.name
if (names.contains("reactNative55") || names.contains("reactNative56") || names.contains("reactNative57")) {
setIgnore(true)
}
}
}
}
}
}
应用程序构建.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.myapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
missingDimensionStrategy "RNN.reactNativeVersion", "reactNative51"
multiDexEnabled true
versionCode 723
versionName "1.72"
ndk {
abiFilters "armeabi-v7a", "x86"
}
versionNameSuffix '3'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
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]
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
}
}
}
productFlavors {
}
}
dependencies {
compile project(':react-native-appsflyer')
compile project(':react-native-text-input-reset')
compile project(':bugsnag-react-native')
compile project(':react-native-version-check')
compile project(':react-native-video')
compile project(':react-native-intercom')
compile project(':react-native-fast-image')
compile project(':react-native-device-info')
compile project(':react-native-rate')
compile(project(':react-native-firebase')) {
transitive = false
}
compile project(':react-native-fbsdk')
compile project(':react-native-linear-gradient')
implementation fileTree(dir: "libs", include: ["*.jar"])
compile 'com.facebook.android:facebook-android-sdk:4.29.0'
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
// From node_modules
compile 'com.facebook.fresco:animated-gif:1.3.0'
implementation project(':react-native-navigation')
// Firebase dependencies
compile 'com.google.android.gms:play-services-base:11.6.0'
compile 'com.google.firebase:firebase-core:11.6.0'
compile 'com.google.firebase:firebase-auth:11.6.0'
compile 'com.google.firebase:firebase-firestore:11.6.0'
compile(project(':react-native-maps')) {
exclude group: 'com.google.android.gms'
}
compile('com.google.android.gms:play-services-base:11.6.0') {
force = true;
}
compile('com.google.android.gms:play-services-maps:11.6.0') {
force = true;
}
compile('com.google.android.gms:play-services-gcm:11.6.0') {
force = true;
}
implementation "com.google.firebase:firebase-analytics:11.6.0"
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
implementation project(':react-native-fbsdk')
implementation "com.google.firebase:firebase-messaging:11.6.0"
implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
}
// 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'
}
apply plugin: 'com.google.gms.google-services'
主要活动.java
package com.myapp;
import com.reactnativenavigation.NavigationActivity;
import android.content.Intent;
import com.appsflyer.AppsFlyerLib;
import com.appsflyer.AppsFlyerConversionListener;
public class MainActivity extends NavigationActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
// @Override
// protected String getMainComponentName() {
// return "MyApp";
// }
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
}
MainApplication.java
package com.myapp;
import com.BV.LinearGradient.LinearGradientPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
// import com.facebook.react.shell.MainReactPackage;
// import com.facebook.soloader.SoLoader;
import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.reactnativenavigation.react.ReactGateway;
import com.nikolaiwarner.RNTextInputReset.RNTextInputResetPackage;
import com.reactlibrary.RNRatePackage;
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import io.invertase.firebase.auth.RNFirebaseAuthPackage;
import io.invertase.firebase.firestore.RNFirebaseFirestorePackage;
import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage;
import com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.facebook.appevents.AppEventsLogger;
import com.airbnb.android.react.maps.MapsPackage;
import io.xogus.reactnative.versioncheck.RNVersionCheckPackage;
import com.bugsnag.BugsnagReactNative;
import com.brentvatne.react.ReactVideoPackage;
import com.dylanvann.fastimage.FastImageViewPackage;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.robinpowered.react.Intercom.IntercomPackage;
import io.intercom.android.sdk.Intercom;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.app.Activity;
// import com.reactnativenavigation.controllers.ActivityCallbacks;
// import com.facebook.react.ReactApplication;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import com.appsflyer.reactnative.RNAppsFlyerPackage;
public class MainApplication extends NavigationApplication {
private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected ReactGateway createReactGateway() {
ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
@Override
protected String getJSMainModuleName() {
return "index";
}
};
return new ReactGateway(this, isDebug(), host);
}
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
// new MainReactPackage(),
new RNAppsFlyerPackage(MainApplication.this),
new RNTextInputResetPackage(),
BugsnagReactNative.getPackage(),
new RNVersionCheckPackage(),
new ReactVideoPackage(),
new IntercomPackage(),
new FastImageViewPackage(),
new RNDeviceInfo(),
new RNRatePackage(),
new RNFirebasePackage(),
new RNFirebaseMessagingPackage(),
new FBSDKPackage(mCallbackManager),
new LinearGradientPackage(),
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
AppEventsLogger.activateApp(this);
Intercom.initialize(this, "android_sdk-mykey", "mykey");
BugsnagReactNative.start(this);
setActivityCallbacks(new ActivityCallbacks() {
@Override
public void onActivityResumed(Activity activity) {
// Do stuff
}
@Override
public void onActivityPaused(Activity activity) {
// Do stuff
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
});
FacebookSdk.sdkInitialize(getApplicationContext());
SoLoader.init(this, /* native exopackage */ false);
}
@Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
@Nullable
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return Arrays.<ReactPackage>asList(
new RNTextInputResetPackage(),
// new MainReactPackage(),
BugsnagReactNative.getPackage(),
new RNVersionCheckPackage(),
new RNRatePackage(),
new RNFirebasePackage(),
new RNFirebaseAuthPackage(),
new RNFirebaseFirestorePackage(),
new RNFirebaseAnalyticsPackage(),
new RNFirebaseMessagingPackage(),
// new RNFirebaseNotificationsPackage(),
new RNDeviceInfo(),
new ReactVideoPackage(),
new IntercomPackage(),
new FastImageViewPackage(),
new MapsPackage(),
new FBSDKPackage(mCallbackManager),
new LinearGradientPackage(),
new RNAppsFlyerPackage(MainApplication.this)
);
}}
我的设置渐变
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/lib/android')
和梯度写入器属性
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip
抱歉代码太长了,但我可能在某个地方弄错了。
看起来RNN模块不存在。
解决此问题的快速检查表:
1) 检查package.json
,它应该在其依赖项中包含"react-native-navigation": "^2.11.0",
或其他类似版本。如果没有,则需要(重新)安装模块。使用npm install --save react-native-navigation
或同等纱线。
2) 在目录./node_modules/react-native-navigation
中进行检查。如果它只包含'lib/android/app/<single file>'
,则您的模块可能已被删除。如果是,npm install
/yarn install
应该恢复它。