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

Cordova@9 doesn't know how to update AndroidManifest.xml #239

Open
staltz opened this issue Jan 13, 2020 · 6 comments
Open

Cordova@9 doesn't know how to update AndroidManifest.xml #239

staltz opened this issue Jan 13, 2020 · 6 comments

Comments

@staltz
Copy link

staltz commented Jan 13, 2020

  • Project: nodejs-mobile-cordova
  • Version: 0.3.4
  • Mobile device: Google Nexus 5
  • Mobile OS and version: Android 6.0
  • Development Node.js: 10.15.3
  • Development platform: Linux

Using Cordova 9.0.0, I noticed this error Unable to graft xml at selector "/manifest/uses-sdk":

$ cordova platform add android

Using cordova-fetch for cordova-android@8.1.0
Adding android project...
Creating Cordova project for the Android platform:
	Path: platforms/android
	Package: se.cret
	Name: SecretApp
	Activity: MainActivity
	Android target: android-28
Subproject Path: CordovaLib
Subproject Path: app
Android project created with cordova-android@8.1.0
Discovered saved plugin "cordova-plugin-whitelist". Adding it to the project
Installing "cordova-plugin-whitelist" for android
Adding cordova-plugin-whitelist to package.json
Discovered saved plugin "nodejs-mobile-cordova". Adding it to the project
Installing "nodejs-mobile-cordova" for android
Failed to install 'nodejs-mobile-cordova': Error: Unable to graft xml at selector "/manifest/uses-sdk" from "/home/staltz/secretapp/platforms/android/app/src/main/AndroidManifest.xml" during config install
    at ConfigFile_graft_child [as graft_child] (/home/staltz/secretapp/node_modules/cordova-common/src/ConfigChanges/ConfigFile.js:120:19)
    at PlatformMunger_apply_file_munge [as apply_file_munge] (/home/staltz/secretapp/node_modules/cordova-common/src/ConfigChanges/ConfigChanges.js:81:34)
    at munge_helper (/home/staltz/secretapp/node_modules/cordova-common/src/ConfigChanges/ConfigChanges.js:238:14)
    at PlatformMunger.add_plugin_changes (/home/staltz/secretapp/node_modules/cordova-common/src/ConfigChanges/ConfigChanges.js:159:12)
    at /home/staltz/secretapp/node_modules/cordova-common/src/PluginManager.js:123:29
    at _fulfilled (/home/staltz/secretapp/node_modules/q/q.js:854:54)
    at /home/staltz/secretapp/node_modules/q/q.js:883:30
    at Promise.promise.promiseDispatch (/home/staltz/secretapp/node_modules/q/q.js:816:13)
    at /home/staltz/secretapp/node_modules/q/q.js:877:14
    at runSingle (/home/staltz/secretapp/node_modules/q/q.js:137:13)
Failed to restore plugin "nodejs-mobile-cordova" from config.xml. You might need to try adding it again. Error: Error: Unable to graft xml at selector "/manifest/uses-sdk" from "/home/staltz/secretapp/platforms/android/app/src/main/AndroidManifest.xml" during config install

I fixed this easily by deleting the uses-sdk edit-config:

diff --git a/node_modules/nodejs-mobile-cordova/plugin.xml b/node_modules/nodejs-mobile-cordova/plugin.xml
index 8f415b6..9a223c3 100644
--- a/node_modules/nodejs-mobile-cordova/plugin.xml
+++ b/node_modules/nodejs-mobile-cordova/plugin.xml
@@ -74,10 +74,6 @@
       <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     </config-file>
 
-    <edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="merge">
-      <uses-sdk android:minSdkVersion="21" />
-    </edit-config>
-
     <source-file src="src/android/java/com/janeasystems/cdvnodejsmobile/NodeJS.java" target-dir="src/com/janeasystems/cdvnodejsmobile/" />
 
     <source-file src="src/common/cordova-bridge/cordova-bridge.h" target-dir="libs/cdvnodejsmobile/" />

And by creating this new hook that creates a file build-extras.gradle that will set the min sdk level:

const fs = require('fs');
const path = require('path');
module.exports = function(context) {
  const filePath = path.join(
    context.opts.projectRoot,
    'platforms',
    'android',
    'build-extras.gradle',
  );
  return fs.promises
    .writeFile(filePath, 'ext.cdvMinSdkVersion = 21\n', 'utf-8')
    .then(() => 'done');
};

It should be pretty straightforward to create a PR for this.

@Arlen22
Copy link

Arlen22 commented Jan 29, 2020

I'm having the same problem. Here's my cordova info if that helps any. I'm running inside a docker container from https://devcenter.bitrise.io/infrastructure/the-environment/, specifically quay.io/bitriseio/android-ndk.

cordova-lib@9.0.1 with:
  cordova-common@3.2.1
  cordova-create@2.0.0
  cordova-fetch@2.0.1
  cordova-serve@3.0.0

Environment: 
  OS: linux
  Node: v10.18.1
  npm: 6.13.4

Plugins:
  nodejs-mobile-cordova

