我想运行一个物理设备上的项目。
你想要的任务是app:installDebug
,但这是假设你有正确的项目结构。
由于不清楚您的项目的结构如何,下面是Android Gradle documentation的推荐结构。
settings.gradle
build.gradle # Top-level
app/ # A module named 'app'
build.gradle # Module-level
libs/
library-1.jar
library-2.jar
...
src/main/
AndroidManifest.xml
java/ # application package in here, then Java files in that
res/
这是settings.gradle
include ':app'
这里是一个顶级build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
jcenter()
}
}
然后,模块build.gradle
与你相依调整。
最重要的是 - 这里的顶部行告诉Gradle这是一个Android应用程序,而不是一个Java应用程序。这意味着您可以运行各种与Android相关的Gradle任务,例如installDebug
,这是您正在寻找的任务。
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "xxxxxxxx"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
ext {
// Variables to keep libraries consistent
supportLibrary = '23+'
// Support Libraries dependencies
supportDependencies = [
design : "com.android.support:design:${supportLibrary}",
appCompatV7 : "com.android.support:appcompat-v7:${supportLibrary}"
]
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
// This line already compiles all jar files in the libs/ directory
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
// recommended
compile supportDependencies.design
}
Gradle有一个'app:installDebug'任务。你没有看到它吗? –
我看不到它。它在哪里? – kaka
请用您的Gradle文件[编辑]您的问题。 –