Android:第一次从命令行运行应用程序

Android:第一次从命令行运行应用程序,android,gradle,android-gradle-plugin,gradlew,Android,Gradle,Android Gradle Plugin,Gradlew,在中,我在尝试运行应用程序时发现以下几行代码 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

在中,我在尝试运行应用程序时发现以下几行代码

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包装器
gradlew
相同,我执行了相同的步骤,但当我尝试运行时:

/MyFirstApp$ gradle wrapper assembleDebug
失败:无法确定要执行的任务

  • 错误:在根项目“MyFirstApp”中找不到任务“包装器”

  • Try:运行gradle任务以获取可用任务的列表

构建失败

总时间:1.946秒

这是我的
MyFirstApp
目录的内容:

AndroidManifest.xml  bin        **gradlew**  local.properties      project.properties  src
ant.properties       build.xml  libs     proguard-project.txt  res
正如您所见,自从我从
/home/me/Downloads/android sdk linux/tools/templates/gradle/wrapper/gradlew
复制以来,我还使用了
gradlew
命令。但是当我尝试运行
/gradlew assembleDebug
时,我得到了以下结果:

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


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


您是否使用Android Studio创建了Android项目?它将为您设置包装器,并预先填充
build.gradle
settings.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,可以继续使用它