Unable to run the first time react-native app for android on mac - reactjs

I'm trying to run the react-native application on the macbook for android version.So I have followed all the step for setting up the environment on the machine from here :
https://facebook.github.io/react-native/docs/getting-started.html
And I have successfully install Android Studio,Android SDK, JDK, Node, NPM, Watchman, Homebrew
javac -version : 9
node -v : v8.9.1
npm -v: 5.5.1
watchman version: 4.9.0
When I tried to run the application with the command
react-native run-android
I got this error :
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.gradle.internal.reflect.JavaMethod (file:/Users/aman/.gradle/wrapper/dists/gradle-2.14.1-all/8bnwg5hd3w55iofp58khbp6yv/gradle-2.14.1/lib/gradle-base-services-2.14.1.jar) to method java.lang.ClassLoader.getPackages()
WARNING: Please consider reporting this to the maintainers of org.gradle.internal.reflect.JavaMethod
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> javax/xml/bind/annotation/XmlSchema
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 9.925 secs
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/android-setup.html

According to this GitHub issue, this issue has to do with JDK version. Make sure you're using v8, not v9, then the error should not occur.

Yes, according to #Sam Hanley it's an issue with the java version update. So, with worrying about the version update/downgrade, we can pass on with this issue by the following process;
First, update the distributionUrl in gradle-wrapper.properties
ie: located in this path;
PROJECT_PATH/android/gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-rc-2-all.zip
Set $JAVA_HOME environment variable using the installed android studio app path (Android studio should be installed)
export JAVA_HOME="/Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home"
(PS: solution for macOS )
Hope this help!

I was able to get past this particular problem by doing the following:
Edit path_to_your_project/android/gradlew
Change DEFAULT_JVM_OPTS="" to DEFAULT_JVM_OPTS="--add-modules java.se.ee"

Related

React-native running app error while gradle

