使用新语法应用 Android Gradle 插件 [英] Apply Android Gradle plugin using new syntax

查看:34
本文介绍了使用新语法应用 Android Gradle 插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用新的 Gradle 插件语法应用 Android 插件:

How can I apply Android plugin using new Gradle plugin syntax:

plugins {
    id "..." version "..."
}

代替:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}

apply plugin: 'com.android.application'

推荐答案

我刚刚遇到了同样的问题并找到了解决方案 这里.问题源于 Google 出于某种原因决定不将应用程序插件放入 Gradle 的社区插件库.

I just ran into the same problem and found the solution here. The problem results from the fact that Google for whatever reasons decided to put the application plugin not into Gradle's repository of community plugins.

build.gradle 中完全删除 buildscript 块并添加

In build.gradle remove the buildscript block completely and just add

plugins {
    id 'com.android.application' version '3.4.0'
}

settings.gradle 添加

pluginManagement {
    repositories {
        gradlePluginPortal()
        jcenter()
        google()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "com.android.application") {
                useModule("com.android.tools.build:gradle:${requested.version}")
            }
        }
    }
}

这篇关于使用新语法应用 Android Gradle 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