Ashung / Android_Res_Export

Export Android resources in Sketch, bitmap assets, nine-patch, vector drawable, app icon, shape XML..
MIT License
209 stars 20 forks source link

"Can't find Android app icon inside current page." when exporting legacy app icon #16

Closed zhutq closed 6 years ago

zhutq commented 6 years ago

Sketch Version 49 Android Res Export 2.3.14

I create page with "New App Icon (Legacy)" and then "Export App Icon", it reports "Can't find Android app icon inside current page."

Running the following script (extracted from export_app_icon.cocoascript),

var doc = context.document;
var page = doc.currentPage();
var iconNormal = page.layerWithID("ic_launcher"),
                iconRound = page.layerWithID("ic_launcher_round");
log(iconNormal)
log(iconRound)

iconNormal and iconRound are both logged as (null).

However if I traverse the layers,

for (var i = 0; i < page.layers().count(); i++) {
    var layer = page.layers()[i];
    if (layer.name() == "ic_launcher") {
        iconNormal = layer;
    } else if (layer.name() == "ic_launcher_round") {
        iconRound = layer;
    }
}
log(iconNormal)
log(iconRound)

iconNormal and iconRound can be found. If I add the above code to export_app_icon.cocoascript, app icon can be exported as expected.

Ashung commented 6 years ago

Thank you.