当前位置: 首页 > 知识库问答 >
问题:

从gradle运行HelloAndroid?

赵永新
2023-03-14

gradle任务数量众多,种类繁多:

thufir@dur:~/AndroidStudioProjects/HelloAndroid$ 
thufir@dur:~/AndroidStudioProjects/HelloAndroid$ gradle clean run

FAILURE: Build failed with an exception.

* What went wrong:
Task 'run' not found in root project 'HelloAndroid'.

* Try:
Run gradle tasks to get a list of available tasks. 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
thufir@dur:~/AndroidStudioProjects/HelloAndroid$ 
thufir@dur:~/AndroidStudioProjects/HelloAndroid$ gradle tasks --all

> Task :tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Android tasks
-------------
app:androidDependencies - Displays the Android dependencies of the project.
app:signingReport - Displays the signing info for each variant.
app:sourceSets - Prints out all the source sets defined in this project.

Build tasks
-----------
app:assemble - Assembles all variants of all applications and secondary packages.
app:assembleAndroidTest - Assembles all the Test applications.
app:assembleDebug - Assembles all Debug builds.
app:assembleRelease - Assembles all Release builds.
app:build - Assembles and tests this project.
app:buildDependents - Assembles and tests this project and all projects that depend on it.
app:buildNeeded - Assembles and tests this project and all projects it depends on.
app:clean - Deletes the build directory.
app:cleanBuildCache - Deletes the build cache directory.
app:compileDebugAndroidTestSources
app:compileDebugSources
app:compileDebugUnitTestSources
app:compileReleaseSources
app:compileReleaseUnitTestSources
app:mockableAndroidJar - Creates a version of android.jar that's suitable for unit tests.

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'HelloAndroid'.
app:buildEnvironment - Displays all buildscript dependencies declared in project ':app'.
components - Displays the components produced by root project 'HelloAndroid'. [incubating]
app:components - Displays the components produced by project ':app'. [incubating]
dependencies - Displays all dependencies declared in root project 'HelloAndroid'.
app:dependencies - Displays all dependencies declared in project ':app'.
dependencyInsight - Displays the insight into a specific dependency in root project 'HelloAndroid'.
app:dependencyInsight - Displays the insight into a specific dependency in project ':app'.
dependentComponents - Displays the dependent components of components in root project 'HelloAndroid'. [incubating]
app:dependentComponents - Displays the dependent components of components in project ':app'. [incubating]
help - Displays a help message.
app:help - Displays a help message.
model - Displays the configuration model of root project 'HelloAndroid'. [incubating]
app:model - Displays the configuration model of project ':app'. [incubating]
projects - Displays the sub-projects of root project 'HelloAndroid'.
app:projects - Displays the sub-projects of project ':app'.
properties - Displays the properties of root project 'HelloAndroid'.
app:properties - Displays the properties of project ':app'.
tasks - Displays the tasks runnable from root project 'HelloAndroid' (some of the displayed tasks may belong to subprojects).
app:tasks - Displays the tasks runnable from project ':app'.

Install tasks
-------------
app:installDebug - Installs the Debug build.
app:installDebugAndroidTest - Installs the android (on device) tests for the Debug build.
app:uninstallAll - Uninstall all applications.
app:uninstallDebug - Uninstalls the Debug build.
app:uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build.
app:uninstallRelease - Uninstalls the Release build.

Verification tasks
------------------
app:check - Runs all checks.
app:connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
app:connectedCheck - Runs all device checks on currently connected devices.
app:connectedDebugAndroidTest - Installs and runs the tests for debug on connected devices.
app:deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers.
app:deviceCheck - Runs all device checks using Device Providers and Test Servers.
app:lint - Runs lint on all variants.
app:lintDebug - Runs lint on the Debug build.
app:lintRelease - Runs lint on the Release build.
app:lintVitalRelease - Runs lint on just the fatal issues in the release build.
app:test - Run unit tests for all variants.
app:testDebugUnitTest - Run unit tests for the debug build.
app:testReleaseUnitTest - Run unit tests for the release build.

