|
11 | 11 |
|
12 | 12 | // injects config.xml preferences into AndroidManifest.xml file.
|
13 | 13 | function writePreferences (context, preferences) {
|
14 |
| - var pathToManifest = path.join(context.opts.projectRoot, 'platforms', 'android', 'AndroidManifest.xml') |
15 |
| - var manifest = xmlHelper.readXmlAsJson(pathToManifest) |
| 14 | + // read manifest |
| 15 | + var manifest = getManifest(context) |
| 16 | + |
| 17 | + // update manifest |
| 18 | + manifest.file = updateBranchMetaData(manifest.file, preferences) |
| 19 | + manifest.file = updateBranchReferrerTracking(manifest.file) |
| 20 | + manifest.file = updateLaunchOptionToSingleTask(manifest.file, manifest.mainActivityIndex) |
| 21 | + manifest.file = updateBranchURIScheme(manifest.file, manifest.mainActivityIndex, preferences) |
| 22 | + manifest.file = updateBranchAppLinks(manifest.file, manifest.mainActivityIndex, preferences, manifest.targetSdk) |
| 23 | + |
| 24 | + // save manifest |
| 25 | + xmlHelper.writeJsonAsXml(manifest.path, manifest.file) |
| 26 | + } |
| 27 | + |
| 28 | + // get AndroidManifest.xml information |
| 29 | + function getManifest (context) { |
| 30 | + var pathToManifest |
| 31 | + var manifest |
| 32 | + |
| 33 | + try { |
| 34 | + // cordova platform add [email protected] |
| 35 | + pathToManifest = path.join(context.opts.projectRoot, 'platforms', 'android', 'AndroidManifest.xml') |
| 36 | + manifest = xmlHelper.readXmlAsJson(pathToManifest) |
| 37 | + } catch (e) { |
| 38 | + try { |
| 39 | + // cordova platform add [email protected] |
| 40 | + pathToManifest = path.join(context.opts.projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'AndroidManifest.xml') |
| 41 | + manifest = xmlHelper.readXmlAsJson(pathToManifest) |
| 42 | + } catch (e) { |
| 43 | + throw new Error('BRANCH SDK: Cannot read AndroidManfiest.xml ' + e) |
| 44 | + } |
| 45 | + } |
16 | 46 | var mainActivityIndex = getMainLaunchActivityIndex(manifest['manifest']['application'][0]['activity'])
|
17 | 47 | var targetSdk = manifest['manifest']['uses-sdk'][0]['$']['android:targetSdkVersion']
|
18 | 48 |
|
19 |
| - // update manifest |
20 |
| - manifest = updateBranchMetaData(manifest, preferences) |
21 |
| - manifest = updateBranchReferrerTracking(manifest) |
22 |
| - manifest = updateLaunchOptionToSingleTask(manifest, mainActivityIndex) |
23 |
| - manifest = updateBranchURIScheme(manifest, mainActivityIndex, preferences) |
24 |
| - manifest = updateBranchAppLinks(manifest, mainActivityIndex, preferences, targetSdk) |
25 |
| - |
26 |
| - // save new version of the AndroidManifest |
27 |
| - xmlHelper.writeJsonAsXml(pathToManifest, manifest) |
| 49 | + return { |
| 50 | + file: manifest, |
| 51 | + path: pathToManifest, |
| 52 | + mainActivityIndex: mainActivityIndex, |
| 53 | + targetSdk: targetSdk |
| 54 | + } |
28 | 55 | }
|
29 | 56 |
|
30 | 57 | // adds to <application> for Branch init and testmode:
|
|
0 commit comments