After update to Android Studio 2.2 / gradle plugin 2.2.0: “could not get unknown property 'assembleRelease'”

前端 未结 6 1017
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 23:48

After updating Android Studio to version 2.2 and the Gradle-plugin to 2.2.0, I get following error:

相关标签:
6条回答
  • 2020-12-30 00:12

    maybe wrap code in afterEvaluate{} will be work:

    afterEvaluate {
        assembleRelease.doLast {
           file('build/outputs/apk/app-release.apk').renameTo("AppName-1.0.0-${project.ext.androidVersionCode}.apk")
        }
    }
    

    gradle-2.14.1 and android gradle plugin 2.2.0

    details: Could not get unknown property 'assembleDebug' (2.2-beta)

    0 讨论(0)
  • 2020-12-30 00:15

    you can do this:

    task copyApk(dependsOn: "assembleRelease") << {
        file('build/outputs/apk/app-release.apk').renameTo("AppName-1.0.0-${project.ext.androidVersionCode}.apk")
    }
    
    0 讨论(0)
  • 2020-12-30 00:16
    tasks.whenTaskAdded { task ->
      if (task.name == 'assembleRelease') {
        task.finalizedBy 'yourRenameTasks'
      }
    }
    
    0 讨论(0)
  • 2020-12-30 00:23

    You may rewrite your task a bit and try like this:

    task renameBuildTask() << {
      file('build/outputs/apk/app-release.apk').renameTo("AppName-1.0.0-${project.ext.androidVersionCode}.apk")
      dependsOn 'assembleRelease'
    }
    

    Also you can check this question to get better understanding.

    EDIT

    As @tangens said in a comment:

    It works when I replace the call gradle assemble by e.g. gradle renameBuildTask. Thank you! The answer contains an error. Correct would be: task renameBuildTask() << { ... }

    0 讨论(0)
  • 2020-12-30 00:28

    I had the same problem after upgrading Android Studio to 2.2 and Gradle to 2.2. I have task copyApk that needs to be run at the end of building. For brevity, let me skip what was working before, and post only what is working right now:

    tasks.create(name: 'copyApk', type: Copy) {
        from 'build/outputs/apk/myapp-official-release.apk'
        into '.../mobile'
        rename('myapp-official-release.apk', 'myapp.apk')
    }
    
    tasks.whenTaskAdded { task ->
        if (task.name == 'assembleRelease') {
            task.dependsOn 'copyApk'
        }
    }
    

    Gradle console shows copyApk was run near the end after packageOfficialRelease, assembleOfficialRelease, right before the last task assembleRelease. "Official" is a flavor of the app. I got the workaround from this SO post. I essentially copied the answer here for your convenience. All credits go to the author of that post.

    0 讨论(0)
  • 2020-12-30 00:28

    inside buildTypes {} method, I put this code : worked like a charm

    task setEnvRelease << {
                ant.propertyfile(
                        file: "src/main/assets/build.properties") {
                    entry(key: "EO_WS_DEPLOY_ADDR", value: "http://PRODUCTION IP")
                }
            }
    
            task setEnvDebug << {
                ant.propertyfile(
                        file: "src/main/assets/build.properties") {
                    entry(key: "EO_WS_DEPLOY_ADDR", value: "http://DEBUG IP TEST")
                }
            }
    tasks.whenTaskAdded { task ->
                if (task.name == 'assembleDebug') {
                    task.dependsOn 'setEnvDebug'
                } else if (task.name == 'assembleRelease') {
                    task.dependsOn 'setEnvRelease'
                }
            }
    
    0 讨论(0)
提交回复
热议问题