Last active
June 6, 2017 08:45
-
-
Save karayok/00f215136371d303a80a87095ce6ad29 to your computer and use it in GitHub Desktop.
Cordova fooks : build.gradle 内の sourceCompatibility と targetCompatibility を `JavaVersion.VERSION_1_7` に変更
This file contains hidden or 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
module.exports = function(ctx) { | |
// make sure android platform is part of build | |
if (ctx.opts.platforms.indexOf('android') < 0) { | |
return; | |
} | |
var fs = ctx.requireCordovaModule('fs'), | |
path = ctx.requireCordovaModule('path'), | |
deferral = ctx.requireCordovaModule('q').defer(); | |
var gradlePath = path.join(ctx.opts.projectRoot, 'platforms/android/build.gradle'); | |
fs.readFile(gradlePath, 'utf8', (err,data) => { | |
if (err) { | |
deferral.reject('Failed to open build.gradle'); | |
return deferral.promise; | |
} | |
// Change Java version | |
var result = data.replace(/VERSION_1_6/g, 'VERSION_1_7'); | |
fs.writeFile(gradlePath, result, 'utf8', (err) => { | |
deferral.reject('Failed to add dexOptions'); | |
return deferral.promise; | |
}); | |
console.log('Replaced result : ' + result); | |
deferral.resolve(); | |
}); | |
return deferral.promise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment