function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Brian KesslerBrian Kessler 

Why is Cordova failing when I try to get started with Hybrid Development?

Hi!

I'm currently trying to work my way through the Trailhead "Get Started with Hybrid Development", but am having problems when I attempt to "forcedroid create".

When it gets to "Installing "cordova-plugin-whitelist" for android" it fails with:
 
Failed to install 'cordova-plugin-whitelist':TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.join (path.js:466:7)
at D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\lib\check_reqs.js:177:42
at _fulfilled (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:796:13)
at D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:857:14
at runSingle (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:137:13)
at flush (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:125:13)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
Failed to restore plugin "cordova-plugin-whitelist" from config.xml. You might need to try adding it again. Error: TypeError: Path must be a string. Received undefined



This error is not imediately fatal, but after a time I see:
 
Installing "cordova-plugin-whitelist" for android
Failed to install 'cordova-plugin-whitelist':TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.join (path.js:466:7)
at D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\lib\check_reqs.js:177:42
at _fulfilled (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:796:13)
at D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:857:14
at runSingle (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:137:13)
at flush (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:125:13)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
Failed to install 'com.salesforce':TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.join (path.js:466:7)
at D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\lib\check_reqs.js:177:42
at _fulfilled (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:796:13)
at D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:857:14
at runSingle (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:137:13)
at flush (D:\tutorials\AndroidStudioProjects\THA\platforms\android\cordova\node_modules\q\q.js:125:13)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
D:\tutorials\AndroidStudioProjects
forcedroid create failed

Command failed: cordova plugin add https://github.com/forcedotcom/SalesforceMobileSDK-CordovaPlugin#v5.0.0 --force
Error: Path must be a string. Received undefined



Whereas, this last bit is fatal.

FWIW,
OS: Windows XP SP3
Java: 1.8.0_121
Node: 5.12.0
Npm: 4.2.0
Cordovoa: 6.5.0

ANDROID_HOME: C:\devtools\Android\sdk
ANDROID_SDK_HOME: C:\devtools\Android\sdk
JAVA_HOME: C:\devtools\Java\jdk1.8.0_121
JDK_HOME: %JAVA_HOME%
JRE_HOME: %JAVA_HOME%\jre
CLASSPATH: .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
User PATH: %JAVA_HOME%\bin;C:\Documents and Settings\Brian Kessler\Application Data\npm
System PATH: C:\Documents and Settings\All Users\Application Data\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Pinnacle\Shared Files\InstantCDDVD\;C:\WINXPSP3\system32\WindowsPowerShell\v1.0;C:\Program Files\Skype\Phone\;C:\Program Files\Kensington\TrackballWorks;C:\devtools\Git\cmd;C:\devtools\Git\GitExtensions\;C:\devtools\nodejs\;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools

Any ideas what is wrong or how to fix this?
Best Answer chosen by Brian Kessler
Brian KesslerBrian Kessler
Finally got it working on Windows XP again.  Here is a complete list of what I needed to do:

