android - 如何在Android中将installDebug.dependsOn(uninstallDebug)添加到Gradle构建文件中?

标签 android gradle installation android-gradle-plugin uninstallation

我正在尝试将installDebug.dependsOn(uninstallDebug)添加到我的生成文件中,例如this

将其添加到主构建文件失败以及将其添加到应用构建文件(在android {}内部或外部)。

感谢帮助

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.5.0' // was 1.3.1
            classpath 'org.hidetake:gradle-ssh-plugin:1.1.2'
        }
    }
//  installDebug.dependsOn(uninstallDebug) // gets: Error:(12, 0) Could not find property 'installDebug' on root project 'Cb7'.

    allprojects {
        repositories {
            jcenter()
        }
    }
    apply plugin: 'org.hidetake.ssh'
    remotes {
        web1 {
            host = 'tayek.com'
            user = 'rtayek'
            password=project.property('password')
        }
    }
    task deliver(dependsOn: ':app:assemble') << {
        ssh.run {
            session(remotes.web1) {
                execute 'pwd'
                put from: 'app/build/outputs/apk/app-debug.apk', into: 'html/conrad/app-debug.apk'
                put from: 'app/build/outputs/apk/app-debug-unaligned.apk', into: 'html/conrad/app-debug-unaligned.apk'
                put from: 'app/build/outputs/apk/app-release-unsigned.apk', into: 'html/conrad/app-release-unsigned.apk'
                execute 'ls -l html/conrad'
            }
        }
    }

apply plugin: 'com.android.application'
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    lintOptions {
        abortOnError false
    }
    defaultConfig {
        applicationId "com.tayek.tablet.gui.android.cb7"
        minSdkVersion 17 // try 19 - 19 does not work :(
        targetSdkVersion 22 // was 23. https://stackoverflow.com/questions/4568267/android-min-sdk-version-vs-target-sdk-version/4568358#4568358
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    //installDebug.dependsOn(uninstallDebug) // Error:(20, 0) Could not find property 'installDebug' on com.android.build.gradle.AppExtension_Decorated@1fc61c76.

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
//installDebug.dependsOn(uninstallDebug) // Error:(28, 0) Could not find property 'installDebug' on project ':app'.

def jdkHome = System.getenv("JAVA_HOME")
dependencies {
    //compile files("${jdkHome}/lib/tools.jar") // who needs this?
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    androidTestCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    //compile files('libs/rabbit.jar')
    //compile files('libs/rabbit-1.0.jar') // not using maven local or flat dirs (yet)
    //runtime files('libs/rabbit-1.0.jar') // try to fix NoClassDefFoundError // does not work
}

最佳答案

您可以推迟任务之间的关联,直到完全评估项目并创建任务之后:

afterEvaluate {
    installDebug.dependsOn(uninstallDebug)
}

在build.gradle的顶层执行此操作,而不是在android块内执行此操作。

关于android - 如何在Android中将installDebug.dependsOn(uninstallDebug)添加到Gradle构建文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35817099/

相关文章:

android - "Package file is invalid",来自开发者端的解决方案(Android)

php - 如何修复 Composer 错误 : "could not scan for classes inside dir"?

android - 在 Android 中将形状放入 MapView

android - 当有两个或多个 Activity 要处理 Intent 时, Activity 结果代码始终为 0(取消)

java - Android "onRequestPermissionsResult"未被调用

android - 找不到 com.android.support :support-v4:21. 0.2

gradle - Tar Gradle任务期间不包括某些文件

安卓 Zoom Gallery 帮助

java - 是否有用于提取Minecraft配方的工具/API?

ubuntu 12.04安装fontforge没有找到包 'zlib'