Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI 8.0.1-dev (cordova-lib@9.0.0-dev) can't install local platforms (iOS, Android) #362

Closed
janpio opened this issue Nov 24, 2018 · 16 comments

Comments

@janpio
Copy link
Member

janpio commented Nov 24, 2018

Currently fighting my way through https://github.com/apache/cordova-mobile-spec and using https://github.com/apache/cordova-coho to get everything locally - which means I am working with master of everything.

C:\Projects\throwaway\mobilespecAndroid  (helloworld@1.0.0)
λ cordova -v
8.0.1-dev (cordova-lib@9.0.0-dev)

Now I am having problems with installing the Android platform from a local folder (../cordova-android is the master checkout of cordova-android):

C:\Projects\throwaway\mobilespecAndroid  (helloworld@1.0.0)
λ cordova platform add ../cordova-android --verbose
Warning: using prerelease version 8.0.1-dev (cordova-lib@9.0.0-dev)
No scripts found for hook "before_platform_add".
fetch: Installing C:\Projects\throwaway\cordova-android to C:\Projects\throwaway\mobilespecAndroid
Running command: npm install C:\Projects\throwaway\cordova-android --production --save
Command finished with error code 0: npm install,C:\Projects\throwaway\cordova-android,--production,--save
Removing "cordova-" prefix from cordova-android
Warning: using prerelease platform android@8.0.0-dev.
Use 'cordova platform add android@latest' to add the latest published version instead.
Adding android project...
PlatformApi successfully found for platform android
Creating Cordova project for the Android platform:
        Path: platforms\android
        Package: io.cordova.hellocordova
        Name: HelloCordova
        Activity: MainActivity
        Android target: android-27
Copying android template project to platforms\android
Cannot find module 'cordova-common'
Error: Cannot find module 'cordova-common'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\Projects\throwaway\mobilespecAndroid\platforms\android\cordova\lib\builders\builders.js:20:22)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

The same works from GitHub directly:

C:\Projects\throwaway\mobilespecAndroid  (helloworld@1.0.0)                                                                                                                                                     
λ cordova platform add https://github.com/apache/cordova-android --verbose                                                                                                                                      
Warning: using prerelease version 8.0.1-dev (cordova-lib@9.0.0-dev)                                                                                                                                             
No scripts found for hook "before_platform_add".                                                                                                                                                                
Using cordova-fetch for https://github.com/apache/cordova-android                                                                                                                                               
fetch: Installing https://github.com/apache/cordova-android to C:\Projects\throwaway\mobilespecAndroid                                                                                                          
Running command: npm install https://github.com/apache/cordova-android --production --save                                                                                                                      
Command finished with error code 0: npm install,https://github.com/apache/cordova-android,--production,--save                                                                                                   
Removing "cordova-" prefix from cordova-android                                                                                                                                                                 
Warning: using prerelease platform android@8.0.0-dev.                                                                                                                                                           
Use 'cordova platform add android@latest' to add the latest published version instead.                                                                                                                          
Adding android project...                                                                                                                                                                                       
PlatformApi successfully found for platform android                                                                                                                                                             
Creating Cordova project for the Android platform:                                                                                                                                                              
        Path: platforms\android                                                                                                                                                                                 
        Package: io.cordova.hellocordova                                                                                                                                                                        
        Name: HelloCordova                                                                                                                                                                                      
        Activity: MainActivity                                                                                                                                                                                  
        Android target: android-27                                                                                                                                                                              
Copying android template project to platforms\android                                                                                                                                                           
Subproject Path: CordovaLib                                                                                                                                                                                     
Subproject Path: app                                                                                                                                                                                            
Android project created with cordova-android@8.0.0-dev                                                                                                                                                          
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...                                                                                                          
PlatformApi successfully found for platform android                                                                                                                                                             
Generating platform-specific config.xml from defaults for android at C:\Projects\throwaway\mobilespecAndroid\platforms\android\app\src\main\res\xml\config.xml                                                  
Merging project's config.xml into platform-specific android config.xml                                                                                                                                          
[Gradle Properties] Preparing Configuration                                                                                                                                                                     
[Gradle Properties] File missing, creating file with Cordova defaults.                                                                                                                                          
[Gradle Properties] Appended missing default: org.gradle.daemon=true                                                                                                                                            
[Gradle Properties] Appended missing default: org.gradle.jvmargs=-Xmx2048m                                                                                                                                      
[Gradle Properties] Appended missing default: android.useDeprecatedNdk=true                                                                                                                                     
[Gradle Properties] Updating and Saving File                                                                                                                                                                    
Merging and updating files from [www, platforms\android\platform_www] to platforms\android\app\src\main\assets\www                                                                                              
  mkdir platforms\android\app\src\main\assets\www\cordova-js-src                                                                                                                                                
  mkdir platforms\android\app\src\main\assets\www\cordova-js-src\android                                                                                                                                        
  copy  platforms\android\platform_www\cordova-js-src\android\nativeapiprovider.js platforms\android\app\src\main\assets\www\cordova-js-src\android\nativeapiprovider.js (new file)                             
  copy  platforms\android\platform_www\cordova-js-src\android\promptbasednativeapi.js platforms\android\app\src\main\assets\www\cordova-js-src\android\promptbasednativeapi.js (new file)                       
  copy  platforms\android\platform_www\cordova-js-src\exec.js platforms\android\app\src\main\assets\www\cordova-js-src\exec.js (new file)                                                                       
  copy  platforms\android\platform_www\cordova-js-src\platform.js platforms\android\app\src\main\assets\www\cordova-js-src\platform.js (new file)                                                               
  mkdir platforms\android\app\src\main\assets\www\cordova-js-src\plugin                                                                                                                                         
  mkdir platforms\android\app\src\main\assets\www\cordova-js-src\plugin\android                                                                                                                                 
  copy  platforms\android\platform_www\cordova-js-src\plugin\android\app.js platforms\android\app\src\main\assets\www\cordova-js-src\plugin\android\app.js (new file)                                           
  copy  platforms\android\platform_www\cordova.js platforms\android\app\src\main\assets\www\cordova.js (updated file)                                                                                           
  delete platforms\android\app\src\main\assets\www\img\cordova.png (no source)                                                                                                                                  
  copy  www\index.html platforms\android\app\src\main\assets\www\index.html (updated file)                                                                                                                      
  copy  www\js\index.js platforms\android\app\src\main\assets\www\js\index.js (updated file)                                                                                                                    
Wrote out android application name "HelloCordova" to C:\Projects\throwaway\mobilespecAndroid\platforms\android\app\src\main\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 "io.cordova.hellocordova" to C:\Projects\throwaway\mobilespecAndroid\platforms\android\app\src\main\java\io\cordova\hellocordova\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 "before_prepare".                                                                                                                                                                     
Checking config.xml and package.json for saved platforms that haven't been added to the project                                                                                                                 
Checking config.xml for saved plugins that haven't been added to the project                                                                                                                                    
Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project                                                                                                                            
No scripts found for hook "before_plugin_add".                                                                                                                                                                  
Calling plugman.fetch on plugin "cordova-plugin-whitelist@1"                                                                                                                                                    
fetch: Installing cordova-plugin-whitelist@"1" to C:\Projects\throwaway\mobilespecAndroid                                                                                                                       
Running command: npm install cordova-plugin-whitelist@"1" --save                                                                                                                                                
Command finished with error code 1: npm install,cordova-plugin-whitelist@"1",--save                                                                                                                             
Failed to restore plugin "cordova-plugin-whitelist" from config.xml. You might need to try adding it again. Error: Failed to fetch plugin cordova-plugin-whitelist@1 via registry.                              
Probably this is either a connection problem, or plugin spec is incorrect.                                                                                                                                      
Check your connection and plugin name/version/URL.                                                                                                                                                              
Error: npm: Command failed with exit code 1 Error output:                                                                                                                                                       
npm ERR! code EINVALIDTAGNAME                                                                                                                                                                                   
npm ERR! Invalid tag name ""1"": Tags may not have any characters that encodeURIComponent encodes.                                                                                                              
                                                                                                                                                                                                                
