cordova-plugin-androidx-adapter
Advanced tools
Comparing version 1.0.2 to 1.1.0
31
apply.js
@@ -6,2 +6,4 @@ var PLUGIN_NAME = "cordova-plugin-androidx-adapter"; | ||
var BUILD_GRADLE_PATH = "./platforms/android/app/build.gradle"; | ||
var PROJECT_PROPERTIES_PATH = "./platforms/android/project.properties"; | ||
var MANIFEST_PATH = "./platforms/android/app/src/main/AndroidManifest.xml"; | ||
@@ -31,13 +33,26 @@ var deferral, fs, path, now, recursiveDir; | ||
var buildGradle = fs.readFileSync(BUILD_GRADLE_PATH).toString(), | ||
artifactMappings = JSON.parse(fs.readFileSync(path.join(__dirname, '.', ARTIFACT_MAPPINGS_FILE)).toString()); | ||
var artifactMappings = JSON.parse(fs.readFileSync(path.join(__dirname, '.', ARTIFACT_MAPPINGS_FILE)).toString()), | ||
buildGradle = fs.readFileSync(BUILD_GRADLE_PATH).toString(), | ||
projectProperties = fs.readFileSync(PROJECT_PROPERTIES_PATH).toString(), | ||
androidManifest = fs.readFileSync(MANIFEST_PATH).toString(); | ||
for(var oldName in artifactMappings){ | ||
var oldRegExpStr = sanitiseForRegExp(oldName) + '[^"]+'; | ||
var newName = artifactMappings[oldName]; | ||
buildGradle = buildGradle.replace(new RegExp(oldRegExpStr, 'gm'), newName); | ||
// Replace artifacts in build.gradle, project.properties & AndroidManifest.xml | ||
for(var oldArtifactName in artifactMappings){ | ||
var newArtifactName = artifactMappings[oldArtifactName], | ||
artifactRegExpStr = sanitiseForRegExp(oldArtifactName) + ':[0-9.+]+'; | ||
buildGradle = buildGradle.replace(new RegExp(artifactRegExpStr, 'gm'), newArtifactName); | ||
projectProperties = projectProperties.replace(new RegExp(artifactRegExpStr, 'gm'), newArtifactName); | ||
} | ||
fs.writeFileSync(BUILD_GRADLE_PATH, buildGradle, 'utf8'); | ||
fs.writeFileSync(PROJECT_PROPERTIES_PATH, projectProperties, 'utf8'); | ||
var classMappings = JSON.parse(fs.readFileSync(path.join(__dirname, '.', CLASS_MAPPINGS_FILE)).toString()); | ||
// Replace class/package names in AndroidManifest.xml | ||
for (var oldClassName in classMappings){ | ||
androidManifest = androidManifest.replace(new RegExp(oldClassName, 'g'), classMappings[oldClassName]); | ||
} | ||
fs.writeFileSync(MANIFEST_PATH, androidManifest, 'utf8'); | ||
// Replace class/package names in source code | ||
recursiveDir(JAVA_SRC_PATH, [function(file, stats){ | ||
@@ -50,4 +65,4 @@ return !file.match(".java"); | ||
var fileContents = fs.readFileSync(filePath).toString(); | ||
for (var oldName in classMappings){ | ||
fileContents = fileContents.replace(new RegExp(oldName, 'g'), classMappings[oldName]); | ||
for (var oldClassName in classMappings){ | ||
fileContents = fileContents.replace(new RegExp(oldClassName, 'g'), classMappings[oldClassName]); | ||
} | ||
@@ -54,0 +69,0 @@ fs.writeFileSync(filePath, fileContents, 'utf8'); |
@@ -0,0 +0,0 @@ { |
{ | ||
"name": "cordova-plugin-androidx-adapter", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Cordova/Phonegap plugin to migrate any code which references the legacy Android Support Library to the new AndroidX mappings in a Cordova Android platform project.", | ||
@@ -5,0 +5,0 @@ "author": "Dave Alden", |
cordova-plugin-androidx-adapter | ||
=============================== | ||
Cordova/Phonegap plugin to migrate any code which references the legacy [Android Support Library](https://developer.android.com/topic/libraries/support-library/index) to the new [AndroidX](https://developer.android.com/jetpack/androidx/migrate) mappings in a Cordova Android platform project. | ||
If your Cordova project contains plugins/libraries which reference both the Android Support Library and AndroidX, your Android build will fail because the two cannot live side-by-side in an Android build. | ||
This enables a Cordova project for which AndroidX has been enabled (e.g. using [cordova-plugin-androidx](https://github.com/dpa99c/cordova-plugin-androidx) to successfully build even if it contains plugins which reference the legacy Support Library. | ||
This plugin provides a shim to migrate references to the legacy [Android Support Library](https://developer.android.com/topic/libraries/support-library/index) to the new [AndroidX](https://developer.android.com/jetpack/androidx/migrate) mappings in a Cordova Android platform project. | ||
The plugin uses a hook script to replace any legacy Support Library Gradle artifact references in the `build.gradle` with the new [artifact mappings](https://developer.android.com/jetpack/androidx/migrate#artifact_mappings) and any legacy Support Library package name references in the Java source code with the new [class mappings](https://developer.android.com/jetpack/androidx/migrate#class_mappings). | ||
This enables a Cordova project for which AndroidX has been enabled (e.g. using [cordova-plugin-androidx](https://github.com/dpa99c/cordova-plugin-androidx)) to successfully build even if it contains plugins which reference the legacy Support Library. | ||
The plugin uses a hook script to replace any legacy Support Library references: | ||
- Gradle artifacts in `app/build.gradle` and `project.properties` with new [artifact mappings](https://developer.android.com/jetpack/androidx/migrate#artifact_mappings) | ||
- Class/package names in `AndroidManifest.xml` or the Java source code (of Cordova plugins) with new [class mappings](https://developer.android.com/jetpack/androidx/migrate#class_mappings). | ||
<!-- DONATE --> | ||
[![donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG_global.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZRD3W47HQ3EMJ) | ||
I dedicate a considerable amount of my free time to developing and maintaining this Cordova plugin, along with my other Open Source software. | ||
To help ensure this plugin is kept updated, new features are added and bugfixes are implemented quickly, please donate a couple of dollars (or a little more if you can stretch) as this will help me to afford to dedicate time to its maintenance. Please consider donating if you're using this plugin in an app that makes you money, if you're being paid to make the app, if you're asking for new features or priority bug fixes. | ||
<!-- END DONATE --> | ||
# Requirements | ||
This plugin requires a minimum of [`cordova@9`](https://github.com/apache/cordova-cli) and [`cordova-android@8`](https://github.com/apache/cordova-android). | ||
This plugin requires a minimum of [`cordova@8`](https://github.com/apache/cordova-cli) and [`cordova-android@8`](https://github.com/apache/cordova-android). | ||
@@ -20,3 +32,3 @@ # Installation | ||
**WARNING**: Do not install this plugin in a Cordova project in which AndroidX has not already been installed or the build will fail. | ||
**WARNING**: Do not install this plugin in a Cordova project in which AndroidX has not already been enabled or the build will fail. | ||
@@ -23,0 +35,0 @@ # Usage |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
218265
2124
68