Phonegap android failing after adding phonegap-plugin-push - android

There are lots of issues talking about Phonegap push notification plugin. May be it's updating time to time, some working solutions for some people not work for others.
I just created a fresh phonegap project(CLI 5.1.1) and added android platform and above plugin. When trying to compile it's failing with below error
Could not find any version that matches com.android.support:support-v13:23+
Below is the detailed compile error
Running command: cmd "/s /c
"C:\Users\me\Documents\PhoneGap_Apps\hello\plat
forms\android\cordova\build.bat""
ANDROID_HOME=F:\Softwares\Android\adt-bundle-windows-x86_64-20140702\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45
Running:
C:\Users\me\Documents\PhoneGap_Apps\hello\platforms\android\gradle w
cdvBuildDebug -b
C:\Users\me\Documents\PhoneGap_Apps\hello\platforms\andr
oid\build.gradle -Dorg.gradle.daemon=true
FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring root project 'android'.
Could not resolve all dependencies for configuration ':_debugCompile'.
Could not find any version that matches com.android.support:support-v13:23+ .
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/support/support-v13/maven-me
tadata.xml
https://repo1.maven.org/maven2/com/android/support/support-v13/
file:/F:/Softwares/Android/adt-bundle-windows-x86_64-20140702/sdk/extra
s/android/m2repository/com/android/support/support-v13/maven-metadata.xml
file:/F:/Softwares/Android/adt-bundle-windows-x86_64-20140702/sdk/extra
s/google/m2repository/com/android/support/support-v13/maven-metadata.xml
file:/F:/Softwares/Android/adt-bundle-windows-x86_64-20140702/sdk/extra
s/google/m2repository/com/android/support/support-v13/
Required by:
:android:unspecified
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
How to overcome this issue?

Update you Android SDK.
The Cordova Plugin named "phonegap-plugin-push" needs "Android Support Library version 23"
Process is explain in here
Compiling
As of version 1.3.0 the plugin has been switched to using Gradle/Maven
for building. You will need to ensure that you have installed the
Android Support Library version 23 or greater.

According to the error message, it's looking for a support-v13 version in the location of <my_sdk>/extras/android/m2repository/com/android/support/support-v13
And this happens because of my plugin.xml (at my_phonegap_app/plugins/phonegap-plugin-push) having below line
<framework src="com.android.support:support-v13:23+" />
But I noticed that I don't have any 23+ versions in my above sdk path and I do have a folder 22.2.0 as the latest. Inside that folder there are support-v13-22.2.0 files.
So update the plugin.xml file so that it refers to one of existing.
<framework src="com.android.support:support-v13:22.2.0" />
To be safe enough, remove android platform and re add it before compiling
phonegap platform remove android
phonegap platform add android
Then try compile. Now it refers for the correct, existing file and compile will get success.

After spending 2h on trying build apk with phonegap-plugin-push plugin I found solution.
In config.xml of your cordova project (in your main directory), just edit or
add this line:
<preference name="android-targetSdkVersion" value="23"/>
Then remove android platform:
cordova platform add android
And add it again:
phonegap platform add android

I had a similar/the same problem when running cordova 6.0.0 project in Visual Studio 2015
Debugging in VS Emulator and Ripple works but not on the device (Sony Xperia Z5 Compact)
Build error output contained the error "Could not find any version that matches com.android.support:support-v13:23+."
Severity Code Description Project File Line Suppression State
Error > Could not find any version that matches com.android.support:support-v13:23+.
I checked that I had the correct SDK tools etc installed on my machine (Windows 10) but still couldn´t build debug to my device.
My solution was to install the adb and fastboot drivers for my phone following this guide (page 2 and 3).
http://www.teamandroid.com/2012/07/30/how-to-set-up-adb-fastboot-with-android-sdk/
install driver for adb interface
http://www.teamandroid.com/2012/07/30/how-to-set-up-adb-fastboot-with-android-sdk/2/
install driver for fastboot bootloader interface
http://www.teamandroid.com/2012/07/30/how-to-set-up-adb-fastboot-with-android-sdk/3/
!note: I have a Xperia z5 and to get it in the fastboot mode the easy way is to (instead of steps 26-28) just run the adb command "adb reboot bootloader"

Related

How to solve (Could not initialize class org.codehaus.groovy.reflection.ReflectionCache) issue in react native

$ npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Launching emulator...
error Failed to launch the emulator. Reason: Could not start an emulator within 30 seconds.
warn Please launch an emulator manually or connect a device. Otherwise, the app may fail to launch.
info Installing the app...
FAILURE: Build failed with an exception.
What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
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 1m 23s
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
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 1m 23s
at checkExecSyncError (child_process.js:629:11)
at execFileSync (child_process.js:647:13)
at runOnAllDevices (E:\work\react-native\AwesomeProject1\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
I think I had the same issue. After installing RN (May 20th, 2020), I bumped into this error. I found this solution on https://github.com/gradle/gradle/issues/10248.
In short:
Go to /android/gradle/wrapper/gradle-wrapper.properties file in your RN project
Find this line that starts with distributionUrl. Change the gradle version into gradle-6.3-all.zip.
In my project, it was:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
and I changed it into:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
That's it.
I had the same error on Mac OS and React Native v0.62.
Apply these instructions correctly: React native environment setup
Adding this variable solved my problem:
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
In the React Native version 0.62.x even the initialized application is not ready for a development build.
I change the Gradle version to the latest and I could to have a clean build, so change this file:
// this file => /android/gradle/wrapper/gradle-wrapper.properties
from:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
to:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Pay Attention: The latest version of the Gradle for my time is 6.5. when you are reading this answer please check this link to see the latest version number of the Gradle.
Update Jan 24, 2023
7.6
I fixed this by these steps:
install android studio 3.5 (or later)
install java 1.8
if you have java JDE 14.x.x you have to remove its folder from library/java/JavaVirtualMachines/jdk-14.x.x.jdk (on mac os)
install an older version of JDE (I installed 11.0.6)
npm run android!
Just follow these 2 steps only and take your coffee.
Navigate to 'android' > gradle > wrapper > gradle-wrapper.properties
Change 'distributionUrl' from old to >
distributionUrl=https://services.gradle.org/distributions/gradle-6.3-all.zip
This Error occurs when the gradle version you used is not compatible on your environment, so you just need to update your gradle version to latest Gradle Versions, just go to: /android/gradle/wrapper/gradle-wrapper.properties to your project file.
Auguest 2021
I was using JDK 16.0.1 and faced this issue. So, for JDK 16.0.1 you need 7.0 version of gradle.
I fixed it by going to /android/gradle/wrapper/gradle-wrapper.properties and changing
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
If you are a macOS user then you should install
brew cask install adoptopenjdk/openjdk/adoptopenjdk8
brew cask install android-platform-tools
update your .bash_profile
nano ~/.bash_profile
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
This would resolve your problem. If you are working on a legacy codebase then changing the distribution URL would lead to other problems. It usually happens because of mismatching java versions.
It's probably because you use Gradle as the build system and JDK14
and the Gradle version is old. Reference:
If you use Gradle Wrapper then refer to
$PROJECT_ROOT/gradle/wrapper/gradle-wrapper.properties
Property distributionUrl should be:
distributionUrl=https://services.gradle.org/distributions/gradle-6.3-bin.zip
If it's an older version then change it, run ./gradlew clean build
and try again.
It is because your Gradle version is not supported by the Java JDK. If you use the JDK version 15.0.2 then you need to Gradle version change 6.6.1 or 6.7
To Change the Gradle Version in Android Studio.
android[project_name]/gradle/wrapper/gradle-wrapper.properties
Open this file and set this
distributionUrl=https://services.gradle.org/distributions/gradle-6.6.1-all.zip
then this problem will be solved.
To check the java JDK version.
open cmd.
run echo %JAVA_HOME%
Then you can also search on google to check the supported version of Gradle to the JDK.
updating JAVA_HOME works for me in mac OS
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
This issue is caused by incorrect version of graddle. so to fix this follow these steps
Make sure you have Android studio installed and SDK is setuped from Android studio menu Tool-> SDK Manager you can setup SDK, install latest SDK if you are using latest version of React Native .
From Android Studio menu Tools > AVD Manager Setup one device and download the image. and test it to see that emulator is running OK.
Make Sure JDK is installed for latest react native install latest JDK : https://www.oracle.com/java/technologies/javase-downloads.html
Next from Android Studio menu File > New > new project create one dummy project aka Hello world and build make sure all android studio issues resolved and your Android studio hello world app is running on emulator.
Now time to fix your react native app. Stop your Android studio hello world app and keep the emulator running.
Locate your Android studio hello world app on your system and go to gradle\wrapper folder and copy the gradle-wrapper.properties file
example in windows case my hello world app is located in my documents:
C:\Users\Superman\Documents\android\hello world\gradle\wrapper
Next go to your react native app folder like : myReactApp\android\gradle\wrapper and paste the gradle-wrapper.properties file you copied from your Android studio hello world app.
finally in your terminal execute : npx react-native run-android
I have the same issue with new project and windows. I try all these way but it doesn'. Ridiculously, I move java/jdk folder from C:\Program Files to another dir in D:\ and it works like a charm.
May be it's useful.
December 2021
If you're using the latest version of Java Development Kit, you'll need to change the Gradle version of your project so it can recognize the JDK. You can do that by going to {project root folder}\android\gradle\wrapper\gradle-wrapper.properties and changing the distributionUrl value to upgrade the Gradle version. You can check out here the lastest releases of Gradle.
If you're looking for a solution for a Java/Kotlin Core Android project and not a React Project because i was also facing this problem in my core android project so here you go...
None of the above solutions worked for me. So basically the idea is to Change the version of gradle. How to do that you ask? Follow these steps:
File>Project Structure
Select SDK Location
You will find something written as "JDK was moved to Gradle Settings". Click on Gradle Settings.
Use Gradle Version 11.0
Sync the project again.
And there you go! A successfully built project! :)

