This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Cordova 9 support #134
Merged
Merged
Cordova 9 support #134
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
module.exports = function(ctx) { | ||
var fs = ctx.requireCordovaModule('fs'), | ||
path = ctx.requireCordovaModule('path'), | ||
var fs = require('fs'), | ||
path = require('path'), | ||
os = require("os"), | ||
readline = require("readline"), | ||
deferral = ctx.requireCordovaModule('q').defer(); | ||
readline = require("readline"); | ||
|
||
var platformRoot = path.join(ctx.opts.projectRoot, 'www'); | ||
var settingsFile = path.join(platformRoot, 'google-services.json'); | ||
|
||
var platformAndroid = 'platforms/android'; | ||
|
||
if (fs.existsSync('platforms/android/app')) { | ||
if (fs.existsSync('platforms/android/app/src/main')) { | ||
// cordova-android >= 7.0.0 | ||
platformAndroid = 'platforms/android/app'; | ||
} | ||
|
||
fs.stat(settingsFile, function(err,stats) { | ||
if (err) { | ||
deferral.reject("To use this plugin on android you'll need to add a google-services.json file with the FCM project_info and place that into your www folder"); | ||
} else { | ||
|
||
fs.createReadStream(settingsFile).pipe(fs.createWriteStream(platformAndroid + '/google-services.json')); | ||
|
||
var lineReader = readline.createInterface({ | ||
terminal: false, | ||
input : fs.createReadStream(platformAndroid + '/build.gradle') | ||
}); | ||
lineReader.on("line", function(line) { | ||
fs.appendFileSync('./build.gradle', line.toString() + os.EOL); | ||
if (/.*\ dependencies \{.*/.test(line)) { | ||
fs.appendFileSync('./build.gradle', '\t\tclasspath "com.google.gms:google-services:3.0.0"' + os.EOL); | ||
fs.appendFileSync('./build.gradle', '\t\tclasspath "com.android.tools.build:gradle:1.2.3+"' + os.EOL); | ||
} | ||
}).on("close", function () { | ||
fs.rename('./build.gradle', platformAndroid + '/build.gradle', deferral.resolve); | ||
}); | ||
|
||
} | ||
}); | ||
|
||
return deferral.promise; | ||
return new Promise(function(resolve, reject) { | ||
fs.stat(settingsFile, function(err,stats) { | ||
if (err) { | ||
reject("To use this plugin on android you'll need to add a google-services.json file with the FCM project_info and place that into your www folder"); | ||
} else { | ||
|
||
fs.createReadStream(settingsFile).pipe(fs.createWriteStream(platformAndroid + '/google-services.json')); | ||
|
||
var lineReader = readline.createInterface({ | ||
terminal: false, | ||
input : fs.createReadStream(platformAndroid + '/build.gradle') | ||
}); | ||
lineReader.on("line", function(line) { | ||
fs.appendFileSync('./build.gradle', line.toString() + os.EOL); | ||
if (/.*\ dependencies \{.*/.test(line)) { | ||
fs.appendFileSync('./build.gradle', '\t\tclasspath "com.google.gms:google-services:3.0.0"' + os.EOL); | ||
fs.appendFileSync('./build.gradle', '\t\tclasspath "com.android.tools.build:gradle:1.2.3+"' + os.EOL); | ||
} | ||
}).on("close", function () { | ||
fs.rename('./build.gradle', platformAndroid + '/build.gradle', resolve); | ||
}); | ||
|
||
} | ||
}); | ||
}) | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about this change. If the
platforms/android/app/src/main
exists we should use'platforms/android/app'
or it should be update also?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had some experiences where some plugins creates an "app" folder. In that case, I would not be able to identify whether cordova-android >= 7.x or not.
The condition is only to try to ensure this. Maybe have another way to do it.