Error : Unable to prepare project - android

While trying to do a release using the following command:
code-push release-cordova myApp android
I'm getting the following error in the terminal:
Running "cordova prepare" command:
[Error] Unable to prepare project. Please ensure that this is a Cordova project and that platform "android" was added with "cordova platform add android"
Any one knows what might be wrong? The project is a cordova project created using the command:
cordova create myApp
And also has android platform added.
UPDATE :
Running cordova prepare android --verbose returns the following output :
Executing "before_prepare" hook for all plugins.
Searching PlatformJson files for differences between project vs. platform installed plugins
No differences found between project and android platform. Continuing...
Generating config.xml from defaults for platform "android"
Wrote out Android application name to "HelloCordova"
Wrote out Android package name to "io.cordova.hellocordova"
This app does not have launcher icons defined
updated project successfully
Executing "after_prepare" hook for all plugins.

Make sure your Nodejs is the last version.
code-push-cli required "child_process"

That error indicates that the current working directory didn't represent the root of a Cordova project at the time that you ran the release-cordova command. Can you make sure that you CD into the directory that contains the www, platforms, plugins, etc. directories, and then run the release-cordova command? That should do the trick for you

Related

Jenkins cannot create cordova platforms

I have a jenkins job that is supposed to create a cordova app but it's failing some reason that I can't quite identify. The jenkins job simply does this:
cordova platform add android
cordova prepare android
cordova build android --debug --verbose
The first command (cordova platform add android) is resulting in the following error:
ENOENT: no such file or directory, mkdir 'platforms/android/app/src/main'
Error: ENOENT: no such file or directory, mkdir 'platforms/android/app/src/main'
at Object.mkdirSync (fs.js:738:3)
at Object.module.exports.makeDirSync (/Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/node_modules/fs-extra/lib/mkdirs/make-dir.js:23:13)
at /Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/node_modules/cordova-android/lib/create.js:231:16
+ /Users/me/.nvm/versions/node/v16.13.2/bin/cordova prepare android
(node:23901) ExperimentalWarning: The fs.promises API is experimental
Discovered platform "android". Adding it to the project
EEXIST: file already exists, mkdir '/Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/platforms'
+ /Users/me/.nvm/versions/node/v16.13.2/bin/cordova build android --debug --verbose
(node:23902) ExperimentalWarning: The fs.promises API is experimental
No platforms added to this project. Please use `cordova platform add <platform>`.
CordovaError: No platforms added to this project. Please use `cordova platform add <platform>`.
at Object.preProcessOptions (/Users/me/.nvm/versions/node/v16.13.2/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/util.js:275:15)
at /Users/me/.nvm/versions/node/v16.13.2/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/build.js:29:31
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:236:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:560:3)
Build step 'Execute shell' marked build as failure
When I look inside the platforms directory on the jenkins box it is empty. It is able to create the platforms folder itself, just nothing else under. It doesn't seem to be a permission issue as far as I can tell. If I ssh into the box as the same user that jenkins in using I can run the cordova commands fine and everything works.
Furthermore, if I add the platform manually by sshing into the box and then let jenkins take over after the android folder already exists, the job works fine. So I guess for some reason it's not able to add the android project.
If it helps, this is what cordova requirements gives:
cordova requirements
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-30,android-29,android-28
Gradle: installed /usr/local/Cellar/gradle/7.3.3/bin/gradle
Okay, I finally figured this SOB out! After taking a few weeks off and coming back to this I noticed that there is a setting in the job config called "Shared Workspace" and I had it set to the value (). I don't know what that means, but it had the effect of putting the code for this project in the
/Users/me/Documents/Jenkins/sharedspace
folder, which apparently was causing problems with cordova. Once I set the Shared Workspace value to NONE, it moved the project to the
/Users/trident/Documents/Jenkins/workspace/my-app
folder which is more what I would expect. After that, lo and behold, everything works.

Ionic Cordova update issue with Android build [duplicate]