1. Use Android Studio 2.2.3 (NOT anything newer!  And don't allow it to update!)

1. Do not install Android Studio to the default directory or use any other path which contains whitespace.
(Gradle has problems with the whitespace.)

2. Use NOX instead of an Android Studio provided emulator.
(Android's emulators are incompatible with an AMD chipset.)
https://www.bignox.com/
https://www.bignox.com/blog/how-to-connect-android-studio-with-nox-app-player-for-android-development-and-debug/

3. Replace Android SDK Platform Tools with Platform Tools version 16.
(Newer versions of Platform Tools are incompatible with Windows XP.)
http://androidtoolsofflinedownload.blogspot.hu/p/download-android-build.html

4. Copy hprof-conv.exe from recent version of Platform Tools into sdk\platform-tools directory.
(Platform Tools v 16.0 does not include this, but it is needed by Android Studio.)

5. Check if sdk\tools\templates exists.
  If not, you need to manually download the SDK from Android and copy the templates into your sdk\tools directory.
  
6.  Use Windows Command instead of Git Bash.  
(Forcedroid or Cordova seems incompatible with Git Bash).

7. Put the TrailHybridApps directory on the root
(Gradle has problems with long directory/file paths.)

8. Remove restrictionType attributes from the app_restrictions.xml
(This attributes is not recognized, perhaps as a result of one of the changes above; this causes a fatal error.)

9. Use JDK 1.8 instead of Android's included JRE.
(Gradle has problems with the Android's JRE.)
File > Project Structure > [Platform Settings] > SDKs
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

10. Add the following to the beginning of firstapp\platforms\android\build.gradle:
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        //YOUR DEPEDENCIES
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
        classpath 'com.github.dcendents:android-maven-plugin:1.2'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

11. Allow Android Studio to upgrade Gradle plugin

All Answers

Logan Smith 10Logan Smith 10
So, I was wrestling with this for HOURS today.  The problem is in the location of your SDK files.  I bet you have two names for your login into Windows or at least a space between words?  When you look at the Android Studio, you will see that there is an error saying that the SDK can't have blank spaces, and because of your user name, the folder has a space that proceeds your documents (C:\Users\Logan Smith\Documents).  This is causing all of the headach...  You need to copy and paste the SDK file to your C:\ and then, re-open your Android Stuidio.  It will notice the SDK folder is missing, and will want to re-run the wizard.  Make sure you change the location so that it is in the folder you moved to the C:\

I tried renaming the folder, but it was more trouble than it's worth... Easier to just move the folder.  Hope this helps someone else...
Brian KesslerBrian Kessler
Hi Logan,

Thanks for your response, but I'm a little unclear about your recommendation.

As I have XP, Windows stores its profile data in:
C:\Documents and Settings\Brian Kessler

However, "My Documents" redirects to:
D:\Brian Stuff

Neither of these are relevant to my SDK which is stored in:
C:\devtools\Android\sdk

I'm executing forcedroid create from within git bash, having first navigated to
/d/tutorials/AndroidStudioProjects

So far as I know -- please correct me if I'm wrong -- there is no possiblity to execute the forcedroid node package  from within Android Studio.

As far as the Android Studio is concerned, there is an error displaying (in a project which has little to do with this --  I just created a project so I could navigate to the Tools menu), but it is completely different:
Error: CreateProcess error=193, %1 is not a valid Win32 application

... So, I think I may be having different headaches...





 
Logan Smith 10Logan Smith 10
As far as I know, you are correct that you can not run it from Studio, but I was having the same problem when I ran forcedroid create.  If you open SDK Manager from Studio, do you see any errors?
Brian KesslerBrian Kessler
The only visible error is in the "Messages Gradle Sync" dialog.
Nested under "Gradle 'SFDC_Trailhead' project refresh failed, there is:
Error: CreateProcess error=193, %1 is not a valid Win32 application

 
Brian KesslerBrian Kessler
Still haven't completed the module, but I solved this problem:

1.  Use Windows Command instead of Git Bash.  
(Forcedroid or Cordova seems incompatible with Git Bash).

And many others:

2. Do not install Android Studio to the default directory or use any other path which contains whitespace.
(Gradle has problems with the whitespace.)

3. Use JDK 1.8 instead of Android's included JRE.
(Gradle has problems with the Android's JRE.)
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

4. Put the TrailHybridApps directory on the root
(Gradle has problems with long directory/file paths.)

5. Use NOX instead of an Android Studio provided emulator.
(Android's emulators are incompatible with an AMD chipset.)
https://www.bignox.com/
https://www.bignox.com/blog/how-to-connect-android-studio-with-nox-app-player-for-android-development-and-debug/

6. Replace Android SDK Platform Tools with Platform Tools version 16.
(Newer versions of Platform Tools are incompatible with Windows XP.)
http://androidtoolsofflinedownload.blogspot.hu/p/download-android-build.html

7. Copy hprof-conv.exe from recent version of Platform Tools into sdk\platform-tools directory.
(Platform Tools v 16.0 does not include this, but it is needed by Android Studio.)

8. Remove restrictionType attributes from the app_restrictions.xml
(This attributes is not recognized, perhaps as a result of one of the changes above; this causes a fatal error.)


Near enough 24 hours later...
... Hope this helps someone else!!!


 
KhalèdKhalèd
This donesn't solve my problem: 
Here is a sreenshot showing the result of forcedroid create:
I'm using windows 7 .
Result of forcedroid create ( windows 7)
 
Brian KesslerBrian Kessler
I've been seeing this lately as I try to do a different Trailhead project.

It seems that the most recent SDK installed by Android no longer includes the template files.
You need to manually download the SDK from Android and copy the templates into your sdk\tools directory.

That said,
Since I started seeing that problem, even with this fix, I haven't gotten the project to actually work... so you may need a specific version of the templates or there may be other requirements I haven't figured out yet.


 
KhalèdKhalèd
Hi Brian, 
This is really what I did and it works.
the /sdk/tools/ folder should really contains the template folder to avoid the error.
Best Regards.
Brian KesslerBrian Kessler
Glad to hear that worked for you.

I'm still struggling with it.

Going to see if I can get and reinstall an older version of Android Studio as the current one (after a very recent upgrade) won't let me select the JDK anymore.
Brian KesslerBrian Kessler
Finally got it working on Windows XP again.  Here is a complete list of what I needed to do:

1. Use Android Studio 2.2.3 (NOT anything newer!  And don't allow it to update!)

1. Do not install Android Studio to the default directory or use any other path which contains whitespace.
(Gradle has problems with the whitespace.)

2. Use NOX instead of an Android Studio provided emulator.
(Android's emulators are incompatible with an AMD chipset.)
https://www.bignox.com/
https://www.bignox.com/blog/how-to-connect-android-studio-with-nox-app-player-for-android-development-and-debug/

3. Replace Android SDK Platform Tools with Platform Tools version 16.
(Newer versions of Platform Tools are incompatible with Windows XP.)
http://androidtoolsofflinedownload.blogspot.hu/p/download-android-build.html

4. Copy hprof-conv.exe from recent version of Platform Tools into sdk\platform-tools directory.
(Platform Tools v 16.0 does not include this, but it is needed by Android Studio.)

5. Check if sdk\tools\templates exists.
  If not, you need to manually download the SDK from Android and copy the templates into your sdk\tools directory.
  
6.  Use Windows Command instead of Git Bash.  
(Forcedroid or Cordova seems incompatible with Git Bash).

7. Put the TrailHybridApps directory on the root
(Gradle has problems with long directory/file paths.)

8. Remove restrictionType attributes from the app_restrictions.xml
(This attributes is not recognized, perhaps as a result of one of the changes above; this causes a fatal error.)

9. Use JDK 1.8 instead of Android's included JRE.
(Gradle has problems with the Android's JRE.)
File > Project Structure > [Platform Settings] > SDKs
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

10. Add the following to the beginning of firstapp\platforms\android\build.gradle:
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        //YOUR DEPEDENCIES
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
        classpath 'com.github.dcendents:android-maven-plugin:1.2'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

11. Allow Android Studio to upgrade Gradle plugin
This was selected as the best answer
Natalya MurphyNatalya Murphy
Here is what finally fixed it for me:

- Downgraded Cordova (see the "Set Up Your Hybrid Development Environment (https://trailhead.salesforce.com/projects/mobilesdk_setup_dev_tools/steps/mobilesdk_setup_hybrid)" trailhead)
(this got me farther but gave me a new error message about ANDROID_HOME not being set.  So, I...
- Set ANDROID_HOME to C:\Users\Natalya\AppData\Local\Android\sdk (*Note: you'll want to change this to point to your local install)

And, FINALLY, I was able to create the app.

P.S.  although I initially fiddled around with adding the template folder, this ended up not helping so I restored the original folder settings back.  
Summer Armitage 5Summer Armitage 5
User-added image

This is the error I get. I've set the ANDROID_HOME. Help!!!!!
Scott WScott W
Need to set ANDROID_HOME before running forcehybrid create

set ANDROID_HOME=C:\ installation location \android\sdk

https://stackoverflow.com/questions/26356359/error-android-home-is-not-set-and-android-command-not-in-your-path-you-must
asg aseasg ase
Can we share this script with dynamic hosted wbeiste? I want to try it for my mini militia mod apk (https://perfectapk.com/mini-militia-mod-apk/) blog.
James DsavageJames Dsavage
can you please share those scripts that works i want to add in my website mcoc v7 guide (https://axialapk.com/blog/how-to-play-mcoc-beginner-guide/)
David ChumliDavid Chumli
Thanks for the script. Does this script works on my Drawing Tablet Compatible with chromebook (https://techtheeta.com/best-drawing-tablet-compatible-with-chromebook/)
Josh SeoJosh Seo

As far as I know, you are correct that you can not run it from Studio, Granny Mod Menu but I was having the same problem when I ran forcedroid create.  If you open SDK Manager from Studio, do you see any errors?
dit chdit ch

Can we share this script with dynamic hosted wbeiste? I want to try it for my mini militia mod apk (https://apkbeer.com/tivimate-premium-apk/) blog.
 
dit chdit ch
Can we share this script with dynamic hosted wbeiste? I want to try it for my tivimate premium apk (https://apkbeer.com/tivimate-premium-apk/) blog.
 
Hugo LouisHugo Louis
Would script work for dynamic hosted website or it's just working for cross development platform? What if I wish to use it for my blog post https://easybill.pk/sepco-online-bill/ - If it's working for dynamically hosted websites then it's worth admirable. I would definietley love to test it for my site.
Muhammad Adnan 14Muhammad Adnan 14
Is this script compatible with a dynamic-hosted Website (https://onlinebillcheck.pk/iesco-online-bill/)?
FixerrsFixerrs
Fixerrs (https://fixerrs.com) offers a community forum where users can connect with each other and share their experiences. The forum provides a platform for users to seek advice from other community members or even offer their own solutions to help others.