Other tasks
-----------
app:assembleDebugAndroidTest
app:assembleDebugUnitTest
app:assembleReleaseUnitTest
app:bundleAppClassesDebug
app:bundleAppClassesDebugAndroidTest
app:bundleAppClassesDebugUnitTest
app:bundleAppClassesRelease
app:bundleAppClassesReleaseUnitTest
app:checkDebugManifest
app:checkReleaseManifest
clean
app:compileDebugAidl
app:compileDebugAndroidTestAidl
app:compileDebugAndroidTestJavaWithJavac
app:compileDebugAndroidTestKotlin - Compiles the debugAndroidTest kotlin.
app:compileDebugAndroidTestNdk
app:compileDebugAndroidTestRenderscript
app:compileDebugAndroidTestShaders
app:compileDebugJavaWithJavac
app:compileDebugKotlin - Compiles the debug kotlin.
app:compileDebugNdk
app:compileDebugRenderscript
app:compileDebugShaders
app:compileDebugUnitTestJavaWithJavac
app:compileDebugUnitTestKotlin - Compiles the debugUnitTest kotlin.
app:compileLint
app:compileReleaseAidl
app:compileReleaseJavaWithJavac
app:compileReleaseKotlin - Compiles the release kotlin.
app:compileReleaseNdk
app:compileReleaseRenderscript
app:compileReleaseShaders
app:compileReleaseUnitTestJavaWithJavac
app:compileReleaseUnitTestKotlin - Compiles the releaseUnitTest kotlin.
app:consumeConfigAttr
app:createDebugCompatibleScreenManifests
app:createReleaseCompatibleScreenManifests
app:extractProguardFiles
app:generateDebugAndroidTestAssets
app:generateDebugAndroidTestBuildConfig
app:generateDebugAndroidTestResources
app:generateDebugAndroidTestResValues
app:generateDebugAndroidTestSources
app:generateDebugAssets
app:generateDebugBuildConfig
app:generateDebugResources
app:generateDebugResValues
app:generateDebugSources
app:generateReleaseAssets
app:generateReleaseBuildConfig
app:generateReleaseResources
app:generateReleaseResValues
app:generateReleaseSources
app:javaPreCompileDebug
app:javaPreCompileDebugAndroidTest
app:javaPreCompileDebugUnitTest
app:javaPreCompileRelease
app:javaPreCompileReleaseUnitTest
app:mergeDebugAndroidTestAssets
app:mergeDebugAndroidTestJniLibFolders
app:mergeDebugAndroidTestResources
app:mergeDebugAndroidTestShaders
app:mergeDebugAssets
app:mergeDebugJniLibFolders
app:mergeDebugResources
app:mergeDebugShaders
app:mergeReleaseAssets
app:mergeReleaseJniLibFolders
app:mergeReleaseResources
app:mergeReleaseShaders
app:packageDebug
app:packageDebugAndroidTest
app:packageRelease
app:platformAttrExtractor
app:preBuild
app:preDebugAndroidTestBuild
app:preDebugBuild
app:preDebugUnitTestBuild
app:prepareLintJar
app:preReleaseBuild
app:preReleaseUnitTestBuild
app:processDebugAndroidTestJavaRes
app:processDebugAndroidTestManifest
app:processDebugAndroidTestResources
app:processDebugJavaRes
app:processDebugManifest
app:processDebugResources
app:processDebugUnitTestJavaRes
app:processReleaseJavaRes
app:processReleaseManifest
app:processReleaseResources
app:processReleaseUnitTestJavaRes
app:resolveConfigAttr
app:splitsDiscoveryTaskDebug
app:splitsDiscoveryTaskDebugAndroidTest
app:splitsDiscoveryTaskRelease
app:transformClassesWithDexBuilderForDebug
app:transformClassesWithDexBuilderForDebugAndroidTest
app:transformClassesWithPreDexForRelease
app:transformDexArchiveWithDexMergerForDebug
app:transformDexArchiveWithDexMergerForDebugAndroidTest
app:transformDexArchiveWithExternalLibsDexMergerForDebug
app:transformDexArchiveWithExternalLibsDexMergerForDebugAndroidTest
app:transformDexWithDexForRelease
app:transformNativeLibsWithMergeJniLibsForDebug
app:transformNativeLibsWithMergeJniLibsForDebugAndroidTest
app:transformNativeLibsWithMergeJniLibsForRelease
app:transformResourcesWithMergeJavaResForDebug
app:transformResourcesWithMergeJavaResForDebugAndroidTest
app:transformResourcesWithMergeJavaResForDebugUnitTest
app:transformResourcesWithMergeJavaResForRelease
app:transformResourcesWithMergeJavaResForReleaseUnitTest
app:validateSigningDebug
app:validateSigningDebugAndroidTest
app:writeDebugApplicationId
app:writeReleaseApplicationId


BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
thufir@dur:~/AndroidStudioProjects/HelloAndroid$ 
thufir@dur:~/AndroidStudioProjects/HelloAndroid$ gradle clean

BUILD SUCCESSFUL in 0s
2 actionable tasks: 1 executed, 1 up-to-date
thufir@dur:~/AndroidStudioProjects/HelloAndroid$ 
thufir@dur:~/AndroidStudioProjects/HelloAndroid$ tree
.
├── app
│   ├── build.gradle
│   ├── libs
│   ├── proguard-rules.pro
│   └── src
│       ├── androidTest
│       │   └── java
│       │       └── android
│       │           └── kotlin
│       │               └── dur
│       │                   └── bounceme
│       │                       └── net
│       │                           └── helloandroid
│       │                               └── ExampleInstrumentedTest.kt
│       ├── main
│       │   ├── AndroidManifest.xml
│       │   ├── java
│       │   │   └── android
│       │   │       └── kotlin
│       │   │           └── dur
│       │   │               └── bounceme
│       │   │                   └── net
│       │   │                       └── helloandroid
│       │   │                           └── MainActivity.kt
│       │   └── res
│       │       ├── drawable
│       │       │   ├── ic_dashboard_black_24dp.xml
│       │       │   ├── ic_home_black_24dp.xml
│       │       │   ├── ic_launcher_background.xml
│       │       │   └── ic_notifications_black_24dp.xml
│       │       ├── drawable-v24
│       │       │   └── ic_launcher_foreground.xml
│       │       ├── layout
│       │       │   └── activity_main.xml
│       │       ├── menu
│       │       │   └── navigation.xml
│       │       ├── mipmap-anydpi-v26
│       │       │   ├── ic_launcher_round.xml
│       │       │   └── ic_launcher.xml
│       │       ├── mipmap-hdpi
│       │       │   ├── ic_launcher.png
│       │       │   └── ic_launcher_round.png
│       │       ├── mipmap-mdpi
│       │       │   ├── ic_launcher.png
│       │       │   └── ic_launcher_round.png
│       │       ├── mipmap-xhdpi
│       │       │   ├── ic_launcher.png
│       │       │   └── ic_launcher_round.png
│       │       ├── mipmap-xxhdpi
│       │       │   ├── ic_launcher.png
│       │       │   └── ic_launcher_round.png
│       │       ├── mipmap-xxxhdpi
│       │       │   ├── ic_launcher.png
│       │       │   └── ic_launcher_round.png
│       │       └── values
│       │           ├── colors.xml
│       │           ├── dimens.xml
│       │           ├── strings.xml
│       │           └── styles.xml
│       └── test
│           └── java
│               └── android
│                   └── kotlin
│                       └── dur
│                           └── bounceme
│                               └── net
│                                   └── helloandroid
│                                       └── ExampleUnitTest.kt
├── build
│   ├── android-profile
│   │   ├── profile-2017-11-05-17-50-01-533.json
│   │   └── profile-2017-11-05-17-50-01-533.rawproto
│   └── kotlin-build
│       └── version.txt
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── HelloAndroid.iml
├── local.properties
└── settings.gradle

44 directories, 41 files
thufir@dur:~/AndroidStudioProjects/HelloAndroid$ 

从Android Studio的

最简单的“跑”是我想要的。类似于runShaow的东西?

生成的代码和生成文件

thufir@dur:~/AndroidStudioProjects/HelloAndroid$ 
thufir@dur:~/AndroidStudioProjects/HelloAndroid$ cat build.gradle 
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.1.51'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
thufir@dur:~/AndroidStudioProjects/HelloAndroid$            
thufir@dur:~/AndroidStudioProjects/HelloAndroid$ cat app/src/main/java/android/kotlin/dur/bounceme/net/helloandroid/MainActivity.kt 
package android.kotlin.dur.bounceme.net.helloandroid

