Skip to content

Commit 7852265

Browse files
committed
✨ Add editing the application manifest with the instabug application class automatically post installing the plugin
1 parent 1b7bc5b commit 7852265

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

scripts/android/before_plugin_install.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var fs = require('fs');
22
var path = require('path');
3+
const editManist = require('./edit_manifest');
34

45
const ibgBuildGradleExists = () => {
56
var target = path.join('plugins', 'instabug-cordova', 'build.gradle');
@@ -53,5 +54,6 @@ module.exports = function(ctx) {
5354
);
5455
writeIbgBuildGradle(buildGradle);
5556
}
57+
return editManist(ctx);
5658
}
5759
};

scripts/android/edit_manifest.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = function(ctx) {
2+
console.log('INNN');
3+
const fs = ctx.requireCordovaModule('fs');
4+
const path = ctx.requireCordovaModule('path');
5+
const Q = ctx.requireCordovaModule('q');
6+
const xml = ctx.requireCordovaModule('cordova-common').xmlHelpers;
7+
8+
const deferred = Q.defer();
9+
const platformPath = path.join(ctx.opts.projectRoot, './platforms/android');
10+
const manifestPaths = [
11+
path.join(platformPath, './AndroidManifest.xml'),
12+
path.join(platformPath, './app/src/main/AndroidManifest.xml'),
13+
];
14+
15+
const manifestPath = manifestPaths.find((filepath) => {
16+
try {
17+
fs.accessSync(filepath, fs.constants.F_OK)
18+
return true
19+
} catch (err) {
20+
return false
21+
}
22+
});
23+
24+
var doc;
25+
26+
if (manifestPath != null) {
27+
doc = xml.parseElementtreeSync(manifestPath)
28+
doc.getroot().find('./application').attrib['android:name'] =
29+
'com.instabug.cordova.plugin.MyApplication'
30+
fs.writeFileSync(manifestPath, doc.write({ indent: 4 }))
31+
deferred.resolve()
32+
} else {
33+
deferred.reject(new Error("Can't find AndroidManifest.xml"))
34+
}
35+
36+
return deferred.promise
37+
}

0 commit comments

Comments
 (0)