Android Studio doesn't install SDKs... what?

I'm trying to use Cordova to build a hello world app and after adding ANDROID_HOME variable (You'd be shocked how long that took to figure out) all I keep seeing when building is this:
BUILD FAILED
Total time: 1 mins 6.679 secs Error:
/Users/vladdy/Desktop/laboratory/cordovaBackgroundApp/platforms/android/gradlew:
Command failed with exit code 1 Error output:
FAILURE: Build failed
with an exception.
What went wrong: A problem occurred configuring root project 'android'.
Failed to find target with hash string 'android-25' in: /Users/vladdy/Library/Android/sdk
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Ok fair enough so let's go install it:
Waiting patiently for the install, and same error running cordova build.
I wonder what else we need to install? But look, it seems that Android Studio still has Nougat and 25 available:
Why is Android Studio not installing anything?
I can see why PhoneGap Build is so popular...
Edit:
cordova requirements is now broken reporting the following:
My ~/.bash_profile:
export ANDROID_HOME=/Users/vladdy/Library/Android/sdk/
Requirements?
If you don't need Android Studio, I recommend not downloading it, instead, as #Tom-Esendam also suggest, go for the command-line tool.
Android Studio and Command Line Tool
Direct download link of Command Line Tool for OSX (2017-03-21)
Proxy?
And if your behind a proxy server, don't forget to add it to the settings in the SDK Manager Settings.
What does the different programs and commands?
cordova build doesn't download any SDK's.
cordova prepare appends the necessary SDK files to the cordova build folders.
After download of Command Line Tool:
After unzipping it, set ANDROID_HOME to it's root, so you have:
build-tools
extras
platforms
platform-tools
system-images
tools
catalogs under the root.
Adding SDK's:
Then install SDK's with ./tools/android.
Android SDK Manager downloads the SDK's, so you check what you need and hit OK to download it.
Preparing the build
Make sure all proxy settings are set if your behind a proxy.
Before running cordova build run cordova prepare. This shouldn't be necessary, but least I need to run that even thou cordova build should include that.
I don't know about the mac version. But on windows you have a standalone sdk manager. If there is one on mac try that?

Cordova - Error code 1 for command | Command failed for

