首页 > 解决方案 > 如何降级android gradle?

问题描述

由于我更新了android gradle,我的铃声应用程序出现了问题,我猜问题出在复制文件和权限上(我注意到清单中的android.permission.WRITE_SETTINGS带有红色下划线,我猜是有问题)

相同的代码在我的旧项目中完美运行,唯一的区别在于 gradle,所以我在网上尝试了一些关于如何降级的教程,但我失败了。

我尝试在gradle-wrapper.properties(Gradle Version)中进行更改

distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip

到以前对我有用的版本,但我收到消息说 4.4 是最低的

然后我尝试在build.gradle(Project)中降级

但仅成功将其降级为

类路径'com.android.tools.build:gradle:3.0.1'

但这并没有解决我的问题,因为工作版本是2.3.3

distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip

当我尝试与 2.3.3 同步时出现错误

Gradle DSL method not found: 'google()'
Possible causes:<ul><li>The project 'MyProject' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 3.1.4 and sync project</li><li>The project 'MyProject' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>

有人可以告诉我正确的方法并逐步解决我的问题吗

标签: androidandroid-studiogradleandroid-permissionsdowngrade

解决方案


以下是您可以尝试的步骤,但这不是解决问题的好方法。你最好专注于主要问题并尝试解决它。从这里开始或找到其他解决方法。

1-从 build.gradle 中删除 google() 并添加 maven:(对于低于 4.1 的 Gradle)

buildscript {
    repositories {
        maven {
            url 'https://maven.google.com'
        }
        jcenter()
    }
}

2-转到gradle-wrapper.properties并将gradle版本更改为:

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

3-将 gradle 插件更改为(如果您使用的是 Android Studio 2.xx):

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

4-同步。


推荐阅读