alibaba / macaca

Automation solution for multi-platform. 多端自动化解决方案
https://macacajs.github.io
MIT License
3.17k stars 419 forks source link

gradle@1.0.9设计问题导致uiautomatorwd、unlock-apk(app-debug.apk、app-debug-androidTest.apk)编译失败但不报错 #927

Closed douniwan5788 closed 4 years ago

douniwan5788 commented 5 years ago

sample-nodejs@1.0.0 doctor F:\tmp\sample-nodejs macaca doctor

macaca-doctor version: 2.0.16

Node.js checklist:

node env: C:\Program Files\nodejs\node.exe node version: v10.15.3

Android checklist:

JAVA version is 1.8 JAVA_HOME is set to C:\Program Files\Java\jdk1.8.0_162 ANDROID_HOME is set to D:\Users\***\AppData\Local\Android\android-sdk Platforms is set to D:\Users\***\AppData\Local\Android\android-sdk\platforms\android-28 ADB tool is set to D:\Users\***\AppData\Local\Android\android-sdk\platform-tools\adb.exe GRADLE_HOME is set to D:\Program Files\Android\Android Studio\gradle\gradle-5.1.1

Installed driver list:

android: 2.1.0 location: F:\tmp\sample-nodejs\node_modules\macaca-android

chrome: 1.1.0 location: F:\tmp\sample-nodejs\node_modules\macaca-chrome

electron: 3.0.2 location: F:\tmp\sample-nodejs\node_modules\macaca-electron

ios: 2.0.35 location: F:\tmp\sample-nodejs\node_modules\macaca-ios

puppeteer: 1.0.2 location: F:\tmp\sample-nodejs\node_modules\macaca-puppeteer

* **Operate System**:
 Microsoft Windows 7 专业版
* **Programming Language**:
N/A

<!-- Enter your issue details and log as much information as possible below this comment. -->
gradle@1.0.9的Windows环境下设计不够严谨,只是检测设置了GRADLE_HOME环境变量就认为安装了gradle并直接使用gradle命令(从PATH定位),而不是使用%GRADLE_HOME%\bin\gradle或 项目下的gradlew,并且错误检测也不够严谨,按教程设置了GRADLE_HOME但没有添加%GRADLE_HOME%\bin\到PATH会导致apk编译失败(如uiautomatorwd的app-debug.apk、app-debug-androidTest.apk 和 unlock-apk的app-debug.apk)但完全不报错。

建议macaca doctor增加相应的检测

gradle.js:

const checkEnv = options => { return new Promise((resolve, reject) => {

if (_.platform.isWindows) {

  if (process.env.GRADLE_HOME) {
    options.gradle = 'gradle';                   <---这里直接用了gradle,而不是使用%GRADLE_HOME%\bin\gradle或 项目下的gradlew
    resolve(options);
  } else {
    reject('please install gradle');
  }
} else {
  try {
    const res = child_process.execSync('which gradle');
    options.gradle = res.toString().trim();
    resolve(options);
  } catch (e) {
    reject('please install gradle');
  }
}

}); };

const gradleBuild = options => { return new Promise((resolve, reject) => { var cwd = path.resolve(options.cwd);

try {
  var gradleProcess = spawn.sync(options.gradle, options.args || ['assembleDebug'], {
    cwd: cwd
  });
  const str = gradleProcess.output.toString();

  if (/BUILD\s+FAILED/.test(str.trim())) {   <---gradle命令找不到时并不包含/BUILD\s+FAILED/,导致认为build成功
    reject(str);
  } else {
    resolve(str);
  }
} catch (e) {
  reject(e);
}

}); };

F:\tmp\sample-nodejs>npm i macaca-android -g npm WARN deprecated tough-cookie@2.2.2: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130 npm WARN deprecated hawk@3.1.3: This version has been deprecated. Please upgrade to the latest version to get the best features, bug fixes, and securi ty patches. npm WARN deprecated node-uuid@1.4.8: Use uuid module instead npm WARN deprecated boom@2.10.1: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for old er versions (hapi.im/commercial). npm WARN deprecated sntp@1.0.9: This module moved to @hapi/sntp. Please make sure to switch over as this distribution is no longer supported and may c ontain bugs and critical security issues. npm WARN deprecated cryptiles@2.0.5: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial). npm WARN deprecated hoek@2.16.3: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for old er versions (hapi.im/commercial).

macaca-chromedriver@1.0.45 install C:\Users***\AppData\Roaming\npm\node_modules\macaca-android\node_modules\macaca-chromedriver node ./bin/macaca-chromedriver install

version: 2.33 chromedriver cdn url: https://chromedriver.storage.googleapis.com/2.33/chromedriver_win32.zip chromedriver local in C:\Users***\AppData\Roaming\npm\node_modules\macaca-android\node_modules\macaca-chromedriver\exec\chromedriver2.33.exe

uiautomatorwd@1.1.1 install C:\Users***\AppData\Roaming\npm\node_modules\macaca-android\node_modules\uiautomatorwd node ./scripts/build.js <----完全不报错

unlock-apk@1.1.2 install C:\Users***\AppData\Roaming\npm\node_modules\macaca-android\node_modules\unlock-apk node ./script/build.js <----完全不报错

paradite commented 5 years ago

@douniwan5788 有兴趣欢迎提PR啊,macaca-doctorgradle这两个npm包都是macaca生态里的。 https://github.com/macacajs/gradle/blob/master/lib/gradle.js https://github.com/macacajs/macaca-doctor/blob/master/lib/android.js

macaca-bot commented 5 years ago

This is the translated issue comment: @paradite


@douniwan5788 Interested in welcoming PR, the two npm packages macaca-doctor and gradle are all in the macaca ecosystem. Https://github.com/macacajs/gradle/blob/master/lib/gradle.js Https://github.com/macacajs/macaca-doctor/blob/master/lib/android.js

xudafeng commented 5 years ago

@douniwan5788 欢迎·pull request

macaca-bot commented 5 years ago

This is the translated issue comment: @xudafeng


@douniwan5788 Welcome·pull request

xudafeng commented 4 years ago

https://github.com/macacajs/gradle/commit/e073d2ba00e2bd8342e54296810bb01237670023