npm ERR! A complete log of this run can be found in:                                                                                                                                                            
npm ERR!     C:\Users\Jan\AppData\Roaming\npm-cache\_logs\2018-11-24T00_58_41_165Z-debug.log                                                                                                                    
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:\Projects\throwaway\mobilespecAndroid\platforms\android\app\src\main\res\xml\config.xml                                                  
Merging project's config.xml into platform-specific android config.xml                                                                                                                                          
[Gradle Properties] Preparing Configuration                                                                                                                                                                     
[Gradle Properties] Updating and Saving File                                                                                                                                                                    
Merging and updating files from [www, platforms\android\platform_www] to platforms\android\app\src\main\assets\www                                                                                              
  copy  platforms\android\platform_www\cordova-js-src\android\nativeapiprovider.js platforms\android\app\src\main\assets\www\cordova-js-src\android\nativeapiprovider.js (updated file)                         
  copy  platforms\android\platform_www\cordova-js-src\android\promptbasednativeapi.js platforms\android\app\src\main\assets\www\cordova-js-src\android\promptbasednativeapi.js (updated file)                   
  copy  platforms\android\platform_www\cordova-js-src\exec.js platforms\android\app\src\main\assets\www\cordova-js-src\exec.js (updated file)                                                                   
  copy  platforms\android\platform_www\cordova-js-src\platform.js platforms\android\app\src\main\assets\www\cordova-js-src\platform.js (updated file)                                                           
  copy  platforms\android\platform_www\cordova-js-src\plugin\android\app.js platforms\android\app\src\main\assets\www\cordova-js-src\plugin\android\app.js (updated file)                                       
  copy  platforms\android\platform_www\cordova.js platforms\android\app\src\main\assets\www\cordova.js (updated file)                                                                                           
  copy  www\index.html platforms\android\app\src\main\assets\www\index.html (updated file)                                                                                                                      
  copy  www\js\index.js platforms\android\app\src\main\assets\www\js\index.js (updated file)                                                                                                                    
Wrote out android application name "HelloCordova" to C:\Projects\throwaway\mobilespecAndroid\platforms\android\app\src\main\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 "io.cordova.hellocordova" to C:\Projects\throwaway\mobilespecAndroid\platforms\android\app\src\main\java\io\cordova\hellocordova\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".                                                                                                                                                                      
Saving android@https://github.com/apache/cordova-android into platforms.json                                                                                                                                    
--save flag or autosave detected                                                                                                                                                                                
Saving android@https://github.com/apache/cordova-android into config.xml file ...                                                                                                                               
adding android to cordova.platforms array in package.json                                                                                                                                                       
No scripts found for hook "after_platform_add".                                                                                                                                                                                                                                                                                                                                                                              

So somehow installing from a local folder is broken.

My npm:

λ npm -v
6.4.1
@janpio
Copy link
Member Author

janpio commented Nov 24, 2018

Here the command to set up your environment this way:

git clone https://github.com/apache/cordova-coho.git
    cd cordova-coho & npm install & cd ..
    node cordova-coho/coho repo-clone -r mobile-spec -r tools -r plugins -r active-platforms
    node cordova-coho/coho npm-link

Should be enough to create a project with cordova-create and then try to install the locally checked out cordova-android.

@gandhirajan

This comment has been minimized.

@janpio

This comment has been minimized.

@gandhirajan

This comment has been minimized.

@janpio

This comment has been minimized.

@gandhirajan

This comment has been minimized.

