cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-13830) Cordova-Android@7.0.0 fails to add a plugin previously removed
Date Mon, 26 Mar 2018 23:09:00 GMT

    [ https://issues.apache.org/jira/browse/CB-13830?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16414743#comment-16414743
] 

ASF GitHub Bot commented on CB-13830:
-------------------------------------

infil00p closed pull request #434: CB-13830: Add handlers for plugins that use non-Java source
files
URL: https://github.com/apache/cordova-android/pull/434
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bin/templates/cordova/Api.js b/bin/templates/cordova/Api.js
index e97f5380a..ae4d17bdd 100644
--- a/bin/templates/cordova/Api.js
+++ b/bin/templates/cordova/Api.js
@@ -248,7 +248,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
     }).then(function () {
         if (plugin.getFrameworks(this.platform).length === 0) return;
         selfEvents.emit('verbose', 'Updating build files since android plugin contained <framework>');
-          // This should pick the correct builder, not just get gradle
+        // This should pick the correct builder, not just get gradle
         require('./lib/builders/builders').getBuilder(this.builder).prepBuildFiles();
     }.bind(this))
         // CB-11022 Return truthy value to prevent running prepare after
diff --git a/bin/templates/cordova/lib/builders/StudioBuilder.js b/bin/templates/cordova/lib/builders/StudioBuilder.js
index 8322e15bd..9587c7558 100644
--- a/bin/templates/cordova/lib/builders/StudioBuilder.js
+++ b/bin/templates/cordova/lib/builders/StudioBuilder.js
@@ -214,28 +214,28 @@ StudioBuilder.prototype.prepBuildFiles = function () {
 StudioBuilder.prototype.prepEnv = function (opts) {
     var self = this;
     return check_reqs.check_gradle()
-      .then(function (gradlePath) {
-          return self.runGradleWrapper(gradlePath);
-      }).then(function () {
-          return self.prepBuildFiles();
-      }).then(function () {
-          // If the gradle distribution URL is set, make sure it points to version we want.
-          // If it's not set, do nothing, assuming that we're using a future version of gradle
that we don't want to mess with.
-          // For some reason, using ^ and $ don't work.  This does the job, though.
-          var distributionUrlRegex = /distributionUrl.*zip/;
-          var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] ||
'https\\://services.gradle.org/distributions/gradle-4.1-all.zip';
-          var gradleWrapperPropertiesPath = path.join(self.root, 'gradle', 'wrapper', 'gradle-wrapper.properties');
-          shell.chmod('u+w', gradleWrapperPropertiesPath);
-          shell.sed('-i', distributionUrlRegex, 'distributionUrl=' + distributionUrl, gradleWrapperPropertiesPath);
-
-          var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
-          var propertiesFilePath = path.join(self.root, propertiesFile);
-          if (opts.packageInfo) {
-              fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
-          } else if (isAutoGenerated(propertiesFilePath)) {
-              shell.rm('-f', propertiesFilePath);
-          }
-      });
+        .then(function (gradlePath) {
+            return self.runGradleWrapper(gradlePath);
+        }).then(function () {
+            return self.prepBuildFiles();
+        }).then(function () {
+            // If the gradle distribution URL is set, make sure it points to version we want.
+            // If it's not set, do nothing, assuming that we're using a future version of
gradle that we don't want to mess with.
+            // For some reason, using ^ and $ don't work.  This does the job, though.
+            var distributionUrlRegex = /distributionUrl.*zip/;
+            var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL']
|| 'https\\://services.gradle.org/distributions/gradle-4.1-all.zip';
+            var gradleWrapperPropertiesPath = path.join(self.root, 'gradle', 'wrapper', 'gradle-wrapper.properties');
+            shell.chmod('u+w', gradleWrapperPropertiesPath);
+            shell.sed('-i', distributionUrlRegex, 'distributionUrl=' + distributionUrl, gradleWrapperPropertiesPath);
+
+            var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
+            var propertiesFilePath = path.join(self.root, propertiesFile);
+            if (opts.packageInfo) {
+                fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
+            } else if (isAutoGenerated(propertiesFilePath)) {
+                shell.rm('-f', propertiesFilePath);
+            }
+        });
 };
 
 /*
@@ -247,33 +247,33 @@ StudioBuilder.prototype.build = function (opts) {
     var args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts);
 
     return spawn(wrapper, args, {stdio: 'pipe'})
-    .progress(function (stdio) {
-        if (stdio.stderr) {
-            /*
-             * Workaround for the issue with Java printing some unwanted information to
-             * stderr instead of stdout.
-             * This function suppresses 'Picked up _JAVA_OPTIONS' message from being
-             * printed to stderr. See https://issues.apache.org/jira/browse/CB-9971 for
-             * explanation.
-             */
-            var suppressThisLine = /^Picked up _JAVA_OPTIONS: /i.test(stdio.stderr.toString());
-            if (suppressThisLine) {
-                return;
+        .progress(function (stdio) {
+            if (stdio.stderr) {
+                /*
+                 * Workaround for the issue with Java printing some unwanted information
to
+                 * stderr instead of stdout.
+                 * This function suppresses 'Picked up _JAVA_OPTIONS' message from being
+                 * printed to stderr. See https://issues.apache.org/jira/browse/CB-9971 for
+                 * explanation.
+                 */
+                var suppressThisLine = /^Picked up _JAVA_OPTIONS: /i.test(stdio.stderr.toString());
+                if (suppressThisLine) {
+                    return;
+                }
+                process.stderr.write(stdio.stderr);
+            } else {
+                process.stdout.write(stdio.stdout);
             }
-            process.stderr.write(stdio.stderr);
-        } else {
-            process.stdout.write(stdio.stdout);
-        }
-    }).catch(function (error) {
-        if (error.toString().indexOf('failed to find target with hash string') >= 0) {
-            return check_reqs.check_android_target(error).then(function () {
-                // If due to some odd reason - check_android_target succeeds
-                // we should still fail here.
-                return Q.reject(error);
-            });
-        }
-        return Q.reject(error);
-    });
+        }).catch(function (error) {
+            if (error.toString().indexOf('failed to find target with hash string') >=
0) {
+                return check_reqs.check_android_target(error).then(function () {
+                    // If due to some odd reason - check_android_target succeeds
+                    // we should still fail here.
+                    return Q.reject(error);
+                });
+            }
+            return Q.reject(error);
+        });
 };
 
 StudioBuilder.prototype.clean = function (opts) {
@@ -283,16 +283,16 @@ StudioBuilder.prototype.clean = function (opts) {
     return Q().then(function () {
         return spawn(wrapper, args, {stdio: 'inherit'});
     })
-    .then(function () {
-        shell.rm('-rf', path.join(builder.root, 'out'));
+        .then(function () {
+            shell.rm('-rf', path.join(builder.root, 'out'));
 
-        ['debug', 'release'].forEach(function (config) {
-            var propertiesFilePath = path.join(builder.root, config + SIGNING_PROPERTIES);
-            if (isAutoGenerated(propertiesFilePath)) {
-                shell.rm('-f', propertiesFilePath);
-            }
+            ['debug', 'release'].forEach(function (config) {
+                var propertiesFilePath = path.join(builder.root, config + SIGNING_PROPERTIES);
+                if (isAutoGenerated(propertiesFilePath)) {
+                    shell.rm('-f', propertiesFilePath);
+                }
+            });
         });
-    });
 };
 
 module.exports = StudioBuilder;
diff --git a/bin/templates/cordova/lib/pluginHandlers.js b/bin/templates/cordova/lib/pluginHandlers.js
index 842489ae0..b5a46cfed 100644
--- a/bin/templates/cordova/lib/pluginHandlers.js
+++ b/bin/templates/cordova/lib/pluginHandlers.js
@@ -34,15 +34,7 @@ var handlers = {
             // a later plugins release.  This is for legacy plugins to work with Cordova.
 
             if (options && options.android_studio === true) {
-                // If a Java file is using the new directory structure, don't penalize it
-                if (!obj.targetDir.includes('app/src/main')) {
-                    if (obj.src.endsWith('.java')) {
-                        dest = path.join('app/src/main/java', obj.targetDir.substring(4),
path.basename(obj.src));
-                    } else if (obj.src.endsWith('.xml')) {
-                        // We are making a huge assumption here that XML files will be going
to res/xml or values/xml
-                        dest = path.join('app/src/main', obj.targetDir, path.basename(obj.src));
-                    }
-                }
+                dest = studioPathRemap(obj);
             }
 
             if (options && options.force) {
@@ -55,10 +47,16 @@ var handlers = {
             var dest = path.join(obj.targetDir, path.basename(obj.src));
 
             if (options && options.android_studio === true) {
-                dest = path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
+                dest = studioPathRemap(obj);
             }
 
-            deleteJava(project.projectDir, dest);
+            // TODO: Add Koltin extension to uninstall, since they are handled like Java
files
+            if (obj.src.endsWith('java')) {
+                deleteJava(project.projectDir, dest);
+            } else {
+                // Just remove the file, not the whole parent directory
+                removeFile(project.projectDir, dest);
+            }
         }
     },
     'lib-file': {
@@ -318,3 +316,16 @@ function removeFileAndParents (baseDir, destFile, stopper) {
 function generateAttributeError (attribute, element, id) {
     return 'Required attribute "' + attribute + '" not specified in <' + element + '>
element from plugin: ' + id;
 }
+
+function studioPathRemap (obj) {
+    // If a Java file is using the new directory structure, don't penalize it
+    if (!obj.targetDir.includes('app/src/main')) {
+        if (obj.src.endsWith('.java')) {
+            return path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
+        } else if (obj.src.endsWith('.xml')) {
+            // We are making a huge assumption here that XML files will be going to res/xml
or values/xml
+            return path.join('app/src/main', obj.targetDir, path.basename(obj.src));
+        }
+    }
+
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Cordova-Android@7.0.0 fails to add a plugin previously removed
> --------------------------------------------------------------
>
>                 Key: CB-13830
>                 URL: https://issues.apache.org/jira/browse/CB-13830
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-android
>    Affects Versions: cordova-android-7.0.0
>         Environment: macOS 10.12.6
> node 9.4.0
> Cordova CLI 8.0.0
>  
>            Reporter: Enrico Giordani
>            Assignee: Joe Bowser
>            Priority: Major
>
> Removing a plugin and than adding it again, causes an error:
> {code}
> $ cordova create testapp
> $ cd testapp
> $ cordova platform add android
> Using cordova-fetch for cordova-android@~7.0.0
> Adding android project...
> Creating Cordova project for the Android platform:
>  Path: platforms/android
>  Package: io.cordova.hellocordova
>  Name: HelloCordova
>  Activity: MainActivity
>  Android target: android-26
> Subproject Path: CordovaLib
> Subproject Path: app
> Android project created with cordova-android@7.0.0
> Android Studio project detected
> Android Studio project detected
> 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@~7.0.0 into config.xml file ...
> {code}
> {code}
> $ cordova plugin add cordova-plugin-camera
> Installing "cordova-plugin-camera" for android
> Android Studio project detected
> Subproject Path: CordovaLib
> Subproject Path: app
> Adding cordova-plugin-camera to package.json
> Saved plugin info for "cordova-plugin-camera" to config.xml
> {code}
> {code}
> $ cordova plugin remove cordova-plugin-camera
> Uninstalling cordova-plugin-camera from android
> Android Studio project detected
> Subproject Path: CordovaLib
> Subproject Path: app
> Removing "cordova-plugin-camera"
> Removing plugin cordova-plugin-camera from config.xml file...
> Removing cordova-plugin-camera from package.json
> {code}
> {code}
> $ cordova plugin add cordova-plugin-camera
> Installing "cordova-plugin-camera" for android
> Android Studio project detected
> Error during processing of action! Attempting to revert...
> Failed to install 'cordova-plugin-camera': CordovaError: Uh oh!
> "/Users/enrico/tmp/testapp/platforms/android/app/src/main/res/xml/provider_paths.xml"
already exists!
>  at copyNewFile (/Users/enrico/tmp/testapp/platforms/android/cordova/lib/pluginHandlers.js:261:45)
>  at install (/Users/enrico/tmp/testapp/platforms/android/cordova/lib/pluginHandlers.js:51:17)
>  at ActionStack.process (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/cordova-common/src/ActionStack.js:56:25)
>  at PluginManager.doOperation (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/cordova-common/src/PluginManager.js:114:20)
>  at PluginManager.addPlugin (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/cordova-common/src/PluginManager.js:144:17)
>  at /Users/enrico/tmp/testapp/platforms/android/cordova/Api.js:247:74
>  at _fulfilled (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/q/q.js:854:54)
>  at self.promiseDispatch.done (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/q/q.js:883:30)
>  at Promise.promise.promiseDispatch (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/q/q.js:816:13)
>  at /Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/q/q.js:570:49
> (node:5722) UnhandledPromiseRejectionWarning: CordovaError: Uh oh!
> "/Users/enrico/tmp/testapp/platforms/android/app/src/main/res/xml/provider_paths.xml"
already exists!
>  at copyNewFile (/Users/enrico/tmp/testapp/platforms/android/cordova/lib/pluginHandlers.js:261:45)
>  at install (/Users/enrico/tmp/testapp/platforms/android/cordova/lib/pluginHandlers.js:51:17)
>  at ActionStack.process (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/cordova-common/src/ActionStack.js:56:25)
>  at PluginManager.doOperation (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/cordova-common/src/PluginManager.js:114:20)
>  at PluginManager.addPlugin (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/cordova-common/src/PluginManager.js:144:17)
>  at /Users/enrico/tmp/testapp/platforms/android/cordova/Api.js:247:74
>  at _fulfilled (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/q/q.js:854:54)
>  at self.promiseDispatch.done (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/q/q.js:883:30)
>  at Promise.promise.promiseDispatch (/Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/q/q.js:816:13)
>  at /Users/enrico/tmp/testapp/platforms/android/cordova/node_modules/q/q.js:570:49
> (node:5722) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error
originated either by throwing inside of an async function without a catch block, or by rejecting
a promise which was not handled with .catch(). (rejection id: 1)
> (node:5722) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated.
In the future, promise rejections that are not handled will terminate the Node.js process
with a non-zero exit code.
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message