当前位置: 首页 > 知识库问答 >
问题:

添加react Navigation6.x后无法使用yarn android

施彬彬
2023-03-14
import android.os.Bundle;
package com.mydoctor2;

import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
    return "MyDoctor2";
  }
  @Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(null);
}
}
import React from 'react';
import {GetStarted} from './pages';
import {NavigationContainer} from '@react-navigation/native';

function App() {
  return (
    <NavigationContainer>
      <GetStarted />
    </NavigationContainer>
  );
}

export default App;

这是来自yarn android

D:\Atur Toko Files\react-native files\MyDoctor2>yarn android
yarn run v1.17.3
$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 963 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...

> Task :react-native-safe-area-context:compileDebugJavaWithJavac

> Task :react-native-svg:compileDebugJavaWithJavac

> Task :react-native-screens:compileDebugKotlin
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\Screen.kt: (80, 26): 'constructor GuardedRunnable(ReactContext!)' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenStackFragment.kt: (59, 28): 'setter for targetElevation: Float' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenStackFragment.kt: (142, 28): 'setter for targetElevation: Float' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenStackHeaderConfig.kt: (154, 56): 'getter for systemWindowInsetTop: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenStackHeaderConfig.kt: (222, 29): 'setColorFilter(Int, PorterDuff.Mode): Unit' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (56, 22): 'constructor GuardedRunnable(ReactContext!)' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (84, 57): 'getter for systemUiVisibility: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (86, 53): 'SYSTEM_UI_FLAG_LIGHT_STATUS_BAR: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (88, 54): 'SYSTEM_UI_FLAG_LIGHT_STATUS_BAR: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (90, 27): 'setter for systemUiVisibility: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (106, 22): 'constructor GuardedRunnable(ReactContext!)' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (115, 43): 'replaceSystemWindowInsets(Int, Int, Int, Int): WindowInsets' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (116, 47): 'getter for systemWindowInsetLeft: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (118, 47): 'getter for systemWindowInsetRight: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (119, 47): 'getter for systemWindowInsetBottom: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (138, 69): 'FLAG_FULLSCREEN: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (139, 71): 'FLAG_FORCE_NOT_FULLSCREEN: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (141, 69): 'FLAG_FORCE_NOT_FULLSCREEN: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\ScreenWindowTraits.kt: (142, 71): 'FLAG_FULLSCREEN: Int' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\HeaderBackButtonClickedEvent.kt: (5, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\HeaderBackButtonClickedEvent.kt: (7, 51): 'constructor Event<T : Event<(raw) Event<*>>!>(Int)' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\HeaderBackButtonClickedEvent.kt: (17, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\HeaderBackButtonClickedEvent.kt: (18, 25): 'receiveEvent(Int, String!, WritableMap?): Unit' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenAppearEvent.kt: (5, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenAppearEvent.kt: (7, 40): 'constructor Event<T : Event<(raw) Event<*>>!>(Int)' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenAppearEvent.kt: (13, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenAppearEvent.kt: (14, 25): 'receiveEvent(Int, String!, WritableMap?): Unit' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenDisappearEvent.kt: (5, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenDisappearEvent.kt: (7, 43): 'constructor Event<T : Event<(raw) Event<*>>!>(Int)' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenDisappearEvent.kt: (13, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenDisappearEvent.kt: (14, 25): 'receiveEvent(Int, String!, WritableMap?): Unit' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenDismissedEvent.kt: (5, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenDismissedEvent.kt: (7, 43): 'constructor Event<T : Event<(raw) Event<*>>!>(Int)' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenDismissedEvent.kt: (13, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenDismissedEvent.kt: (17, 25): 'receiveEvent(Int, String!, WritableMap?): Unit' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenTransitionProgressEvent.kt: (5, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenTransitionProgressEvent.kt: (13, 5): 'constructor Event<T : Event<(raw) Event<*>>!>(Int)' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenTransitionProgressEvent.kt: (22, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenTransitionProgressEvent.kt: (27, 25): 'receiveEvent(Int, String!, WritableMap?): Unit' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenWillAppearEvent.kt: (5, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenWillAppearEvent.kt: (7, 44): 'constructor Event<T : Event<(raw) Event<*>>!>(Int)' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenWillAppearEvent.kt: (13, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenWillAppearEvent.kt: (14, 25): 'receiveEvent(Int, String!, WritableMap?): Unit' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenWillDisappearEvent.kt: (5, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenWillDisappearEvent.kt: (7, 47): 'constructor Event<T : Event<(raw) Event<*>>!>(Int)' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenWillDisappearEvent.kt: (13, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\ScreenWillDisappearEvent.kt: (14, 25): 'receiveEvent(Int, String!, WritableMap?): Unit' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\StackFinishTransitioningEvent.kt: (5, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\StackFinishTransitioningEvent.kt: (7, 52): 'constructor Event<T : Event<(raw) Event<*>>!>(Int)' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\StackFinishTransitioningEvent.kt: (13, 44): 'RCTEventEmitter' is deprecated. Deprecated in Java
w: D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\react-native-screens\android\src\main\java\com\swmansion\rnscreens\events\StackFinishTransitioningEvent.kt: (14, 25): 'receiveEvent(Int, String!, WritableMap?): Unit' is deprecated. Deprecated in Java