I'm new on cordova, so if my question is not relevant, forgive me.
i have a cordova project in my Windows 7 x64 machine.
Yesterday i was build my cordova app via cordova build android --release.
But i need to add new plugin cordova-plugin-zip to update my cordova project.
What i did to add this plugin to my cordova app;
I installed a git application to my win7 x64 env.
npm install -g git i wrote this command on cmd.
I Opened Windows Environment Variables/Path Window and added ;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd
add plugin via this command cordova plugin add https://github.com/apache/cordova-plugin-file.git
then added other plugin cordova plugin add https://github.com/MobileChromeApps/zip.git
(Everything fine till this step)
Then i run on cmd cordova build android --release
Unfourtunately it throws following error;
BUILD FAILED C:\android\sdk\tools\ant\build.xml:720: The following
error occurred while execu ting this line:
C:\android\sdk\tools\ant\build.xml:734: Compile failed; see the
compiler error o utput for details.
Total time: 7 seconds
C:\hascevher\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^ Error code 1 for command: cmd with args: /s,/c,ant,release,-f,C:\hascevher\platf
orms\android\build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
ERROR building one of the platforms: Error: cmd: Command failed with
exit code 1
You may not have the required environment or OS to build this project
Error: cmd: Command failed with exit code 1
at ChildProcess.whenDone (C:\Users\Hddn\AppData\Roaming\npm\node_modules\cor
dova\node_modules\cordova-lib\src\cordova\superspawn.js:134:23)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
When i try to create a new helloworld cordova project and adding android platform then from cmd cordova build android it creates sample app?
So what is wrong with my other application?
Any help greatly appricated.
OS: Windows 7 x64
Cordova v 5.1.1
Ant version 1.9.4
Plugins On Cordova Project:
cordova-plugin-file
cordova-plugin-zip
org.apache.cordova.console
org.apache.cordova.device
org.apache.cordova.inappbrowser
Full Windows Environment Variables/Path:
C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common
Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common
Files\Microsoft Shared\Windows
Live;%C_EM64T_REDIST11%bin\Intel64;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program
Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files
(x86)\Windows Live\Shared;C:\Program Files
(x86)\QuickTime\QTSystem\;C:\Program Files
(x86)\Java\jdk1.7.0_75\bin;C:\cordova\apache-ant-1.9.4\bin;C:\android\sdk\tools;C:\android\sdk\platform-tools;C:\Program
Files\nodejs\;C:\Program Files (x86)\Git\bin;C:\Program Files
(x86)\Git\cmd
I removed android platforms and installed again then worked. I wrote these lines in command window:
cordova platform remove android
then
cordova platform add android
Delete platforms/android folder and try to rebuild. That helped me a lot.
(Visual Studio Tools for Apache Cordova)
Delete all the apk files from platfroms >> android >> build >> generated >> outputs >> apk
and run command cordova run android
I found answer myself; and if someone will face same issue, i hope my solution will work for them as well.
Downgrade NodeJs to 0.10.36
Upgrade Android SDK 22
I have had this problem several times and it can be usually resolved with a clean and rebuild as answered by many before me. But this time this would not fix it.
I use my cordova app to build 2 seperate apps that share majority of the same codebase and it drives off the config.xml. I could not build in end up because i had a space in my id.
com.company AppName
instead of:
com.company.AppName
If anyone is in there config as regular as me. This could be your problem, I also have 3 versions of each app. Live / Demo / Test - These all have different ids.
com.company.AppName.Test
Easy mistake to make, but even easier to overlook. Spent loads of time rebuilding, checking plugins, versioning etc. Where I should have checked my config. First Stop Next Time!
I had the same error code but different issue
Error: /Users/danieloram/desktop/CordovaProject/platforms/android/gradlew: Command failed with exit code 1 Error output:
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
To resolve this issue I opened the Android SDK Manager, uninstalled the latest Android SDK build-tools that I had (24.0.3) and installed version 23.0.3 of the build-tools.
My cordova app then proceeded to build successfully for android.
In my case it was the file size restriction which was put on proxy server. Zip file of gradle was not able to download due this restriction. I was getting 401 error while downloading gradle zip file. If you are getting 401 or 403 error in log, make sure you are able to download those files manually.
Faced same problem. Problem lies in required version not installed.
Hack is simple Goto Platforms>platforms.json
Edit platforms.json in front of android modify the version to the one which is installed on system.
I'm using Visual Studio 2015, and I've found that the first thing to do is look in the build output.
I found this error reported there:
Reading build config file: \build.json... SyntaxError: Unexpected
token
The solution for that was to remove the bom from the build.json file
Then I hit a second problem - with this message in the build output:
FAILURE: Build failed with an exception. * What went wrong: A
problem was found with the configuration of task ':packageRelease'.
File 'C:\Users\Colin\etc' specified for property
'signingConfig.storeFile' is not a file.
Easily solved by putting the correct filename into the keystore property

Phonegap 3.3 Build Android Failed

