Skip to content

Commit 61b8c26

Browse files
author
Vladimir Enchev
committed
Validate drawable resources before building anything
1 parent 5e5c839 commit 61b8c26

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/services/android-project-service.ts

+17
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,23 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
258258
public buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void> {
259259
return (() => {
260260
if (this.canUseGradle().wait()) {
261+
// Validate App_Resources drawable resources accoring to the official docs: https://developer.android.com/guide/topics/resources/providing-resources.html
262+
let drawableFilePrefix = "drawable-";
263+
let allowedDrawables = ["ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi", "nodpi", "tvdpi"];
264+
let appSourceDirectoryPath = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME);
265+
let sourceAppResourcesDirectoryPath = path.join(appSourceDirectoryPath, constants.APP_RESOURCES_FOLDER_NAME);
266+
267+
if (this.$fs.exists(sourceAppResourcesDirectoryPath).wait()) {
268+
this.$fs.enumerateFilesInDirectorySync(sourceAppResourcesDirectoryPath, (file: string, stat: IFsStats) => {
269+
if (stat.isDirectory() && file.indexOf(drawableFilePrefix) !== -1 &&
270+
allowedDrawables.indexOf(path.basename(file).replace(drawableFilePrefix, "")) === -1) {
271+
this.$errors.failWithoutHelp(`Invalid Android drawable resource folder detected: ${file}. Please check your ${constants.APP_RESOURCES_FOLDER_NAME} folder.`);
272+
return false;
273+
}
274+
return true;
275+
});
276+
}
277+
261278
this.$androidToolsInfo.validateInfo({ showWarningsAsErrors: true, validateTargetSdk: true }).wait();
262279
let androidToolsInfo = this.$androidToolsInfo.getToolsInfo().wait();
263280
let compileSdk = androidToolsInfo.compileSdkVersion;

0 commit comments

Comments
 (0)