0

我已经建立了一个新的 RN 项目,在我添加 react-native-navigation 之前它工作得非常好。我已遵循此处提供的所有步骤即使在尝试了我找到的许多解决方案之后,似乎也没有任何效果。

完整的堆栈跟踪:

react-native run-android
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...

> Configure project :app 
WARNING: The specified Android SDK Build Tools version (25.0.1) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.4.
Android SDK Build Tools 27.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Configure project :react-native-navigation 
downloadRobolectricDependencies /Users/shubhamaneja/shubham/workspace/projects/react/react-native/PROJECT_DIRECTORY/android/build/robolectric-dependencies
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation' and 'testApi'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: The specified Android SDK Build Tools version (26.0.2) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.4.
Android SDK Build Tools 27.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '26.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Task :app:compileDebugJavaWithJavac FAILED
/Users/shubhamaneja/shubham/workspace/projects/react/react-native/PROJ_NAME/android/app/src/main/java/com/PROJ_NAME/MainApplication.java:57: error: cannot find symbol
        return getPackages();
               ^
  symbol:   method getPackages()
  location: class MainApplication
1 error


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

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

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
28 actionable tasks: 1 executed, 27 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

重现步骤

  1. npm install --save react-native-navation
  2. 请按照以下步骤操作
  3. react-native run-android

环境

  • React Native Navigation 版本:1.1.486
  • React Native 版本:0.57.0
  • 平台(iOS、Android 或两者?):Android 设备信息(模拟器/设备?操作系统版本?调试/发布?):模拟器 | 调试 | Pixel2 Android 6.0 API 级别 23

安卓/settings.gredle:

rootProject.name = PROJECT_NAME

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

安卓/应用程序/build.gradle:

更换

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

 android {
     compileSdkVersion 25
     buildToolsVersion "25.0.1"
     ...
 }

并将依赖项更新为:

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation project(':react-native-navigation')
}

MainActivity.java

    package com.PROJECT_NAME;

    import com.facebook.react.ReactActivity;
    import com.reactnativenavigation.controllers.SplashActivity;


    public class MainActivity extends SplashActivity {

        /**
         * Returns the name of the main component registered from JavaScript.
         * This is used to schedule rendering of the component.
         */
        protected String getMainComponentName() {
            return "PROJ_NAME";
        }
    }


> MainApplication.java

package com.PROJECT_NAME;

import android.app.Application;

import com.facebook.react.ReactApplication;
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;
import com.reactnativenavigation.NavigationApplication;


public class MainApplication extends NavigationApplication 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()
            );
        }

        @Override
        protected String getJSMainModuleName() {
            return "index";
        }
    };

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

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

    @Override
    public boolean isDebug() {
        // Make sure you are using BuildConfig from your own application
        return BuildConfig.DEBUG;
    }


    @Override
    public List < ReactPackage > createAdditionalReactPackages() {
        return getPackages();
    }

    @Override
    public String getJSMainModuleName() {
        return "index";
    }
}
4

0 回答 0