Skip to content

Commit a159a33

Browse files
BrunoVillanovafacebook-github-bot
authored andcommitted
Added: informational error message on getting Android drawable folder… (#17751)
Summary: … suffix for asset Better informational error message on getting Android drawable folder suffix error using the asset name scale. <!-- Thank you for sending the PR! We appreciate you spending the time to work on these changes. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html Happy contributing! --> I've got an not well described error when trying to bundle my React Native project package. You can test the React Native bundle command like this: node node_modules/react-native/local-cli/cli.js bundle --platform android --dev false --reset-cache --entry-file index.android.js --bundle-output /project/android/app/build/intermediates/assets/release/index.android.bundle --assets-dest /project/android/app/build (If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/react-native-website, and link to your PR here.) <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [CATEGORY] [TYPE] [LOCATION] - MESSAGE EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> Pull Request resolved: #17751 Differential Revision: D13840597 Pulled By: cpojer fbshipit-source-id: f755ef665b76ce3dd9c96e575fbc71e9aaf43a44
1 parent 46aaa02 commit a159a33

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

Libraries/Image/assetPathUtils.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,25 @@
1212

1313
import type {PackagerAsset} from './AssetRegistry';
1414

15+
const androidScaleSuffix = {
16+
'0.75': 'ldpi',
17+
'1': 'mdpi',
18+
'1.5': 'hdpi',
19+
'2': 'xhdpi',
20+
'3': 'xxhdpi',
21+
'4': 'xxxhdpi',
22+
};
23+
1524
/**
1625
* FIXME: using number to represent discrete scale numbers is fragile in essence because of
1726
* floating point numbers imprecision.
1827
*/
1928
function getAndroidAssetSuffix(scale: number): string {
20-
switch (scale) {
21-
case 0.75:
22-
return 'ldpi';
23-
case 1:
24-
return 'mdpi';
25-
case 1.5:
26-
return 'hdpi';
27-
case 2:
28-
return 'xhdpi';
29-
case 3:
30-
return 'xxhdpi';
31-
case 4:
32-
return 'xxxhdpi';
29+
if (scale.toString() in androidScaleSuffix) {
30+
return androidScaleSuffix[scale.toString()];
3331
}
34-
throw new Error('no such scale');
32+
33+
throw new Error('no such scale ' + scale.toString());
3534
}
3635

3736
// See https://developer.android.com/guide/topics/resources/drawable-resource.html
@@ -52,8 +51,12 @@ function getAndroidResourceFolderName(asset: PackagerAsset, scale: number) {
5251
var suffix = getAndroidAssetSuffix(scale);
5352
if (!suffix) {
5453
throw new Error(
55-
"Don't know which android drawable suffix to use for asset: " +
56-
JSON.stringify(asset),
54+
"Don't know which android drawable suffix to use for scale: " +
55+
scale +
56+
'\nAsset: ' +
57+
JSON.stringify(asset, null, '\t') +
58+
'\nPossible scales are:' +
59+
JSON.stringify(androidScaleSuffix, null, '\t'),
5760
);
5861
}
5962
const androidFolder = 'drawable-' + suffix;

0 commit comments

Comments
 (0)