Skip to content

Commit 7b4409c

Browse files
authored
Merge pull request #407 from BranchMetrics/android-7-support
Android 7 support
2 parents 35c90ee + d5a62a3 commit 7b4409c

File tree

5 files changed

+52
-15
lines changed

5 files changed

+52
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "branch-cordova-sdk",
33
"description": "Branch Metrics Cordova SDK",
44
"main": "src/branch.js",
5-
"version": "2.6.20",
5+
"version": "2.6.21",
66
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
77
"repository": {
88
"type": "git",

plugin.template.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.6.20">
27+
version="2.6.21">
2828

2929
<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->
3030

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.6.20">
27+
version="2.6.21">
2828

2929
<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->
3030

src/scripts/android/updateAndroidManifest.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,47 @@
1111

1212
// injects config.xml preferences into AndroidManifest.xml file.
1313
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+
}
1646
var mainActivityIndex = getMainLaunchActivityIndex(manifest['manifest']['application'][0]['activity'])
1747
var targetSdk = manifest['manifest']['uses-sdk'][0]['$']['android:targetSdkVersion']
1848

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+
}
2855
}
2956

3057
// adds to <application> for Branch init and testmode:

src/scripts/lib/fileHelper.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
// entry
77
module.exports = {
88
readFile: readFile,
9-
writeFile: writeFile
9+
writeFile: writeFile,
10+
accessFile: accessFile
11+
}
12+
13+
// access file
14+
function accessFile (file) {
15+
try {
16+
return fs.accessSync(file)
17+
} catch (err) {
18+
throw new Error('BRANCH SDK: Cannot access file ' + file)
19+
}
1020
}
1121

1222
// read file

0 commit comments

Comments
 (0)