An error occurred while running ionic cordova build android - ionic4

when build android app using ionic ionic cordova build android comment getting an error
You have been opted out of telemetry. To change this, run: cordova telemetry on.
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=...\AppData\Local\Android\Sdk (DEPRECATED)
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
[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
ionic cordova build android
ionic cordova build android
You have been opted out of telemetry. To change this, run: cordova telemetry on.
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=...\AppData\Local\Android\Sdk (DEPRECATED)
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
[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.

As of Cordova-Android 6.4.0, Gradle is now required to be installed to build Android.
When installing on Windows, you need to add Gradle to your path, (see
Setting Environment Variables)

Related

React Native and Android Studio licenses issue

I'm having a problem with React Native and Android licenses.
My Android knowledge is dated, I do write React but have no experience with React Native. Which is why I hired someone to turn a progressive web app I made into a native one. But due to circumstances I now have to finish the final thing myself.
The app was created on a mac, I'm trying to run it on pc.
The app does build for both IOS and Android from the Microsoft Appcenter. So I know it works, but I want it to run locally as well.
After doing all the installing and running react-native run-android the build starts but halts due to unaccepted licenses.
I already had Android Studio installed. I have checked the SDK Manager for the correct package versions (with 'show package details').
Updated everything I can think of including reinstalling Android Studio for the nth time. After the first uninstall/reinstall it would put it into a directory suffixed with '1' probably because the original directory couldn't be deleted. Yet the environment variables still pointed to the one without the suffix.
Accepting the licenses through cli with sdkmanager --licenses did opt me to accept a couple of times, but it didn't match the number of unaccepted packages I get from the react-native run-android error and the error remained the same afterwards (forgot to pay attention to which packages I was accepting though).
Two curious things:
- the error seems to be looking for licenses in a folder licenses yet my Android Studio folder only contains a folder license
- the error states Using Android SDK: C:\Program Files\Android\Android Studio but during the install of Android Studio I put mine in C:\AndroidSDK because it was whining about spaces.
Here is the error I get after running react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 905 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
info Installing the app...
> Configure project :app
Checking the license for package Android SDK Platform-Tools in C:\Program Files\Android\Android Studio\licenses
Warning: License for package Android SDK Platform-Tools not accepted.
Checking the license for package SDK Patch Applier v4 in C:\Program Files\Android\Android Studio\licenses
Warning: License for package SDK Patch Applier v4 not accepted.
Checking the license for package Android Emulator in C:\Program Files\Android\Android Studio\licenses
Warning: License for package Android Emulator not accepted.
Checking the license for package Android SDK Tools in C:\Program Files\Android\Android Studio\licenses
Warning: License for package Android SDK Tools not accepted.
Checking the license for package Android SDK Build-Tools 28.0.3 in C:\Program Files\Android\Android Studio\licenses
Warning: License for package Android SDK Build-Tools 28.0.3 not accepted.
Checking the license for package Android SDK Platform 28 in C:\Program Files\Android\Android Studio\licenses
Warning: License for package Android SDK Platform 28 not accepted.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
patcher;v4 SDK Patch Applier v4
build-tools;28.0.3 Android SDK Build-Tools 28.0.3
emulator Android Emulator
tools Android SDK Tools
platforms;android-28 Android SDK Platform 28
platform-tools Android SDK Platform-Tools
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html
Using Android SDK: C:\Program Files\Android\Android Studio
* 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 4s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
error Failed to install the app. Please accept all necessary SDK licenses using SDK Manager: "$ANDROID_HOME/tools/bin/sdkmanager --licenses". Run CLI with --verbo
se flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
patcher;v4 SDK Patch Applier v4
build-tools;28.0.3 Android SDK Build-Tools 28.0.3
emulator Android Emulator
tools Android SDK Tools
platforms;android-28 Android SDK Platform 28
platform-tools Android SDK Platform-Tools
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html
Using Android SDK: C:\Program Files\Android\Android Studio
* 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 4s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
at checkExecSyncError (child_process.js:611:11)
at execFileSync (child_process.js:629:15)
at runOnAllDevices (C:\Users\foo\bar\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAl
lDevices.js:74:39)
at buildAndRun (C:\Users\foo\bar\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\index.js:15
8:41)
at C:\Users\foo\bar\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\index.js:125:12
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Command.handleAction (C:\Users\foo\bar\node_modules\#react-native-community\cli\build\cliEntry.js:160:7)

Unable to load script.Make sure you're either running a Metro server(run 'react-native start') or that your bundle

I want to start React native programming. so in CMD I tried react-native init AwesomeProject then tried react-native run-android but I had some errors that I could not find solution.
some of errors resolved by editing this project in android studio:
add implementation 'androidx.appcompat:appcompat:1.1.0' to build.gradle
and change classpath("com.android.tools.build:gradle:3.4.2") to classpath("com.android.tools.build:gradle:3.5.0")
but emulator showed me
Unable to load script....
showed in this image:
error in emulator
befor this message it showed me on my phone:
JSIExecutor+JSCRuntime does not support Sampling Profiler
so I tried to create the assets directory in
...AwesomeProject\android\app\src\main\
and run gradlew clean in my root project directory.then I tried
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
but this error is occurred:
....error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[
\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\
\.*)$/: Unterminated character class. Run CLI with --verbose flag for more detai
ls.
SyntaxError: Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\
]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__t
ests__\\.*)$/: Unterminated character class....
and that error is showed me again in emulator.
I clicked Reload in emulator but it show me this error:
could not connect to development server...
i run react-native info for mor details and its result is:
info Fetching system and libraries information...
System:
OS: Windows 7
CPU: (8) x64 Intel(R) Core(TM) i7 CPU Q 740 # 1.73GHz
Memory: 892.99 MB / 3.98 GB
Binaries:
Node: 12.11.1 - C:\Program Files\nodejs\node.EXE
npm: 6.11.3 - C:\Program Files\nodejs\npm.CMD
SDKs:
Android SDK:
API Levels: 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
Build Tools: 25.0.0, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.1, 28.0.2, 28.0.3, 29.0.1, 29.0.2
System Images: android-25 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.2 => 0.61.2
the screen shot of react-native run-android command is :
CMD screen shot
and logcat in android studio after runing react-native run-android show this error:
first screen shot of logcat in android studio
then i clicked on reload and logcat showed this error:
logcat screen shot when click on reload
what is problem and how can i resolve it?
my problem is solved.
I tried to run choco uninstall nodejs.install and choco uninstall npm in CMD then I run choco install nodejs.install --version=10.16.3 and choco install npm --version=6.9.0
when I run react-native run android I had other problems, So I opened my project in Android studio and add bellow codes to build.gradle:
implementation "com.facebook.react:react-native:0.61.2" // From node_modules
implementation 'com.android.support:appcompat-v7:27.0.1'
of course that project had some warnings that using Android studio resolved them.
finally react-native run-android work correctly without error.
Adnan comment was helpful but I could not understand why:
React causes lots of errors because of version incompatibility
when I followed official website?!
The way how I ran React-Native for the first time is by following these steps mentioned on the official site:
https://facebook.github.io/react-native/docs/getting-started.html
1) Download NodeJS from this link and install
https://nodejs.org/en/
2) Download Python from this link and install
https://www.python.org/downloads/
3)download JDK from this link and install
https://www.oracle.com/technetwork/java/javase/downloads/index.html
4) If you do not have android studio installed on your PC, download from this link and install
https://developer.android.com/studio/index.html
And later install SDK from within android studio
5) Configure the ANDROID_HOME environment variable
Go to Environment variables and create a new User variable ANDROID_HOME and add the SDK path to Variable path
The default SDK location: c:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk
If you changed the SDK location in step 4, add that path above
6) Add platform-tools to Path
Go to Environment variables and in User variables, click on Path>Edit>New
Add this path in the text field
c:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk\platform-tools
If you changed SDK location, then your SDK path/platform-tools
7) Install a nice text editor like this one, VS Code:
https://code.visualstudio.com
8)Goto Viw>Terminal in VS Code, run this command
npm install -g react-native-cli
9)Create a new project
react-native init NewProjectName
10)For running the project on a physical device, follow these steps:
https://facebook.github.io/react-native/docs/running-on-device
OR use a virtual device like Genymotion
11) Run the project
-Goto your project folder, run this in VS Code terminal:
cd NewProjectName cd means change directory
-Run the project:
react-native run-android
Hope this helps!
I ran my project without any errors following these steps
IMPORTANT
Do not forget to run VS Code As Administrator if your project is in C:/Users/.. folder because it needs administrative privileges to make changes to that folder.
Make sure Metro Server window is running. The Metro Server starts automatically after running react-native run-android.
See the picture below, the top window is the server window.