import android.os.Bundle
import android.support.design.widget.BottomNavigationView
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
        when (item.itemId) {
            R.id.navigation_home -> {
                message.setText(R.string.title_home)
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_dashboard -> {
                message.setText(R.string.title_dashboard)
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_notifications -> {
                message.setText(R.string.title_notifications)
                return@OnNavigationItemSelectedListener true
            }
        }
        false
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
    }
}
thufir@dur:~/AndroidStudioProjects/HelloAndroid$ 

共有2个答案

羊毅庵
2023-03-14

你可以看到

gradle installDebug

将应用程序安装到设备上。您仍然需要按照@moxi:$adb shell am start-n“android.kotlin.dur.bounceme.net.helloandroid/android.kotlin.dur.bounceme.net.helloandroid.MainActivity”的描述运行它。意图行动MAIN-cAndroid。意图类别LAUNCHER如果您有一些测试,也可以使用

gradle connectedAndroidTest

这将启动应用程序以运行测试。

冯枫涟
2023-03-14

gradle run不用于Android项目,请尝试一个assemble[Flavor]任务。要将apk“安装并运行”到仿真器或Android设备中,有3个步骤:

1) 创建apk。例如,首先您必须运行:

$ ./gradlew clean assembleDebug

这将生成一个apk文件,我假设生成的apk名为app debug。apk。

2) 在设备或模拟器中安装生成的apk:

$ adb install -r app/build/outputs/apk/debug/app-debug.apk 

如果您安装了adb,并且有一个正在运行的仿真器或连接的设备,那么输出应该是“Success”。如果已经安装了相同的apk,则使用-r选项,您可以了解有关其他adb安装选项的更多信息。

3) 在模拟器或设备中“运行”应用程序:

$ adb shell am start -n "android.kotlin.dur.bounceme.net.helloandroid/android.kotlin.dur.bounceme.net.helloandroid.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

我假设你的发射器是你的主活动,你可以在Androidanifest.xml中改变它,你也需要包的名字。

 类似资料:
  • 如何从gradle运行另一个gradle脚本。我有多个gradle脚本在

  • 我有一个带有gradle Build Jhipster4.6.2应用程序。从IDE运行测试存在问题。测试通常从命令行执行,但通过单击fails for application context Failure(应用程序上下文失败),从STS运行测试失败: 我遵循了https://jhipster.github.io/configuring-ide-eclipse-gradle/的说明,并且可以从ST

  • 主要内容:执行多个任务,排除任务,发生故障时继续构建,选择执行哪些构建,获取构建信息Gradle提供了一个命令行来执行构建脚本。 它可以一次执行多个任务。在这里将介绍如何使用不同的选项来执行多个任务。 执行多个任务 可以从单个构建文件执行多个任务。使用命令处理构建文件。此命令将按列出的顺序编译每个任务,并使用不同的选项执行每个任务以及依赖关系。 示例 - 假设有四个任务 - ,,和。和取决于和。 看看下面的图表。 在上面的四个任务是相互依赖的,用一个箭头符号表示。 看看下面的代码

  • 问题内容: 我有一个非常简单的问题。我是Mac的新手,我正试图将Java项目移到新Mac上。该项目有一个Gradlew文件,我认为我可以从命令行运行以在任何计算机上构建和运行。当我从命令行(在gradlew文件的位置)执行gradlew时,它说未找到gradlew。我是否缺少有关如何从bash shell运行命令的内容? 问题答案: 您的gradlew目录未包含在PATH中,因此您必须指定grad

  • 我正在学习Spring Boot,有一个关于如何从CLI运行的初学者问题。

  • 现在,当我运行和时,一切都很好,但是当我尝试运行项目时(在build/libs/中运行构建的jar和在IntelliJ中运行velotest类时也是如此),我会得到以下错误: 线程“main”java.lang.noClassDefFounderror:org/apache/commons/collections/extendedProperties 在org.apache.velocity.ru