> Task :app:compileDebugJavaWithJavac

> Task :app:installDebug
Installing APK 'app-debug.apk' on 'Nexus_6P_API_29(AVD) - 10' for app:debug
Installed on 1 device.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 27s
84 actionable tasks: 70 executed, 14 up-to-date
info Connecting to the development server...
8081
info Starting the app on "emulator-5554"...
Starting: Intent { cmp=com.mydoctor2/.MainActivity }
Done in 34.71s.

D:\Atur Toko Files\react-native files\MyDoctor2>yarn android
yarn run v1.17.3
$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 995 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...

> Task :app:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings
58 actionable tasks: 2 executed, 56 up-to-date
D:\Atur Toko Files\react-native files\MyDoctor2\android\app\src\main\java\com\mydoctor2\MainActivity.java:2: error: class, interface, or enum expected
package com.mydoctor2;
^
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 7s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
D:\Atur Toko Files\react-native files\MyDoctor2\android\app\src\main\java\com\mydoctor2\MainActivity.java:2: error: class, interface, or enum expected
package com.mydoctor2;
^
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 7s

    at makeError (D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\execa\index.js:174:9)
    at D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\execa\index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:106:5)
    at async Command.handleAction (D:\Atur Toko Files\react-native files\MyDoctor2\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

共有1个答案

严承允
2023-03-14

您应该将下面的import语句移动到您的包名。

import语句写在类定义之前,package语句之后(如果有的话)

只需将MainActivity.java更改为,

package com.mydoctor2;

import android.os.Bundle; // moved import statement
import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {

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

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
  }
}
 类似资料:
  • 根据下面的内容,我不确定如何排除这个非常简单的使用场景。 我有一个脚本(大约一个月运行一次),它在功能上做相同的事情,一个月前就开始工作了。 我将感谢任何关于开始研究为什么这不起作用的地方的建议。

  • 问题内容: 对于下面的内容,我不确定如何解决这种非常简单的使用情况。 我有脚本功能上做了相同的事情,这(我跑大约每月一次) 用 工作作为一个月前。 我会很高兴有任何地方的指针开始研究为什么它不起作用。 问题答案: 您应该先打开url并加载cookie,然后再打开包含cookie的下一个URL。如果要打开相同的url,也可以像这样打开: 希望这可以帮助

  • 使用1.8.9 http://www.cinemas-utopia.org/admin/grilles/toulouse/2015-06-02.pdf

  • 我有很多DynamoDB表要在数据管道中设置备份。我能够通过aws命令行为1或2个表传递一个json文件,这意味着json文件正在工作。 但是,当我传递一个大型JSON(包含50-100个DynamoDB表)来设置DataPipeline时,我会遇到这样的错误: 调用PutPipelineDefinition操作时发生错误(InvalidRequestException):超过Web服务限制:超过

  • 我使用systemd服务运行spring boot应用程序: 在我添加logback-spring.xml生成日志文件之前,它运行良好: 现在服务无法启动。“systemctl status-l myapp”没有显示任何有用的提示: journalctl-uMyApp。服务: 但是,如果我用命令java-jar手动运行jar,它就可以启动了 我还使用“chown java-webapp-daemo