Closed JackRo closed 5 years ago
I am also facing same issue ,were you able to fix this issue ?
I am also facing same issue ,were you able to fix this issue ?
I have been able to fix this issue, but I fixed this issue by Cordova Hook mechanism.
I removed the edit-config
from my custom plugin's plugin.xml. Then I used the Cordova Hook mechanism to satisfy my demand that added MyApp.java
to my Cordova Project and configured the AndroidManifest.xml
of Cordova Project's android platform
If you want to fix this issue, you also could see Cordova Hook Guide first.
@JackRo Can you provide your hook example?
@videmort The hook example like this:
the plugin.xml
like below:
<platform name="android">
<hook type="after_plugin_install" src="scripts/afterPluginInstall.js" />
<hook type="before_plugin_uninstall" src="scripts/beforePluginUninstall.js" />
the afterPluginInstall.js like below:
#!/usr/bin/env node
module.exports = function(context) {
let fs = context.requireCordovaModule('fs'),
path = context.requireCordovaModule('path');
// android platform directory
let platformAndroidDir = path.join(context.opts.projectRoot, 'platforms/android');
// android app module directory
let platformAndroidAppModuleDir = path.join(platformAndroidDir, 'app');
// android manifest file
let androidManifestFile = path.join(platformAndroidAppModuleDir, 'src/main/AndroidManifest.xml');
if (fs.existsSync(androidManifestFile)) {
fs.readFile(androidManifestFile, 'UTF-8', function(err, data) {
if (err) {
throw new Error('Unable to find AndroidManifest.xml: ' + err);
}
// the Android Application class that need to config to Android manifest file
let applicationClassName = 'com.jackro.example.MyApp';
if (data.indexOf(applicationClassName) === -1) {
let result = data.replace(/<application/g, '<application android:name="' + applicationClassName + '"');
fs.writeFile(androidManifestFile, result, 'UTF-8', function(err) {
if (err)
throw new Error('Unable to write into AndroidManifest.xml: ' + err);
})
}
});
}
};
the beforePluginUninstall.js
like below:
#!/usr/bin/env node
module.exports = function(context) {
let fs = context.requireCordovaModule('fs'),
path = context.requireCordovaModule('path');
// android platform directory
let platformAndroidDir = path.join(context.opts.projectRoot, 'platforms/android');
// android app module directory
let platformAndroidAppModuleDir = path.join(platformAndroidDir, 'app');
// android manifest file
let androidManifestFile = path.join(platformAndroidAppModuleDir, 'src/main/AndroidManifest.xml');
// android app module gradle
let androidAppModuleGradleFile = path.join(platformAndroidAppModuleDir, 'build.gradle');
if (fs.existsSync(androidManifestFile)) {
fs.readFile(androidManifestFile, 'UTF-8', function(err, data) {
if (err) {
throw new Error('Unable to find AndroidManifest.xml: ' + err);
}
//Android Application of Android manifest that need to delete config
let applicationClassConfig = 'android:name="com.jackro.example.MyApp"';
if (data.indexOf(applicationClassConfig) !== -1) {
let result = data.replace(applicationClassConfig, '');
fs.writeFile(androidManifestFile, result, 'UTF-8', function(err) {
if (err)
throw new Error('Unable to write into AndroidManifest.xml: ' + err);
})
}
});
}
if (fs.existsSync(androidAppModuleGradleFile)) {
fs.readFile(androidAppModuleGradleFile, 'UTF-8', function(err, data) {
if (err) {
throw new Error('Unable to find build.gradle: ' + err);
}
let androidAppModuleGradleConfigLine = 'apply from: "../com-jackro-example/app-jackroexample.gradle"';
if (data.indexOf(androidAppModuleGradleConfigLine) !== -1) {
let result = data.replace(androidAppModuleGradleConfigLine, '');
fs.writeFile(androidAppModuleGradleFile, result, 'UTF-8', function(err) {
if (err)
throw new Error('Unable to write into build.gradle: ' + err);
})
}
});
}
};
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This thread has been automatically locked.
There was no conflict with install my custom plugin after install barcodescanner plugin
After install barcodescanner plugin, then install my custom plugin, There was a conflict trying to modify attributes with in my plugin
my custom plugin's plugin.xml is like below:
`
first install the barcodescanner plugin, then install my custom plugin
Android 8.1
No devices, just install plugin conflict
Cordova CLI version and cordova platform version
Plugin version
Sample Code that illustrates the problem
Logs taken while reproducing problem