This question already has an answer here:
Unable to run cordova run android in IONIC project?
(1 answer)
Closed 5 years ago.
I recently upgraded my Ionic CLI to v3 and updated my Android Studio to the new release as well.
I have a couple existing Ionic v1 projects that were building fine, even after the update, until recently.
My iOS builds fine, but for some reason, my android build is not working.
The error is Error: spawn EACCES
From what I've read about the error, it appears to be a permissions issue that should be resolved by running "chmod 777" on the directory that shows in the error.
I've removed and re-added Cordova as well as removed and re-added the android platform.
But nothing seems to be working!
Below are the results of my android build command with the --verbose flag.
I was hoping someone a lot smarter than me might see something I'm missing.
Results of running build with --verbose:
Mac myprogram$ chmod 755 hooks/after_prepare/*
Mac myprogram$ cordova build android --verbose
No scripts found for hook "before_build".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at /Users/mymac/Documents/Projects/myprogram/platforms/android/res/xml/config.xml
Merging project's config.xml into platform-specific android config.xml
Merging and updating files from [www, platforms/android/platform_www] to platforms/android/assets/www
copy www/index.html platforms/android/assets/www/index.html (updated file)
Wrote out android application name "myprogram" to /Users/mymac/Documents/Projects/myprogram/platforms/android/res/values/strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (0.0.1): 1
Wrote out Android package name "com.freshconsulting.chainlink.myprogram" to /Users/mymac/Documents/Projects/myprogram/platforms/android/src/com/freshconsulting/chainlink/myprogram/MainActivity.java
Updating icons at platforms/android/res
Updating splash screens at platforms/android/res
This app does not have additional resource files defined
Prepared android project successfully
Executing script found in hooks directory for hook "after_prepare": hooks/after_prepare/010_add_platform_class.js
Running command: /Users/mymac/Documents/Projects/myprogram/hooks/after_prepare/010_add_platform_class.js /Users/mymac/Documents/Projects/myprogram
add to body class: platform-android
Command finished with error code 0: /Users/mymac/Documents/Projects/myprogram/hooks/after_prepare/010_add_platform_class.js /Users/mymac/Documents/Projects/myprogram
Executing script found in plugin cordova-plugin-facebook4 for hook "after_prepare": plugins/cordova-plugin-facebook4/scripts/after_prepare.js
No scripts found for hook "before_compile".
Running command: /usr/libexec/java_home
Command finished with error code 0: /usr/libexec/java_home
ANDROID_HOME=/Users/mymac/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
Running command: "/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle" -p /Users/mymac/Documents/Projects/myprogram/platforms/android wrapper -b /Users/mymac/Documents/Projects/myprogram/platforms/android/wrapper.gradle
Error: spawn EACCES
Any ideas would be GREATLY appreciated!
Resolve problem with:
sudo chmod 755 /Applications/Android\ Studio.app/Contents/gradle/gradle-XXX/bin/gradle

Unable to generate android apk file through Ionic Project

I recently buy one ionic project, i had tried a lot to generate APK file but unable to successful.
First i download the file and run cmd.goto the files directory.
i run the command ionic platform add android , bit it says
After Executing ionic platform add android
if i rename ionic.project to ionic.config.json and again execute ionic platform add android it says * Looks like a fresh checkout! No ./node_modules directory found. Would you like to install proj
ect dependencies?*
After installing npm i execute ionic build --release android but it does nothing and gives me warning
[WARN] Not performing Ionic build for project type: ionic1.
[WARN] Error with .\www\lib\ionic\version.json file: FILE_NOT_FOUND, trying .\bower.json.
Warning
Please help me out i am badly stuck.
Had the same problem after updating.
ionic lib update does not work if there is no www/lib/ionic.
You can create it though by copying manually from node_modules/ionic-sdk/release.
This removed the FILE_NOT_FOUND errors for me.

on a fresh install of PhoneGap, "phonegap run android" results in "Error: Cannot read property 'length' of undefined"

The objective:
My goal at this point is to simply create a new phonegap app based on their hello-world template, and test it in an Android emulator on my Windows PC. I've run into a number of snags along the way, most of which I've been able to resolve, until now. I'm a relative newcomer to node.js, and this is the first time I've ever tried using phonegap; I'm trying to use this template as a way to get started.
There seem to be two similar issues on this site, but I wasn't able to extract a working solution from either:
Cordova Android build error "Cannot read property 'length' of undefined"
https://pt.stackoverflow.com/questions/219442/cordova-build-android-error-cannot-read-property-length-of-undefined
First I'll explain exactly what I'm typing and what response I'm getting. Then I'll provide more details about my environment, and the steps I've taken to get this far.
The command:
$ phonegap run android
The response:
[phonegap] executing 'cordova run android ' ...
ANDROID_HOME=c:\android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131
Error: Cannot read property 'length' of undefined
There's not even any indication of where this error happened, which makes it especially difficult to track down in a library full of code I've never seen before.
The sample app:
I haven't even done any coding at this point. The app I'm trying to run was generated using this command:
phonegap create pgHello --id "com.pghello.app" --name "pgHello" --template hello-world
My environment:
Windows 7 Professional x64 SP1
Java SDK 8u131 (I had to install this because 7u79 was too old.) I also had to manually configure the JAVA_HOME and ANDROID_HOME environment variables.
npm 5.2.0:
$ npm version
{ npm: '5.2.0',
ares: '1.10.1-DEV',
cldr: '30.0.3',
http_parser: '2.7.0',
icu: '58.2',
modules: '51',
node: '7.9.0',
openssl: '1.0.2k',
tz: '2016j',
unicode: '9.0',
uv: '1.11.0',
v8: '5.5.372.43',
zlib: '1.2.11' }
phonegap 6.5.2 (installed via npm)
cordova 6.5.0 (part of phonegap)
cordova android platform 6.2.2 (updated via phonegap because the older version was having fits over a missing gradle; with this, the gradle problem went away. That solution was found here: Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK - Android)
Android Studio 2.3.3 (here's a link to my Android SDK tools screen capture)
UPDATE:
This time I executed the same command with the --verbose flag:
No scripts found for hook "before_run".
No scripts found for hook "before_prepare".
Checking config.xml for saved platforms that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at C:\nodejs\apps\pgHello\platforms\android\res\xml\config.xml
Merging project's config.xml into platform-specific android config.xml
Merging and updating files from [www, platforms\android\platform_www] to platforms\android\assets\www
Wrote out android application name "pgHello" to C:\nodejs\apps\pgHello\platforms\android\res\values\strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (1.0.0): 10000
Wrote out Android package name "com.pghello.app" to C:\nodejs\apps\pgHello\platforms\android\src\com\pghello\app\MainActivity.java
Updating icons at platforms\android\res
Updating splash screens at platforms\android\res
This app does not have additional resource files defined
Prepared android project successfully
No scripts found for hook "after_prepare".
Checking config.xml for saved plugins that haven't been added to the project
ANDROID_HOME=c:\android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131
Error: TypeError: Cannot read property 'length' of undefined
at Object.module.exports.check_gradle (C:\nodejs\apps\pgHello\platforms\android\cordova\lib\check_reqs.js:143:19)
at GradleBuilder.prepEnv (C:\nodejs\apps\pgHello\platforms\android\cordova\lib\builders\GradleBuilder.js:176:23)
at Api.module.exports.run (C:\nodejs\apps\pgHello\platforms\android\cordova\lib\build.js:152:20)
at C:\nodejs\apps\pgHello\platforms\android\cordova\Api.js:348:43
at _fulfilled (C:\nodejs\apps\pgHello\platforms\android\cordova\node_modules\q\q.js:854:54)
at self.promiseDispatch.done (C:\nodejs\apps\pgHello\platforms\android\cordova\node_modules\q\q.js:883:30)
at Promise.promise.promiseDispatch (C:\nodejs\apps\pgHello\platforms\android\cordova\node_modules\q\q.js:816:13)
at C:\nodejs\apps\pgHello\platforms\android\cordova\node_modules\q\q.js:624:44
at runSingle (C:\nodejs\apps\pgHello\platforms\android\cordova\node_modules\q\q.js:137:13)
at flush (C:\nodejs\apps\pgHello\platforms\android\cordova\node_modules\q\q.js:125:13)
Is this a bug in gradle?
UPDATE 2:
Since PhoneGap essentially is Cordova, I decided to nix the phonegap package and install cordova instead. The results, perhaps unsurprisingly, are very similar.
$ npm uninstall -g phonegap
removed 873 packages in 87.918s
$ npm install -g cordova
npm WARN deprecated node-uuid#1.4.8: Use uuid module instead
C:\Users\bbale\AppData\Roaming\npm\cordova -> C:\Users\bbale\AppData\Roaming\npm\node_modules\cordova\bin\cordova
+ cordova#7.0.1
added 602 packages in 107.461s
$ cordova create pushTest com.copperfielld.kostizi.pushtest pushTest
Creating a new cordova project.
$ cd pushtest
$ cordova platform add android#6.2.3
Using cordova-fetch for cordova-android#6.2.3
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms\android
Package: com.copperfielld.kostizi.pushtest
Name: pushTest
Activity: MainActivity
Android target: android-25
Subproject Path: CordovaLib
Android project created with cordova-android#6.2.3
Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project
Installing "cordova-plugin-whitelist" for android
This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in.
Adding cordova-plugin-whitelist to package.json
Saved plugin info for "cordova-plugin-whitelist" to config.xml
--save flag or autosave detected
Saving android#~6.2.3 into config.xml file ...
$ cordova run android
ANDROID_HOME=c:\android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131
Error: Cannot read property 'length' of undefined
$ cordova run android --verbose
No scripts found for hook "before_run".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at C:\nodejs\apps\pushTest\platforms\android\res\xml\config.xml
Merging project's config.xml into platform-specific android config.xml
Merging and updating files from [www, platforms\android\platform_www] to platforms\android\assets\www
Wrote out android application name "pushTest" to C:\nodejs\apps\pushTest\platforms\android\res\values\strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (1.0.0): 10000
Wrote out Android package name "com.copperfielld.kostizi.pushtest" to C:\nodejs\apps\pushTest\platforms\android\src\com\copperfielld\kostizi\pushtest\MainActivity.java
This app does not have launcher icons defined
This app does not have splash screens defined
This app does not have additional resource files defined
Prepared android project successfully
No scripts found for hook "after_prepare".
ANDROID_HOME=c:\android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131
Error: Cannot read property 'length' of undefined
To answer my own question from earlier: no, this doesn't appear to be a bug in gradle. It seems to be a bug in the cordova android platform where it checks to see if gradle is installed--so gradle hasn't even been invoked yet.
I suspect this because versions of the cordova android platform prior to 6.2.2 will throw "Error: Error" instead of "Error: Cannot read property 'length' of undefined".
Can anyone verify that this is the case?
UPDATE 3:
Trying a new command here:
$ cordova requirements
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-26,android-25,android-24,Google Inc.:Google APIs:24,android-23,android-22,android-21
Gradle: not installed
Cannot read property 'length' of undefined
Error: Some of requirements check failed
It says Gradle is not installed, but I can verify that it is:
$ gradle -v
------------------------------------------------------------
Gradle 4.0.1
------------------------------------------------------------
Build time: 2017-07-07 14:02:41 UTC
Revision: 38e5dc0f772daecca1d2681885d3d85414eb6826
Groovy: 2.4.11
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_131 (Oracle Corporation 25.131-b11)
OS: Windows 7 6.1 amd64
I've also tried setting GRADLE_HOME and GRADLE_PATH environment variables, to no avail.
It turns out the solution to this problem was this:
uninstall Android Studio
delete any folders from Program Files with names similar to "Android Studio"
reinstall Android Studio
The cause of the problem is that the build script was looking for an apparently hard-coded path, "C:\Program Files\Android\Android Studio\gradle", to find out what versions of gradle were installed.
But I had recently upgraded to a new version of Android Studio on my machine, and the installer put the new version in a different folder: "C:\Program Files\Android\Android Studio1" instead of "C:\Program Files\Android\Android Studio".
I could have copied the gradle folder from the "Android Studio1" folder to the "Android Studio" folder. That would have been a workable quick fix, but I would have lost the ability to take advantage of automatic updates for gradle in Android Studio. The "uninstall/delete/install" method is much more reliable.
This is the ticket I submitted to Apache's Cordova project:
https://issues.apache.org/jira/browse/CB-13104
Nikita Matrosov provided the key piece of information I needed to solve this problem.
I had this error in ionic and solved it by setting gradle path in windows 7
GRADLE_HOME=C:\Users\myUser\.gradle\wrapper\dists\gradle-5.4.1-all\xyz..lablabla\gradle-5.4.1
path= %GRADLE_HOME%\bin;%path%
and then open new console and check if it's work by this command
gradle -v
close your console or your id like vscode and then run
phonegap run android
or
ionic cordova run android

Upgraded to Phonegap3, project does not load needed plugins correctly

So I've tried posting some of these issues on the Phonegap forum but have not heard from anyone regarding my issues...
I recently upgraded from PG 2.9 to 3.3 and am having trouble adjusting my project to the change... it should be as easy as installing phonegap 3.3 and creating a new project and dragging my /www to the root of the project and calling the cordova CLI commands to build and update my project-- both of which say that they complete successfully.
But it's not that easy! Instead, building and updating my project deletes the cordova2.9.jar and does not create a 3.3.0 jar... so I build it myself which goes fine. I stick it in my /libs folder and my app loads on my phone finally... The problem now is that running in PG 3 requires a change in how API calls are handled-- they are all plugins which you have to install before using them... so I installed all of the needed plugins...
The problem now is this message in logcat within Eclipse:
Unable to open asset URL: file:///android_asset/www/cordova/lib/cordova_plugins.js
so I find this cordova_plugins.js file in the root of my assets/www/ directory (Why is it here?! Shouldn't this be automated by cordova build & update to the correct location?!) So I try to copy the file to /www/cordova/lib/ where the error reports it is trying to find it.
When I do this, I get all of these errors:
Unable to open asset URL:file:///android_asset/www/cordova/lib/plugins/org.apache.cordova.file/www/DirectoryEntry.js
Unable to open asset URL:file:///android_asset/www/cordova/lib/plugins/org.apache.cordova.file/www/DirectoryReader.js
Unable to open asset URL:file:///android_asset/www/cordova/lib/plugins/org.apache.cordova.file/www/File.js
Unable to open asset URL:file:///android_asset/www/cordova/lib/plugins/org.apache.cordova.file/www/Entry.js
...etc (basically every plug-in that I had installed in the project.)
I am clearly missing something here... relocating these javascript files to the correct directory manually should not be what I need to do...
I should mention that this original error occurred when I was running the application in PG2.9 but the only plugins that I needed to use were included by default so I could still use the needed API functionalities.
Any ideas here?
You must need to create and deploy any phonegap project/application using Phonegap Command Line Interface
To Create any project write following command on command line:
$ phonegap create <path> <package_name> <project_name>
i.e.
$ phonegap create hello com.example.hello HelloWorld
To add any platform to your project:
cd <path_to_project>
$ phonegap build <platform>
i.e.
cd hello
$ phonegap build ios
$ phonegap build android
To add any plugin feature to your project:
cd <path_to_project>
$ phonegap local plugin add <path_to_plugin>
i.e.
cd hello
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

Categories

Resources