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

时间:2015-10-08 11:29:04

标签: android gradle android-gradle gradlew

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
  

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

     
      
  • 出了什么问题:在根项目'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

1 个答案:

答案 0 :(得分:0)

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

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

相关问题