代码之家  ›  专栏  ›  技术社区  ›  Nital

无法在Android上构建和运行基于ionic和cordova的应用程序

  •  0
  • Nital  · 技术社区  · 8 年前

    我有一个非常基本的 Ionic 我正在尝试构建并运行的应用程序 Win 10 机器。但是当我运行这个命令时,出现了以下错误。我不确定还有什么东西不见了,因为我是新手 NodeJS 和 Android 技术。

    # ionic cordova build android
    > ionic-app-scripts build --target cordova --platform android
    [16:57:21]  ionic-app-scripts 3.2.0
    [16:57:21]  build dev started ...
    [16:57:21]  clean started ...
    [16:57:21]  clean finished in 21 ms
    [16:57:21]  copy started ...
    [16:57:21]  deeplinks started ...
    [16:57:21]  deeplinks finished in 26 ms
    [16:57:21]  transpile started ...
    [16:57:23]  transpile finished in 2.77 s
    [16:57:23]  preprocess started ...
    [16:57:23]  preprocess finished in 1 ms
    [16:57:23]  webpack started ...
    [16:57:24]  copy finished in 2.94 s
    [16:57:26]  webpack finished in 2.57 s
    [16:57:26]  sass started ...
    [16:57:27]  sass finished in 913 ms
    [16:57:27]  postprocess started ...
    [16:57:27]  postprocess finished in 10 ms
    [16:57:27]  lint started ...
    [16:57:27]  build dev finished in 6.43 s
    [16:57:29]  lint finished in 2.17 s
    > cordova build android
    Android Studio project detected
    ANDROID_HOME=C:\Program Files\Android\Android Studio
    JAVA_HOME=C:\Java\jdk
    studio
    Subproject Path: CordovaLib
    Subproject Path: app
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Script 'C:\Users\nital\Documents\Tech\RESET-CODE-SAMPLES\IONIC-CODE-SAMPLES\ionic-basics\platforms\android\CordovaLib\cordova.gradle' line: 68
    
    * What went wrong:
    A problem occurred evaluating project ':CordovaLib'.
    > No installed build tools found. Install the Android build tools version 19.1.0 or higher.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 0s
    (node:15236) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with exit code 1 Error output:
    FAILURE: Build failed with an exception.
    
    * Where:
    Script 'C:\Users\nital\Documents\Tech\RESET-CODE-SAMPLES\IONIC-CODE-SAMPLES\ionic-basics\platforms\android\CordovaLib\cordova.gradle' line: 68
    
    * What went wrong:
    A problem occurred evaluating project ':CordovaLib'.
    > No installed build tools found. Install the Android build tools version 19.1.0 or higher.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 0s
        at ChildProcess.whenDone (C:\Users\nital\Documents\Tech\RESET-CODE-SAMPLES\IONIC-CODE-SAMPLES\ionic-basics\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
        at ChildProcess.emit (events.js:182:13)
        at maybeClose (internal/child_process.js:961:16)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:250:5)
    (node:15236) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
    (node:15236) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    

    离子信息

    # ionic info
    √ Gathering environment info - done!
    
    Ionic:
    
       ionic (Ionic CLI)  : 4.1.2 (C:\Users\nital\AppData\Roaming\npm\node_modules\ionic)
       Ionic Framework    : ionic-angular 3.9.2
       @ionic/app-scripts : 3.2.0
    
    Cordova:
    
       cordova (Cordova CLI) : 8.0.0
       Cordova Platforms     : android 7.0.0
       Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.1.4, (and 4 other plugins)
    
    System:
    
       NodeJS : v10.9.0 (C:\Program Files\nodejs\node.exe)
       npm    : 6.2.0
       OS     : Windows 10
    

    Cordova要求:

    # cordova requirements
    Android Studio project detected
    
    Requirements check results for android:
    Java JDK: installed 1.8.0
    Android SDK: installed true
    Android target: not installed
    cmd: Command failed with exit code 1 Error output:
    'android' is not recognized as an internal or external command,
    operable program or batch file.
    Gradle: installed C:\Program Files\Android\Android Studio\gradle\gradle-4.4\bin\gradle
    (node:10252) UnhandledPromiseRejectionWarning: CordovaError: Some of requirements check failed
        at C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\src\cli.js:414:27
        at _fulfilled (C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:787:54)
        at C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:816:30
        at Promise.promise.promiseDispatch (C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:749:13)
        at C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:557:44
        at flush (C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:108:17)
        at process._tickCallback (internal/process/next_tick.js:61:11)
    (node:10252) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
    (node:10252) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    

    环境变量:

    JAVA_HOME = C:\Java\jdk
    GRADLE_HOME = C:\Program Files\Android\Android Studio\gradle\gradle-4.4
    ANDROID_HOME = C:\Program Files\Android\Android Studio
    Path =  %JAVA_HOME%\bin; %GRADLE_HOME%\bin; %ANDROID_HOME%\bin;
    

    # javac -version
    javac 1.8.0_181
    
    # java -version
    java version "1.8.0_181"
    Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
    

    我也查看了这个在线链接 https://cordova.apache.org/docs/en/latest/guide/platforms/android/ 安装Android Studio后,安装了所有必需的工具和插件(下面的屏幕截图)

    enter image description here

    enter image description here

    2 回复  |  直到 8 年前
        1
  •  2
  •   Sumama Waheed    8 年前

    路径中缺少android sdk目录。

    'android' is not recognized as an internal or external command

    所以你需要添加 tools platform-tools 在系统路径中安装android sdk的任何地方。

        2
  •  1
  •   Nital    8 年前

    找到了解决办法。

    1. 不正确 ANDROID_HOME

      ANDROID\u HOME=C:\Users\nital\AppData\Local\ANDROID\Sdk

    2. 不指向 PATH platform_tools 和 tools 文件夹位于 Sdk

      路径=C:\Users\nital\AppData\Local\Android\Sdk\platform tools

      路径=C:\Users\nital\AppData\Local\Android\Sdk\tools