expo-cli icon indicating copy to clipboard operation
expo-cli copied to clipboard

failed on expo build android because of icon

Open gvnc opened this issue 8 years ago • 17 comments

I just run expo build:android to get an apk.

If I add icon property to app.json, build fails and get below errors.

If I remove the icon property, it builds the apk and I download it as expected.

I definitely make sure the locale image path is correct and the file exists.

Warning: Could not copy android.iml to shell app directory. Unhandled promise rejection: Error: Failed to resize image: ic_launcher.png. Error: Input file is missing or of an unsupported image format at /app/node_modules/xdl/build/detach/AndroidIcons.js:62:19 at Generator.throw () at step (/app/node_modules/xdl/build/detach/AndroidIcons.js:232:191) at /app/node_modules/xdl/build/detach/AndroidIcons.js:232:402 at

app.json is : { "expo": { "name":"AppXZ", "slug":"app-xz", "privacy":"public", "sdkVersion": "31.0.0", "version":"1.0.0", "orientation":"portrait", "facebookScheme": "fb248300512502782", "icon":"./src/assets/icon.png", "splash": { "backgroundColor": "#FFC300", "resizeMode": "contain", "image": "./src/assets/icon.png" }, "ios": { "bundleIdentifier": "app.x.z", "buildNumber":"1.0.0" }, "android": { "package": "app.x.z", "versionCode":1 } } }

Build url https://expo.io/builds/526d5921-a9dc-4bd0-bcd9-46a489f4181e

Environment Expo CLI 2.6.0 environment info: System: OS: macOS High Sierra 10.13.6 Shell: 3.2.57 - /bin/bash

Binaries:
  Node: 10.13.0 - /usr/local/bin/node
  npm: 6.4.1 - /usr/local/bin/npm
  Watchman: 4.9.0 - /usr/local/bin/watchman

IDEs:
  Android Studio: 3.2 AI-181.5540.7.32.5056338
  Xcode: 10.1/10B61 - /usr/bin/xcodebuild

npmPackages:
  expo: 31.0.0 => 31.0.0 
  react: 16.5.0 => 16.5.0 
  react-native: 0.57.1 => 0.57.1 
  react-navigation: 2.11.2 => 2.11.2 
npmGlobalPackages:
  expo-cli: 2.6.0

gvnc avatar Dec 03 '18 11:12 gvnc

This error means the icon might not be a valid PNG file. Can you run this command in the project folder and copy paste the output here?

file ./src/assets/icon.png

fson avatar Dec 03 '18 16:12 fson

users-MacBook-Pro-2:assets guvenc$ file icon.png 
icon.png: PNG image data, 1024 x 1024, 8-bit/color RGBA, non-interlaced

gvnc avatar Dec 03 '18 16:12 gvnc

This is funny, I got the exact same error when I added default expo icon png to my assets folder and set it as my icon in app.json.

So now I believe the problem is not related to the image I provided.

The problem is not related to file path neither, because expo does not even start building if I set a file path not really exists.

[21:29:21] Error: Problems validating asset fields in app.json. See https://docs.expo.io/ [21:29:21] • Field: android.icon - cannot access file at './src/assets/nofilex.png'. [21:29:21] Couldn't publish because errors were found. (See logs above.) Please fix the errors and try again.

gvnc avatar Dec 03 '18 18:12 gvnc

cc @dsokal

fson avatar Dec 03 '18 23:12 fson

Hello @gvnc, it looks like you removed assetBundlePatterns key from your app.json and this causes that your app assets are not being uploaded to Expo servers when you publish your app. Please set that key back and rebuild your app, should fix the problem. https://docs.expo.io/versions/latest/workflow/configuration#assetbundlepatterns

dsokal avatar Dec 04 '18 09:12 dsokal

hello @dsokal

assetBundlePatterns didnt help me, but it made me realize another error.