react-native-camera: sdk manager plateforms-tools 28.0.1 can't be installed

I'm trying to install react-native-camera. I'm on Ubuntu 18, Webstorm for IDE. Targeting Android.
For the Android SDK, I don't have a full Android Studio install. I've instead install only android-sdk and I'm using the sdkmanager. That works fine with my stub app, it compile and runs on Android with
react-native run-android
I've installed react-native-camera as a module with npm as per the indications:
npm install react-native-camera --save
react-native link react-native-camera
So far so good. It links. If I try to launch the app however (even before trying to actually use the camera), I get some warnings:
> Configure project :react-native-camera
Checking the license for package Android SDK Platform-Tools in /usr/lib/android-sdk/licenses
License for package Android SDK Platform-Tools accepted.
Preparing "Install Android SDK Platform-Tools (revision: 28.0.1)".
Warning: Failed to read or create install properties file.
WARNING: platform-tools package is not installed, and automatic installation failed.
So I've tried to install the platforms tools using the sdk manager & instructions provided here:
sdkmanager "platform-tools" "platforms;android-28"
Which yields:
Warning: Failed to read or create install properties file.
So I am guessing it really has to do with the sdkmanager...
Do I absolutely need 28.0.1 for react-native-camera? If so, how can I get around this issue with the SDK manager? I've tried various similar syntax for the install of the platform and it didn't work. I checked with sdkmanager --list that it's the proper name (seems to be). And if I go under android-sdk/platforms-tools all I see there is the adb file (or perhaps the install is supposed to just update that file?)
Silly me.
I needed to run the SDK manager as sudo. To do that:
sudo bash sdkmanager [installations args as per post above].
I will leave the post - I lost a ridiculous amount of time for that, hopefully it can help others....
And yes - if the platform-tools install has worked then under /platform-tools you should see a bunch of files, not just the adb one.

