weex 运行 npm run android 要打开android studio 下载所需要的依赖否则会报错


初始化

请确保你已经安装了 Node.js,然后全局安装 weex-toolkit

npm install weex-toolkit -g

这条命令会向你命令行环境中注册一个 weex 命令。你可以用 weex create 命令来创建一个空的模板项目:

weex create awesome-app

命令执行完以后,在当前目录的 awesome-app 文件夹里就有了一个空的 Weex + Vue.js 项目。


编译和运行

默认情况下 weex create 命令并不初始化 iOS 和 Android 项目,你可以通过执行 weex platform add 来添加特定平台的项目。

weex platform add ios
weex platform add android


运行报错


* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':classpath'.
  > Could not resolve com.android.tools.build:gradle:2.2.2.
   Required by:
     :android:unspecified
   > Could not resolve com.android.tools.build:gradle:2.2.2.
     > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.2/gradle-2.2.2.pom'.
      > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.2/gradle-2.2.2.pom'.
        > Connect to jcenter.bintray.com:443 [jcenter.bintray.com/108.168.243.150] failed: Connection timed out: connect
  > Could not resolve com.taobao.android:weexplugin-gradle-plugin:1.3.
   Required by:
     :android:unspecified
   > Could not resolve com.taobao.android:weexplugin-gradle-plugin:1.3.
     > Could not get resource 'https://jcenter.bintray.com/com/taobao/android/weexplugin-gradle-plugin/1.3/weexplugin-gradle-plugin-1.3.pom'.
      > Could not GET 'https://jcenter.bintray.com/com/taobao/android/weexplugin-gradle-plugin/1.3/weexplugin-gradle-plugin-1.3.pom'.
        > Connect to jcenter.bintray.com:443 [jcenter.bintray.com/108.168.243.150] failed: Connection timed out: connect

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

  at checkExecSyncError (child_process.js:603:11)
  at Object.execSync (child_process.js:640:13)
  at C:\Users\Administrator\.xtoolkit\node_modules\weexpack\lib\run\android.js:331:20
  at new Promise (<anonymous>)
  at buildApp (C:\Users\Administrator\.xtoolkit\node_modules\weexpack\lib\run\android.js:327:10)
  at process._tickCallback (internal/process/next_tick.js:68:7)


当打开android studio后重新运行 看到下面的就是运行成功

17:25:33 : Building app ...
 ------
Download https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.2/gradle-2.2.2.pom
Download https://jcenter.bintray.com/com/android/tools/build/gradle-core/2.2.2/gradle-core-2.2.2.pom
Download https://jcenter.bintray.com/com/android/tools/build/builder/2.2.2/builder-2.2.2.pom
Download https://jcenter.bintray.com/com/android/tools/lint/lint/25.2.2/lint-25.2.2.pom
Download https://jcenter.bintray.com/com/android/tools/build/gradle-api/2.2.2/gradle-api-2.2.2.pom
Download https://jcenter.bintray.com/com/android/databinding/compilerCommon/2.2.2/compilerCommon-2.2.2.pom
----


然后 开启虚拟机然后开启android模拟器


打包apk,生成一个签名的apk和一个没签名的apk


Administrator@lenovo-PC MINGW64 /e/jackieli/weex/weex-demo
$ npm run pack:android
~~~~~
:app:assembleRelease

BUILD SUCCESSFUL

Total time: 23.81 secs
17:46:06 : Move APK to `release/android`
17:46:06 : Copying file E:\jackieli\weex\weex-demo\platforms\android\app\build\outputs\apk\app-release-un        signed.apk...
17:46:06 : Copying file E:\jackieli\weex\weex-demo\platforms\android\app\build\outputs\apk\weex-app.apk..        .
17:46:06 : Copied to E:\jackieli\weex\weex-demo\release\android\app-release-unsigned.apk
17:46:06 : Copied to E:\jackieli\weex\weex-demo\release\android\weex-app.apk
17:46:06 : Move 2 files. SUCCESSFUL


结果打包apk安装后出现如下错误

render error:wx_create_instance_error 是因为模拟器版本太低了 可以升级模拟器到android到高版本可以解决安装签名的apk在模拟器中打开