[19:08:53] Analyzing assets [19:08:54] Finished building JavaScript bundle in 1726ms. [19:08:54] ::ffff:127.0.0.1 - - [04/Dec/2018:16:08:54 +0000] "GET /./node_modules/expo/AppEntry.assets?dev=false&minify=true&hot=false&assetPlugin=%2FUsers%2Fguvenc%2FCardCollection%2Ffrontend%2Fnode_modules%2Fexpo%2Ftools%2FhashAssetFiles&platform=ios HTTP/1.1" 200 - "-" "-" [19:08:56] Finished building JavaScript bundle in 1780ms. [19:08:56] ::ffff:127.0.0.1 - - [04/Dec/2018:16:08:56 +0000] "GET /./node_modules/expo/AppEntry.assets?dev=false&minify=true&hot=false&assetPlugin=%2FUsers%2Fguvenc%2FCardCollection%2Ffrontend%2Fnode_modules%2Fexpo%2Ftools%2FhashAssetFiles&platform=android HTTP/1.1" 200 - "-" "-" [19:08:56] Uploading assets [19:08:56] No assets to upload, skipped. [19:08:56] Processing asset bundle patterns: [19:08:56] - /Users/guvenc/CardCollection/frontend/src/assets/images/* [19:08:56] - /Users/guvenc/CardCollection/frontend/src/assets/locales/* [19:08:56] Cannot read property 'forEach' of undefined [19:08:56] TypeError: Cannot read property 'forEach' of undefined at /[email protected]/src/Project.js:1018:26 at Generator.next () at step (/usr/local/lib/node_modules/expo-cli/node_modules/xdl/build/Project.js:2202:191) at /usr/local/lib/node_modules/expo-cli/node_modules/xdl/build/Project.js:2202:361

Then I troubleshoot more and realized my assets are never being uploaded, see the logs above which says "No assets to upload, skipped". forEach is undefined because assets do not have fileHashes property in part of code where it started to run after I added assetBundlePattern.

https://github.com/expo/expo-cli/blob/master/packages/xdl/src/Project.js

if (assets.length > 0 && assets[0].fileHashes) { await uploadAssetsAsync(projectRoot, assets); } else { logger.global.info({ quiet: true }, 'No assets to upload, skipped.'); }`

Then I found out the json returning from below url does not include any fileHashes, but hash.

I am not sure but it seemed to me wrong. I couldn't resolve the reason and the issue.

http://127.0.0.1:19001/node_modules/expo/AppEntry.assets?dev=false&minify=true&hot=false&assetPlugin=%2FUsers%2Fguvenc%2FCardCollection%2Ffrontend%2Fnode_modules%2Fexpo%2Ftools%2FhashAssetFiles&platform=android

{"__packager_asset":true,"fileSystemLocation":"/Users/guvenc/CardCollection/frontend/node_modules/expo/node_modules/@expo/vector-icons/fonts","httpServerLocation":"/assets/node_modules/expo/node_modules/@expo/vector-icons/fonts","scales":[1],"files":["/Users/guvenc/CardCollection/frontend/node_modules/expo/node_modules/@expo/vector-icons/fonts/AntDesign.ttf"],"hash":"3a2ba31570920eeb9b1d217cabe58315","name":"AntDesign","type":"ttf"},{"__packager_asset":true,"fileSystemLocation":"/Users/guvenc/CardCollection/frontend/node_modules/expo/node_modules/@expo/vector-icons/fonts","httpServerLocation":"/assets/node_modules/expo/node_modules/@expo/vector-icons/fonts","scales":[1],"files":["/Users/guvenc/CardCollection/frontend/node_modules/expo/node_modules/@expo/vector-icons/fonts/Entypo.ttf"],"hash":"744ce60078c17d86006dd0edabcd59a7","name":"Entypo","type":"ttf"}

I checked the assetPlugin function which is given in url. It seems ok, but I suspect this function is never being called.

`users-MacBook-Pro-2:frontend guvenc$ cat node_modules/expo/tools/hashAssetFiles.js 'use strict';

const md5File = require('md5-file/promise');

module.exports = function hashAssetFiles(asset) { return Promise.all(asset.files.map(md5File)).then(hashes => { asset.fileHashes = hashes; return asset; }); }; `

So I am stuck. I also tried all cleaning options for npm, reset-cache, etc.

gvnc avatar Dec 04 '18 16:12 gvnc

@gvnc [19:08:56] Cannot read property 'forEach' of undefined you're getting this because you most probably tried to upgrade react-native npm package. Currently, Expo doesn't support react-native from npm. You must use react-native package distributed by Expo. So if you're using SDK31, you should change it back (in package.json) to https://github.com/expo/react-native/archive/sdk-31.0.1.tar.gz.

dsokal avatar Dec 05 '18 08:12 dsokal

@dsokal thanks a lot.

That was my problem and I missed it from all the beginning.

gvnc avatar Dec 05 '18 11:12 gvnc

@dsokal

I am having a similar problem but I did not upgrade react-native. However are you saying that you cannot use any npm packages at all with react-native expo? I did install axios and maybee one other react native module. Is this my problem? I am confused about what I am limited to...

cparello avatar Jan 07 '19 04:01 cparello

@cparello you can use any package you need, the only limitation is that you cannot change react-native package version.

Do you have this in expo object in app.json?

    "assetBundlePatterns": [
      "**/*"
    ],