react-native run-android not working on ubuntu 16.04

i have a problem with react native in ubuntu, i have installed,
java jdk 8 (both javac --version) as well as echo $JAVA_HOME gives the proper output.
I have also installed android studio and set the android environment variables as well as the tools and echo $ANDROID_HOME gives output of the sdk location.
I have also installed gradle version 4.4.
I am unable to start the android app using react-native run-android. can any one let me know if i have missed something during installation.
And react-native as well as android studio works fine as I am currently using react-native start to start the metro builder as well as the other react-native cli commands. also android studio and gradle is also able to generate debug as well as release apks with no problems.
The error i get,
Scanning folders for symlinks in /home/igate-naveed/Documents/ReactNative/mobile-app-android/node_modules (16ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
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
First of all you need to create a project like this:
react-native init myProjectName
Then, start an emulator from Android Studio... Afterwards:
npm install && npm start
in your project directory, and from another terminal, inside your project directory, run :
react-native run-android
Is this working?
Instead of using the npm install manager, I used yarn and it worked for me. In your project directory, just do:
(project-directory)$ yarn
Update the gradle version.
Create new project:
react-native init projectname
Uninstall the npm pack.
Reinstall the npm pack again.
npm start
react-native start
react-native run-android

Apache Cordova VS Community 2015 - Run Dependency Checker Fails

Apache Cordova Dependency Checker fails in VS Community 2015. It was previously working on this computer until I ran several VS and 3rd party tools updates. Here's what I've done to try to resolve the issue:
Installed VS / Apache Cordova (no error messages displayed) following article https://taco.visualstudio.com/en-us/docs/install-vs-tools-apache-cordova/
Run Apache Cordova Dependency Checker but VS freezes with the error message - VS 2015 has stopped working, windows will try to restart the program.
I restarted VS and cleared Cordova cache, checked environment variables (all good), then tried Apache Cordova Dependency Checker with the same freeze result.
I tried to update Apache Cordova with the fix option (no error messages) but received the same freeze results.
I completely uninstalled Apache Cordova, 3rd party tools (following article https://support.microsoft.com/en-us/kb/3016536), and VS community and then reinstalled them (no error messages) but received the same freeze results.
I installed Apache Cordova on another computer and the dependency checker phonegap app... worked. Unfortunately that's not a computer that I have access to.
What else can I do to resolve the Apache Cordova installation issue?
Thanks for any help,
Mike
Since my original post, I've had to resolve Visual Studio, Ionic, Cordova, Phonegap, plugin... environment issue several times. I've found the below works best:
Ensure platform matches plugin requirements, see platform in config.xml e.g. 6.1.1
Uninstall, reinstall latest jdk (adobe)
Clear MEF Cache - download the tool and follow instructions
Download/install latest node.js
Run the following from the command line:
Clear cache: Npm cache clean
Install latest npm: npm install -g npm
Uninstall cordova: Npm uninstall -g cordova
Reinstall cordova: Npm install –g cordova (note, this took 5+ tries to complete without errors. No other changes were made between runs. Not sure
why. Found others complaining about the same issue.)
Remove Android platform: Cordova platform remove android
Install Cordova platform add android#6.X.X (Note, as of 4/20/17 cordova and android compatibility issue. Build error - unable to find installed version of gradle. resolved by running (npm install -g cordova#6.4.0) and (cordova platform add android#6.1.2). Addt'l build errors, resolved by updating components in Android SDK Manager)
Uninstall/Reinstall plugins from the command line. For example:
cordova plugin remove phonegap-plugin-push
cordova plugin add phonegap-plugin-push variable SENDER_ID="YourID#"
npm install bower -g
Restart Visual Studio - Verify plugins were installed via config.xml
Install Ionic:
npm uninstall -g ionic
npm install -g ionic (note: to install specific version, npm install -g ionic#2.2.3)
$ ionic platform add ios
$ ionic platform add android (note: redundant, already added above)
I recommend putting as much of this as possible in a batch file with a pause between commands. Verify each command was successful, if not press ctrl+break at the pause to term the batch file early. The batch file is an easy way to restore your environment when everything breaks again. Stuff happens!
I also started using a VM (oracle virtualbox) for my development environment. That way I can backup my environment before making changes and easily restore. Don't forget to upload to GIT on a daily basis. GIT and VMs are my lifesavers.
Cool NPM commands:
npm list (lists all installed packages)
npm prune (removes packages not depended on by your project according to your package.json)
npm outdated (tells you which installed packages are outdated with respect to what is current in the npm registry but allowable by the version definition in your package.json. Make sure all up-to-date)
Please feel free to add/make suggestions to the above list.
-Mike