Android platform:
  *************************************************************************
  The "android" command is deprecated.
  For manual SDK, AVD, and project management, please use Android Studio.
  For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
  *************************************************************************
  Running /opt/android-sdk-linux/tools/bin/avdmanager list target

  Available Android targets:==============] 100% Fetch remote repository...       
  ----------
  id: 1 or "android-15"
       Name: Android API 15
       Type: Platform
       API level: 15
       Revision: 5
  ----------
  id: 2 or "android-17"
       Name: Android API 17
       Type: Platform
       API level: 17
       Revision: 3
  ----------
  id: 3 or "android-19"
       Name: Android API 19
       Type: Platform
       API level: 19
       Revision: 4
  ----------
  id: 4 or "Google Inc.:Google APIs:21"
       Name: Google APIs
       Type: Add-On
       Vendor: Google Inc.
       Revision: 1
       Description: Google APIs
       Based on Android 5.0 (API level 21)
       Libraries:
        * com.google.android.maps (maps.jar)
            API for Google Maps
        * com.android.future.usb.accessory (usb.jar)
            API for USB Accessories
        * com.google.android.media.effects (effects.jar)
            Collection of video effects
  ----------
  id: 5 or "android-21"
       Name: Android API 21
       Type: Platform
       API level: 21
       Revision: 2
  ----------
  id: 6 or "Google Inc.:Google APIs:22"
       Name: Google APIs
       Type: Add-On
       Vendor: Google Inc.
       Revision: 1
       Description: Google APIs
       Based on Android 5.1 (API level 22)
       Libraries:
        * com.google.android.maps (maps.jar)
            API for Google Maps
        * com.android.future.usb.accessory (usb.jar)
            API for USB Accessories
        * com.google.android.media.effects (effects.jar)
            Collection of video effects
  ----------
  id: 7 or "android-22"
       Name: Android API 22
       Type: Platform
       API level: 22
       Revision: 2
  ----------
  id: 8 or "Google Inc.:Google APIs:23"
       Name: Google APIs
       Type: Add-On
       Vendor: Google Inc.
       Revision: 1
       Description: Google APIs
       Based on Android 6.0 (API level 23)
       Libraries:
        * com.google.android.maps (maps.jar)
            API for Google Maps
        * com.android.future.usb.accessory (usb.jar)
            API for USB Accessories
        * com.google.android.media.effects (effects.jar)
            Collection of video effects
  ----------
  id: 9 or "android-23"
       Name: Android API 23
       Type: Platform
       API level: 23
       Revision: 3
  ----------
  id: 10 or "android-24"
       Name: Android API 24
       Type: Platform
       API level: 24
       Revision: 2
  ----------
  id: 11 or "android-25"
       Name: Android API 25
       Type: Platform
       API level: 25
       Revision: 3
  ----------
  id: 12 or "android-26"
       Name: Android API 26
       Type: Platform
       API level: 26
       Revision: 2
  ----------
  id: 13 or "android-27"
       Name: Android API 27
       Type: Platform
       API level: 27
       Revision: 3
  ----------
  id: 14 or "android-28"
       Name: Android API 28
       Type: Platform
       API level: 28
       Revision: 6
  ----------
  id: 15 or "android-29"
       Name: Android API 29
       Type: Platform
       API level: 29
       Revision: 4

@Arlen22
Copy link

Arlen22 commented Feb 5, 2020

And the nodejs variable is not defined.

@dtrax
Copy link

dtrax commented May 21, 2020

https://github.com/dtrax/nodejs-cordova-plugin

I have fixed the project for cordova 9 and cordova-android 8.1.0 here. You can use this one until it is fixed here.

@plmercereau
Copy link

Thanks for your help @staltz et al.
I'm still stuck with the same error as @Arlen22
@dtrax, you mean we install through cordova plugin add https://github.com/dtrax/nodejs-cordova-plugin?

@jb33k
Copy link

jb33k commented Jul 10, 2020

@dtrax could you please spare a minute to answer @plmercereau above. I'm also stuck at the same step. I can get cordova to seemingly install nodejs-cordova-plugin but it looks like it doesn't execute actual installation of the plugin because I can't see it in the config.xml for example. Thanks for helping!

@iMrDJAi
Copy link

iMrDJAi commented Aug 25, 2020

it's: cordova plugin add https://github.com/dtrax/nodejs-cordova-plugin.git

iMrDJAi added a commit to iMrDJAi/nodejs-mobile-cordova that referenced this issue Mar 25, 2021
iMrDJAi added a commit to iMrDJAi/nodejs-mobile-cordova that referenced this issue Mar 25, 2021
jaimecbernardo pushed a commit to JaneaSystems/nodejs-mobile-cordova that referenced this issue Jul 30, 2021
* Patched to work with cordova-android@9.0.0

JaneaSystems/nodejs-mobile#239 (comment)

* Patched to work with cordova-android@9.0.0

JaneaSystems/nodejs-mobile#239 (comment)

* Updated build.gradle

* Removed copy-build-extras-gradle hook

* Delete build-extras.gradle

* Delete copy-build-extras-gradle.js

* Create build-apk.yaml

* Fixed a typo

* Delete build-apk.yaml

* Added "Build Android Project" test

* Added "Build IOS Project" test

* Update package.json

* Update build-ios.yaml

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

No branches or pull requests

7 participants