I'm new to react-native and i went trough making my first app, and all good until i got to run it because i get this error, i would ¡be thankful if someone could help me, i did all the tutorial that react-native provide in it's page so i think i installed it correctly.
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 870 file(s) to forward-jetify. Using 12 workers...
info Starting JS server...
/bin/sh: adb: command not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/fovu/Documents/AwesomeProject/android/local.properties'.
* 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 2s
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 app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/fovu/Documents/AwesomeProject/android/local.properties'.
* 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 2s
at makeError (/Users/fovu/Documents/AwesomeProject/node_modules/execa/index.js:174:9)
at /Users/fovu/Documents/AwesomeProject/node_modules/execa/index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (/Users/fovu/Documents/AwesomeProject/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction (/Users/fovu/Documents/AwesomeProject/node_modules/#react-native-community/cli/build/index.js:192:9)
info Run CLI with --verbose flag for more details.
Hello and welcome to StackOverflow!
As the logs mention, it cannot compile you app since the location of your android SDK cannot be found.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/fovu/Documents/AwesomeProject/android/local.properties'.
It seems that your properties file points to a wrong SDK directory, your ANDROID_SDK_ROOT path points to a wrong directory or the ANDROID_SDK_ROOT path doesn't exist at all.
I'd recommend you to read through the official setup documentation and following each step: https://reactnative.dev/docs/environment-setup
Appendix
I have seen in your logs that react-native doesn't even see an emulator, hence this line:
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
So you need to either manually launch an emulator or if you don't have an android emulator, install one. Or if you want: You can try to install the app on your phone by plugging it into your computer and enable USB debugging on your phone.
Cheers.

How to make app compatible with Android 12 (Snow Cone)

I am trying to build my Ionic App to support Android 12. It works fine upto Android 11, but is not supporting Android 12.
==Supported credentials to Android 11==
package.json
“cordova-android”: “^9.1.0”
build.gradle file:
defaultBuildToolsVersion=“29.0.2”
defaultMinSdkVersion=22
defaultTargetSdkVersion=30
defaultCompileSdkVersion=30
config.xml file:
preference name="android-targetSdkVersion" value="30"
==Tried increasing sdk to 31==
package.json file:
“cordova-android”: “^10.0.0”
build.gradle file:
defaultTargetSdkVersion=31
defaultCompileSdkVersion=31
config.xml file:
preference name="android-targetSdkVersion" value="31"
added android:exported=“true” in MainActivity in ..\platforms\android\app\src\main\AndroidManifest.xml
Error :
FCMPlugin: Support for Gradle v4 or lower is deprecated. Please upgrade to a newer version.WARNING:: Configuration ‘compile’ is obsolete and has been replaced with ‘implementation’ and ‘api’.
It will be removed in version 7.0 of the Android Gradle plugin.
For more information, see Add build dependencies | Android Developers.
WARNING:: Using flatDir should be avoided because it doesn’t support any meta-data formats.
Task :app:processDebugMainManifest FAILED
…\platforms\android\app\src\main\AndroidManifest.xml Error:
Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See <activity> | Android Developers for details.
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ‘:app:processDebugMainManifest’.
Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See <activity> | Android Developers 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use ‘–warning-mode all’ to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See Command-Line Interface
BUILD FAILED in 3s
15 actionable tasks: 1 executed, 14 up-to-date
Command failed with exit code 1: …\platforms\android\gradlew cdvBuildDebug -b …\platforms\android\build.gradle
[ERROR] An error occurred while running subprocess cordova.
cordova.cmd build android exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
I have tried all forums and posts, nothing seem to works. Anybody has an idea on how to make this work?

The app build fails when using React Native CLI

I am very fustrated. The React Native CLI is failing when building the app.
** BUILD FAILED **
The following build commands failed:
CompileC /~/Library/Developer/Xcode/DerivedData/third-eknrlzcnsdfzrlhgyioqgsamgxub/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/ConnectionContextStore.o /~/Projects/reactnativetest/third/ios/Pods/Flipper/xplat/Flipper/ConnectionContextStore.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /~/Library/Developer/Xcode/DerivedData/third-eknrlzcnsdfzrlhgyioqgsamgxub/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperConnectionManagerImpl.o /~/Projects/reactnativetest/third/ios/Pods/Flipper/xplat/Flipper/FlipperConnectionManagerImpl.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /~/Library/Developer/Xcode/DerivedData/third-eknrlzcnsdfzrlhgyioqgsamgxub/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperClient.o /~/Projects/reactnativetest/third/ios/Pods/Flipper/xplat/Flipper/FlipperClient.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /~/Library/Developer/Xcode/DerivedData/third-eknrlzcnsdfzrlhgyioqgsamgxub/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperRSocketResponder.o /~s/Projects/reactnativetest/third/ios/Pods/Flipper/xplat/Flipper/FlipperRSocketResponder.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(4 failures)
I did uninstall Xcode and install it fresh but did not make any difference, I got exactly the same error. The errors seem to be related with the Flipper library, but Flipper is installed as a pod in the ios/Pods directory.
Yesterday I tried Expo. The installation of the expo CLI took forever and it got hanging in the iTerm window, so I kill it. But then, when typing “expo whoami”, it gave me the asnwer of “Not logged in”, which means that Expo was installed. I was able to run the app in the ios simulator.
Today, when I tried to run the app again, I got the message that Expo was not installed. Weird, since I used it yesterday. I did the Expo cli installation again today and it did the same than yesterday. It has been more than 3 hours hanging in the terminal. But when I type “expo whoami”, I get the correct answer and I am able to run the app.
Also, today I did install the latest version of Android Studio 4.1.2 (I had version 1.3). After installation, Android Studio opens a window and then quits. I researched and it seems like Android Studio does not work on Mac version greater than 10.14 (Mac OS Mojave).
Why I am having so many problems just to run the app?. Anybody else having these problems?. Any solutions?.
If you are not using flipper just comment it out on the Podfile, that fixed the issue for me,
How to do it,
open podfile and make sure all this is commented,
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
# use_flipper!
# post_install do |installer|
# flipper_post_install(installer)
# end
update pods
pod update
That will fix it,
If you need flipper you'll have to specify use_flipper!({ 'Flipper-Folly' => '2.3.0' }) version and run pod install

ionic build fails error 65

Building my ionic app fails since this weekend:
** BUILD FAILED **
The following build commands failed:
CompileC build/App.build/Debug-iphonesimulator/App.build/Objects-normal/i386/IonicKeyboard.o App/Plugins/com.ionic.keyboard/IonicKeyboard.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
Error: Error code 65 for command: xcodebuild with args: -xcconfig,/Users/me/Documents/app/platforms/ios/cordova/build-debug.xcconfig,-project,app.xcodeproj,ARCHS=i386,-target,app,-configuration,Debug,-sdk,iphonesimulator,build,VALID_ARCHS=i386,CONFIGURATION_BUILD_DIR=/Users/me/Documents/app/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/Users/me/Documents/app/platforms/ios/build/sharedpch
OSX 10.11.3
XCode 7.2.1 (7C1002)
ionic -v
1.7.14
Today I reinstalled cordova and ionic, but I still keep getting the error. I had to adjust another issue with macports (here), which I fixed by setting the rights right, but still keep getting the above error.
Error 65 seems to have originate from within Cordova plugins. I've been able to "band-aid" this issue by:
cordova plugin remove <plugin name>
ionic platform remove <os>
ionic platform add <os>
cordova plugin add <plugin name>
I've also tried using sudo while running these commands with mixed results.
I fixed with following steps
in xCode go-to "Build Phase" >> Under "Compile Sources" >>
did you notice any missing or .m files failed to link... in my case it was "IonicKeyboard.m" file
I just added the file to the list "plugins/cordova-plugin-ionic-keyboard/src/ios/IonicKeyboard.m"
then Build Project - worked
iOS
Open platforms/ios on XCode
Find & Replace io.ionic.starter in all files for a unique identifier
Click the project to open settings
Signing > Select a team
Go to your device Settings > General > DeviceManagement
Trust your account/team
ionic cordova run ios --device --livereload

Ionic emulate ios - Error

I'm getting this following error after I ran my app on my own ios device.
No target specified for emulator. Deploying to iPhone-6 simulator
An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=159):
Invalid device state
An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=159):
Invalid device state
ENOENT, no such file or directory '/Users/cauealmeida/Library/Logs/CoreSimulator/5C6DA43E-3993-4260-87EE-73FEB27DE181/system.log'
Error code 1 for command: ios-sim with args: launch,/Users/cauealmeida/Documents/jobs/dev/ionic-maptest/map-test/platforms/ios/build/emulator/map-test.app,--devicetypeid,com.apple.CoreSimulator.SimDeviceType.iPhone-6,--stderr,/Users/cauealmeida/Documents/jobs/dev/ionic-maptest/map-test/platforms/ios/cordova/console.log,--stdout,/Users/cauealmeida/Documents/jobs/dev/ionic-maptest/map-test/platforms/ios/cordova/console.log,--exit
Error: /Users/cauealmeida/Documents/jobs/dev/ionic-maptest/map-test/platforms/ios/cordova/run: Command failed with exit code 2
I've tried with ionic emulate ios -cls from different projects and the same error is shown.
What am I missing?
Here are the steps you can use to correct this issue:
1) Empty the 'platforms' folder in your Ionic project
2) Re-run ionic platform add ios, ionic build ios, and ionic emulate ios without sudo
3) Still getting a permissions error, make sure all the files in your user's home folder actually belong to that user by running
sudo chown -R username /Users/username
We fixed this using the SO answer here, which was just to Reset Content and Settings in the Simulator menu.
You need to download ios simulator.
Go to xcode and download ios 9 or other simulator.
you also need to install ios-sim using your terminal.
sudo npm install -g ios-sim
also check and confirmed your device is connected properly.
connected device you see in xcode window

Resources