If not, this is probably your problem.

https://docs.expo.io/versions/latest/workflow/configuration#assetbundlepatterns

dsokal avatar Jan 07 '19 08:01 dsokal

@dsokal

I had "assetBundlePatterns": [ "**/*" ],

In my app.json but the build failed saying foreach of undefined in bundling the assets so I switched to"assetBundlePatterns": [ "assets/*" ], Now I get the png error on top of this ticket and this

/app/workingdir/android/sdk31/android-shell-app/app/src/main/res/mipmap-mdpi/ic_launcher.png: error: failed to read PNG signature: file does not start with PNG signature. /app/workingdir/android/sdk31/android-shell-app/app/src/main/res/mipmap-xhdpi/ic_launcher.png: error: failed to read PNG signature: file does not start with PNG signature. /app/workingdir/android/sdk31/android-shell-app/app/src/main/res/mipmap-hdpi/ic_launcher.png: error: failed to read PNG signature: file does not start with PNG signature. /app/workingdir/android/sdk31/android-shell-app/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: error: failed to read PNG signature: file does not start with PNG signature. /app/workingdir/android/sdk31/android-shell-app/app/src/main/res/drawable-xxxhdpi/shell_launch_background_image.png: error: failed to read PNG signature: file does not start with PNG signature. /app/workingdir/android/sdk31/android-shell-app/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: error: failed to read PNG signature: file does not start with PNG signature. Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details :app:mergeProdMinSdkProdKernelReleaseResources FAILED [stderr] warning: Attempt to recreate a file for type com.raizlabs.android.dbflow.config.ExponentKernel$Database [stderr] warning: Attempt to recreate a file for type com.raizlabs.android.dbflow.config.ExponentKernel$Database [stderr] warning: File for type 'com.raizlabs.android.dbflow.config.GeneratedDatabaseHolder' created in the last round will not be subject to annotation processing. [stderr] Note: Some input files use or override a deprecated API. [stderr] Note: Recompile with -Xlint:deprecation for details. [stderr] Note: Some input files use unchecked or unsafe operations. [stderr] Note: Recompile with -Xlint:unchecked for details. [stderr] 3 warnings [stderr] FAILURE: Build failed with an exception. [stderr] * What went wrong: [stderr] Execution failed for task ':app:mergeProdMinSdkProdKernelReleaseResources'. [stderr] > Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details [stderr] * Try: [stderr] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. [stderr] * Get more help at https://help.gradle.org [stderr] BUILD FAILED in 5m 0s 690 actionable tasks: 690 executed Error: Process exited with non-zero code: 1 at ChildProcess.child.on (/app/node_modules/@expo/spawn-async/build/spawnAsync.js:39:21) at emitTwo (events.js:126:13) at ChildProcess.emit (events.js:214:7) at maybeClose (internal/child_process.js:915:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

i switched asset bundle patern back to ***

Now I get whats attached below. Thanks for your help.

capture

forget it I see the problem now npm changed react-native in package.json

from: ... "react-native": "^0.57.1", ... to: ... "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz", ...

After switiching back now seems to be building. My first build so I was really confused. Thanks!

cparello avatar Jan 08 '19 03:01 cparello

Experiencing similar issues on SDK 33. I've had to downgrade my project to SDK 32 in order to see images correctly on publishes.

"expo": "^32.0.0",
"expo-cli": "^2.21.1",
"react": "16.8.3",
"react-dom": "^16.8.6",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",

Aryojaam avatar Jun 28 '19 23:06 Aryojaam

@cparello was facing the same problem and your way worked. Thank You

Leleking avatar Jul 06 '19 22:07 Leleking

Is anyone still facing this issue? When I try to run exp build:android I get the following errors when I changed the icon to another png file, but the apk is built as expected if I use the default icon.

> Task :app:mergeReleaseResources FAILED
[stderr] FAILURE: Build failed with an exception.
[stderr] * What went wrong:
[stderr] Execution failed for task ':app:mergeReleaseResources'.
[stderr] > java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
[stderr]   /app/turtle/workingdir/android/sdk33/android-shell-app/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: error: failed to read PNG signature: file does not start with PNG signature.
[stderr] * Try:
[stderr] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[stderr] * Get more help at https://help.gradle.org
[stderr] BUILD FAILED in 44s
17 actionable tasks: 17 executed
Error: ./gradlew exited with non-zero code: 1
    at ChildProcess.completionListener (/app/turtle/node_modules/@expo/xdl/node_modules/@expo/spawn-async/build/spawnAsync.js:52:23)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:915:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
    ...
    at spawnAsync (/app/turtle/node_modules/@expo/xdl/node_modules/@expo/spawn-async/build/spawnAsync.js:17:21)
    at spawnAsyncThrowError (/app/turtle/node_modules/@expo/xdl/build/detach/ExponentTools.js:176:45)
    at buildShellAppAsync (/app/turtle/node_modules/@expo/xdl/build/detach/AndroidShellApp.js:687:11)
    at <anonymous>

This is my app.json:- { "expo": { "name": "foo", "slug": "bar", "privacy": "public", "sdkVersion": "33.0.0", "platforms": [ "ios", "android", "web" ], "version": "1.0.0", "orientation": "portrait", "icon": "./logo.png", "splash": { "image": "./assets/splash.png", "resizeMode": "contain", "backgroundColor": "#ffffff" }, "updates": { "fallbackToCacheTimeout": 0 }, "assetBundlePatterns": ["assets/*"], "ios": { "supportsTablet": true, "bundleIdentifier": "in.foo.bar" }, "android": { "package": "in.foo.bar" } } }

Versions:- "expo": "^33.0.0" "react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz"

I've tried various things like not changing the assetBundlerPatterns and shifting the image to the assets directory, nothing seems to work. I have verified that the image is indeed a png file. Again, the build is successful when I use the default icon.

GunaShekar02 avatar Jul 14 '19 13:07 GunaShekar02

@GunaShekar02 I am getting the same forEach error.

I have the correct react-native in package.json and assetBundlePatterns in app.json

I am just now updating from v28 to v33.

No solution yet

mattfca avatar Jul 16 '19 04:07 mattfca

@mattfca I resolved this using expo-cli build:android -t apk instead of exp build:android. This resolved all the issues, all the images were properly rendered too. Make sure you have expo-cli installed.

GunaShekar02 avatar Jul 16 '19 06:07 GunaShekar02

the forEach error is because many assets does not have fileHashes (while having a hash BTW).

I've added some logs into xdl to illustrate that, a hash property but no fileHashes one:

[20:58:11] Uploading assets
[20:58:11] No assets to upload, skipped.
[20:58:11] Processing asset bundle patterns:
[20:58:11] - /Users/houzse00/src/inextensodigital/buro.mobile/**/*
{ __packager_asset: true,
  fileSystemLocation:
   '/Users/houzse00/src/inextensodigital/buro.mobile/node_modules/@expo/vector-icons/build/vendor/react-native-vector-icons/Fonts',
  httpServerLocation:
   '/assets/node_modules/@expo/vector-icons/build/vendor/react-native-vector-icons/Fonts',
  scales: [ 1 ],
  files:
   [ '/Users/houzse00/src/inextensodigital/buro.mobile/node_modules/@expo/vector-icons/build/vendor/react-native-vector-icons/Fonts/AntDesign.ttf' ],
  hash: '3a2ba31570920eeb9b1d217cabe58315',
  name: 'AntDesign',
  type: 'ttf' }
one asset to bundle
[20:58:11] Cannot read property 'forEach' of undefined
[20:58:12] TypeError: Cannot read property 'forEach' of undefined
    at /[email protected]/src/Project.js:1013:5
    at Generator.next (<anonymous>)
    at step (/[email protected]/src/Project.js:66:1)
    at /[email protected]/src/Project.js:66:1
Something went wrong
error Command failed with exit code 1.

shouze avatar Jul 24 '19 19:07 shouze