Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

二进制adb文件,electron构建之后在某些系统内无法访问 #11566

Closed
icepy opened this issue Jan 4, 2018 · 7 comments
Closed

二进制adb文件,electron构建之后在某些系统内无法访问 #11566

icepy opened this issue Jan 4, 2018 · 7 comments

Comments

@icepy
Copy link

icepy commented Jan 4, 2018

  • Electron version: 1.7.10
  • Operating system: Mac 10.13.1

Expected behavior

可以启动adb service通过adb devices 获取到设备id

Actual behavior

A JavaScript error occurred in the main process

Uncaught Exception:

Error : spawn ENOTDIR

adb放置在resources/mac/adb,代码写在src/index.js中,整体的目录结构如下:

resources // adb二进制文件
src //源代码
.babelrc
package.json

代码:

import os from 'os';
import path  from 'path';
import childProcess from 'child_process';
const spawn = childProcess.spawn;
const PLATFORM = {
  MAC: 'mac',
  WINDOWS: 'windows',
  UNKNOWN: 'unknown'
}
function fetchPlatform(){
  switch(os.platform()){
    case 'darwin':
        return PLATFORM.MAC;
      break;
    case 'win32':
        return PLATFORM.WINDOWS;
      break;
    default:
        return PLATFORM.UNKNOWN;
      break;
  }
}
const platform = fetchPlatform();
const rootDir = path.resolve(__dirname,'../');
const RESOURCES = path.resolve(rootDir,'resources')
const _adbPath = path.resolve(RESOURCES,platform);
function fetchAdbPath(){
  switch(platform){
    case PLATFORM.MAC:
        return path.resolve(_adbPath,'adb');
      break;
    case PLATFORM.WINDOWS:
        return path.resolve(_adbPath, 'adb.exe');
      break;
    default:
        return false;
      break;
  }
}
export function start_server(callback){
  let adbExecPath = fetchAdbPath();
  if (adbExecPath){
    let adb = spawn(adbExecPath,['start-server']);
    adb.stdout.on('data', function (data) {
      console.log('stdout: ' + data);
    });
    adb.stderr.on('data', function (data) {
      console.log('stderr: ' + data);
    });
    adb.on('exit', function (code) {
      typeof callback === 'function' && callback(code);
    });
    adb.stdin.end();
  } else {
    throw new Error('Not Found Android Debug Bridge');
  }
}

How to reproduce

将上述代码做为一个npm包,假设叫adb-test-a,然后在electron工程里,npm install adb-test-a,调用start_server,必抛错误:Error : spawn ENOTDIR

@welcome
Copy link

welcome bot commented Jan 4, 2018

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

@icepy icepy closed this as completed Jan 5, 2018
@icepy icepy reopened this Jan 10, 2018
@icepy
Copy link
Author

icepy commented Jan 10, 2018

问题依旧没有解决,问了一圈社区里的人,都说是electron的问题,希望能帮忙指导一下,怎么解决。

@KagamiChan
Copy link
Contributor

KagamiChan commented Jan 10, 2018

ENOTDIR means not a directory, this usually means that you're passing a wrong path, check that using fs.stat or anything similar

Edited as it is irrelevant

@icepy
Copy link
Author

icepy commented Jan 10, 2018

@KagamiChan i know, but my example code did not use fs or anything similar, please help me, check my example code .

some os the dir path is app.asar, some other is app.asar.unpacked, i am very confused about this.

@sindresorhus
Copy link
Contributor

Duplicate of #9459

@MarshallOfSound
Copy link
Member

Good catch @sindresorhus 👍 Closing as duplicate

@xucongyong
Copy link

unpacked

@KagamiChan i know, but my example code did not use fs or anything similar, please help me, check my example code .

some os the dir path is app.asar, some other is app.asar.unpacked, i am very confused about this.

not understand

step:

  1. add adb file to app.asar
  2. use electron-util#fixpathforasarunpackpath,get app.asar.unpacked
  3. use exec run adb command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants