【问题标题】:Android: run an app from the command line for the first timeAndroid:第一次从命令行运行应用程序
【发布时间】:2015-10-08 11:29:04
【问题描述】:

docs 中,我在尝试运行应用程序时发现了以下这些行。

Run the app from a command line
-------------------------------

Open a command-line and navigate to the root of your project directory. Use Gradle to build your project in debug mode, invoke the assembleDebug build task using the Gradle wrapper script (gradlew assembleRelease).

This creates your debug .apk file inside the module build/ directory, named MyFirstApp-debug.apk.

On Windows platforms, type this command:

> gradlew.bat assembleDebug

On Mac OS and Linux platforms, type these commands:

$ chmod +x gradlew
$ ./gradlew assembleDebug

所以我安装了Gradle,假设gradle wrappergradlew一样,我也做了同样的步骤,但是当我尝试运行时:

/MyFirstApp$ gradle wrapper assembleDebug

FAILURE:无法确定要执行的任务。

  • 出了什么问题:在根项目“MyFirstApp”中找不到任务“包装器”。

  • 尝试:运行 gradle 任务以获取可用任务列表。

构建失败

总时间:1.946 秒

这是我的MyFirstApp目录的内容:

AndroidManifest.xml  bin        **gradlew**  local.properties      project.properties  src
ant.properties       build.xml  libs     proguard-project.txt  res

正如你所见,我也有gradlew 命令,因为我是从/home/me/Downloads/android-sdk-linux/tools/templates/gradle/wrapper/gradlew 复制的。但是当我尝试运行 ./gradlew assembleDebug 时,我得到了这个:

错误:无法找到或加载主类 org.gradle.wrapper.GradleWrapperMain

【问题讨论】:

    标签: android gradle android-gradle-plugin gradlew


    【解决方案1】:

    gradle wrapper 命令实际上设置了一个目录(项目),用于使用包装器使用 gradle 进行构建。它获取包装脚本/可执行文件并将 gradle 版本在本地拉入目录(好吧,一个子目录)。这与调用 gradlew 不同,因为 gradlew 是包装本身。

    您是否使用 Android Studio 创建了您的 Android 项目?它将为您设置包装器并预先填充build.gradlesettings.gradle 和其他必要的文件。

    【讨论】:

    • 我有用户这个命令来创建项目./android create project --target 1 --name MyFirstApp --path ~/workspace/android/MyFirstApp --activity MyActivity --package com.example.myfirstapp。正如它在文档中所说的那样,在“使用命令行工具创建项目”部分。我不想使用 Android Studio。
    • 有趣。看起来创建项目的方法没有与工具同步。它为旧的基于 Eclipse/ant 的样式而不是 gradle 创建项目布局。就工具而言,Android Studio 绝对是重点所在。我建议至少使用它来设置您的项目。创建项目后,您可以使用 vi、emacs 或其他任何东西。您甚至可能会发现自己对 Android Studio 的喜爱足以继续使用它。 ;-)
    猜你喜欢
    • 2017-01-31
    • 1970-01-01
    • 2016-06-18
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    相关资源
    最近更新 更多