@janpio

This comment has been minimized.

@gandhirajan

This comment has been minimized.

@janpio

This comment has been minimized.

@janpio
Copy link
Member Author

janpio commented Dec 2, 2018

Here are the command to a full repro, after setting up your system with the coho calls above:

# all Cordova projects were checked out to C:\Projects\cordova5 via coho
C:\Projects\cordova5\cordova-cli\bin\cordova create mobilespec_android org.apache.cordova.mobilespec MobileSpec_Tests --template cordova-mobile-spec\www
cd mobilespec_android 
C:\Projects\cordova5\cordova-cli\bin\cordova platform add "C:\Projects\cordova5\cordova-android" --verbose

(The exact same works for iOS as well)

@janpio
Copy link
Member Author

janpio commented Dec 2, 2018

I debugged and understood the problem in apache/cordova-mobile-spec#159, so here is a copy of my last comment that has all the information:

I now have 2 apps with the Android platform added, one with master and one with 7.1.x: master is missing node_modules in platforms/android/cordova (which is created from https://github.com/apache/cordova-android/tree/master/bin/templates/cordova).

In 7.1.x this was copied there with this line:
https://github.com/apache/cordova-android/blob/7.1.x/bin/lib/create.js#L171

In master this is behind if (options.copyPlatformNodeModules):
https://github.com/apache/cordova-android/blob/master/bin/lib/create.js#L171

This was added in apache/cordova-android#536 by @erisu with the comment:

When platform is installed though CLI, cordova platform add android, the copy node_modules step is no longer valid as dependencies are now at the project level.
The step is required only when the create binary from the platform repo is called.

I was using the CLI to add the platform (C:\Projects\cordova5\cordova-cli\bin\cordova platform add "C:\Projects\cordova5\cordova-android" --verbose), so something went wrong there I guess :/

@janpio
Copy link
Member Author

janpio commented Dec 2, 2018

The problem only manifests when installing master from a local path, not when it is installed from GitHub. (Then I encounter #363 though, but that's a separate problem)

@dpogue
Copy link
Member

dpogue commented Dec 3, 2018

@janpio Regarding the node_modules folder, see apache/cordova#32

@janpio
Copy link
Member Author

janpio commented Dec 3, 2018

Thanks for the pointer, this indeed seems to be the reason - the PR I linked to here was a result of that issue.

@janpio janpio changed the title Problems with CLI 8.0.1-dev (cordova-lib@9.0.0-dev): can't install local Android, hello-world-app plugin CLI 8.0.1-dev (cordova-lib@9.0.0-dev) can't install local platforms (iOS, Android) Dec 3, 2018
@janpio
Copy link
Member Author

janpio commented Dec 3, 2018

@erisu helped me confirm that this does not only happen on Windows and out of the context of coho etc. Here are the reproduction commands:

λ mkdir CordovaLocalPlatformFoo
λ cd CordovaLocalPlatformFoo
λ git clone http://github.com/apache/cordova-cli
λ git clone http://github.com/apache/cordova-android
λ cd cordova-cli
λ npm i
λ cd ..
λ cd cordova-android
λ npm i
λ cd ..

# variant 1: with `npm link`
λ cd cordova-cli
λ npm link
λ cd ..
λ cordova create test1
λ cd test1
λ cordova platform add ../cordova-android

# variant 2: without `npm link`
λ cordova-cli\bin\cordova create test2
λ cd test2
λ ..\cordova-cli\bin\cordova platform add "../cordova-android"

@raphinesse
Copy link
Contributor

I just ran the following commands on my machine successfully (extracted from your reproduction listing @janpio):

git clone http://github.com/apache/cordova-cli && cd cordova-cli
npm i
npm link
cd ..

git clone http://github.com/apache/cordova-android && cd cordova-android
npm i
cd ..

cordova create test1 && cd test1

cordova platform add ../cordova-android

Works for me, YMMV. Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants