About the problem of image duplication in packaging after upgrading the Gradle version in React Native

Yesterday, after I upgraded android studio 3.0, the Gradle version was also upgraded, but after the upgrade, the node_modules_reactnavigation_src_views_assets_backicon.png image was duplicated in the package. I searched for this reason on Github for a long time, only to find that it was because of the offline packaging path after Gradle 2.3. They will all be in drawable-xxx-v4, and the original offline path is in drawable-xxx, so the problem of image duplication is caused. How to solve this problem:

1. Modify assetPathUtils.js

assetPathUtils.js file path: node_modules\react-native\local-cli\bundle\assetPathUtils.js

Modification: getAndroidAssetSuffix method

before fixing:

 function getAndroidAssetSuffix(scale) {
   switch (scale) {
    case 0.75: return 'ldpi';
    case 1: return 'mdpi';
    case 1.5: return 'hdpi';
    case 2: return 'xhdpi';
    case 3: return 'xxhdpi';
    case 4: return 'xxxhdpi';
   }
 }

After modification:

 function getAndroidAssetSuffix(scale) {
   switch (scale) {
     case 0.75: return 'ldpi-v4';
    case 1: return 'mdpi-v4';
    case 1.5: return 'hdpi-v4';
    case 2: return 'xhdpi-v4';
    case 3: return 'xxhdpi-v4';
    case 4: return 'xxxhdpi-v4';
   }
 }

After the modification, delete the previous drawable-xxx folder, and then it can be packaged normally

drawable-xxx file path: YourProject\android\app\src\main\res

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325446348&siteId=291194637