-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A silly code to workaround issue apache/cordova-android#1178
- Loading branch information
1 parent
ddb8012
commit 626ff04
Showing
2 changed files
with
61 additions
and
0 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
module.exports = (context) => { | ||
// Make sure android platform is part of build | ||
if (!context.opts.platforms.includes('android')) { | ||
return; | ||
} | ||
|
||
const platformRoot = path.join(context.opts.projectRoot, 'platforms/android'); | ||
const buildGradleFile = path.join(platformRoot, 'build.gradle'); | ||
const projectPropertiesFile = path.join(platformRoot, 'project.properties'); | ||
const cordovaProjectPropertiesFile = path.join(platformRoot, 'CordovaLib/project.properties'); | ||
|
||
fs.readFile(buildGradleFile, 'utf8', function (error, data) { | ||
if (error) { | ||
return console.error(error); | ||
} | ||
const result = data | ||
.replace(/defaultBuildToolsVersion="29.0.2"/g, 'defaultBuildToolsVersion="30.0.3"') | ||
.replace(/defaultTargetSdkVersion=29/g, 'defaultTargetSdkVersion=30') | ||
.replace(/defaultCompileSdkVersion=29/g, 'defaultCompileSdkVersion=30'); | ||
|
||
fs.writeFile(buildGradleFile, result, 'utf8', (error) => { | ||
if (error) { | ||
return console.error(error); | ||
} | ||
}); | ||
}); | ||
|
||
fs.readFile(projectPropertiesFile, 'utf8', (error, data) => { | ||
if (error) { | ||
return console.error(error); | ||
} | ||
const result = data | ||
.replace(/target=android-29/g, 'target=android-30'); | ||
|
||
fs.writeFile(projectPropertiesFile, result, 'utf8', (error) => { | ||
if (error) { | ||
return console.error(error); | ||
} | ||
}); | ||
}); | ||
|
||
fs.readFile(cordovaProjectPropertiesFile, 'utf8', (error, data) => { | ||
if (error) { | ||
return console.error(error); | ||
} | ||
const result = data | ||
.replace(/target=android-29/g, 'target=android-30'); | ||
|
||
fs.writeFile(cordovaProjectPropertiesFile, result, 'utf8', (error) => { | ||
if (error) { | ||
return console.error(error); | ||
} | ||
}); | ||
}); | ||
|
||
return Promise.resolve().then(() => console.log('Modifying build.gradle and project.properties is done to target SDK 30')) | ||
}; |