I'm trying to build a project but when I type: cordova build android the following error occurred:
Generating config.xml from defaults
for platform "android"
Preparing android project
Compiling app on platform "android"
via command "../platforms/android/cordova/build"
Error: An error occurred
while building the android project.Error executing "ant debug -f "../platforms/android/build.xml"":BUILD FAILED /usr/local/Cellar/android-sdk/22.3/tools/ant/build.xml:932:The following error occurred
while executing this line: /usr/local/Cellar/android-sdk/22.3/tools/ant/build.xml:950:null returned: 1
Total time: 18 seconds
at ChildProcess. < anonymous > (/usr/local/lib/node_modules/cordova/src/compile.js:65:22)
at ChildProcess.EventEmitter.emit(events.js: 98: 17)
at maybeClose(child_process.js: 735: 16)
at Socket. < anonymous > (child_process.js: 948: 11)
at Socket.EventEmitter.emit(events.js: 95: 17)
at Pipe.close(net.js: 466: 12)
Is there a fix for this problem?
EDIT
I used brew to install Android-SDK and installed all possible build-tools:
And my android manifest looks like:
EDIT2
As requested here is the responce for cordova build android --verbose: http://pastebin.com/rqdkVKYG
I found the bug.
While testing, reinstalling android-sdk and ant. I tried to create a new project. Than typed in the terminal cordova build and it build flawlessly. After this I copied my existing WWW folder in to the new project. Typed cordova build again, it gave an error. Now I knew that the bug was in my WWW folder and not in the project itself. Scanning my folders I noticed a file with no extension(hidden files). I deleted the file and tried again. Success!
SUMMARY:
Scan your folders for files without extensions and delete or move them. Cordova doesn't like those.
EDIT
If this doesn't work try:
cordova platform rm android
then reinstall android using :
cordova platform add android
Now try to build.
try to run the command $home/.cordova/lib/android/cordova/3.3.0/bin/check_reqs to check if you have all the required components installed for android.
¿Did you add to windows path the sdk?
You can also try:
cordova platform add android
cordova build
try ant -v in your terminal and make sure it's above 1.8. Cordova requires that.
Also check path is given correct for Ant, Android-SDK/tools, and Android-SDK/platformtools
To debug exact issue try $Cordova build android --verbose
Let me know.

PhoneGap 3.0 Android build Command failed to execute : ant jar

I installed PhoneGap 3.0 with Node.js and configured all the environment variables so that javac, java, and ant all work but when I do a basic app create and try to build it for Android, I get the following error:
An error occurred during creation of android sub-project. Creating Cordova project for the Android platform: Command failed to execute : ant jar
Any ideas?
Make sure you have the Android Build Tools installed for your Android SDK version. In the Android SDK manager under Tools>Android SDK Build-tools you should see that the Build tools for your SDK version are not installed.
Detail on how I uncovered this:
To identify this as the root cause I ran the Cordova command with -d for verbosity:
cordova -d platform add android
The output of this command shows the error:
Running bin/create for platform "android" with command: ""C:\Users\---\.cordova\lib\android\cordova\3.1.0\bin\create" "C:\Users\---\workspace_android\FleetView\platforms\android" "com.---.fleetview" "Fleet View"" (output to follow)
Running the offending command directly:
"C:\Users\---\.cordova\lib\android\cordova\3.1.0\bin\create" "C:\Users\---\workspace_android\FleetView\platforms\android" "com.---.fleetview" "Fleet View"
produces this output:
BUILD FAILED
C:\tools\adt-bundle-windows-x86_64-20130219\sdk\tools\ant\build.xml:479: SDK does not have any Build Tools installed.
Total time: 1 second
Command failed to execute : ant jar
I am on Windows 7.
This is due to ANT tools could not find tools.jar in JRE lib directory. When I copied tools.jar from JDK lib directory to JRE lib directory, the problem was absolutely solved and the build was successful when I ran the command "cordova -d platform add android". Hope this helps you.
Posted the answer to similar question: Android Platform Guide trouble with adding a platform through the command line
A combination of 2 things worked for me:
include the JDK in your path (path\to\jdk\bin of course)
exclude the JRE from your path (or at least have it come after the JDK)
I faced the same issue,
I was having jdk-6 and I updated to jdk-7,
that fixed the issue,
Also I didn't installed ant in the first place,
in your case ant PATH might be missing.
See if that helps.

Categories

Resources