So I'm using https://reactnavigation.org/docs/getting-started to make my navigation. I did the yarn add @react-navigation/native and yarn add react-native-screens react-native-safe-area-context. At this point my app is still fine even after restarting yarn start. The problem started after I add the code needed to MainActivity.java and from there the app won't launch (it also won't work even after wrapping it in NavigationContainer in App.js)
This is the code from the MainActivity.java (import android.os.Bundle and @Override proctected void onCreate is the addition inserted into this app from the reactnavigation)
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);
}
}
App.js
import React from 'react';
import {GetStarted} from './pages';
import {NavigationContainer} from '@react-navigation/native';
function App() {
return (
<NavigationContainer>
<GetStarted />
</NavigationContainer>
);
}
export default App;
This is from 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.
CodePudding user response:
You should move the import statement below to your package name.
The import statement is written before the class definition and after the package statement(if there is any)
Simply change your MainActivity.java
to,
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);
}
}