【AndroidStudio】Error:Could not find com.android.tools.build:gradle:2.3.3

时间:2022-04-17 22:53:22

导入时钟项目时,在C盘用户目录下配置好了3.4的gradle(只需要复制压缩包即可),

C:\Users\Administrator\.gradle\wrapper\dists\gradle-3.4-all\4bi7dnjj1pmknw0wphqavp2sz

删除临时文件,导入压缩包,然后AS会自动解压。

但打开项目时还是报错了:

Error:Could not find com.android.tools.build:gradle:2.3.3. Searched in the following locations: file:/D:/Software/AS3.0/gradle/m2repository/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.pom file:/D:/Software/AS3.0/gradle/m2repository/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.jar https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.pom https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.jar https://maven.google.com/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.pom https://maven.google.com/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.jar Required by: project :

--------------------------------------------------------------------------------------------------------------------
以下为转载的解决方案:


一、今天更新Android Studio后打开Project,报如下错误:

Error: Could not find com.android.tools.build:gradle:2.2.1. 
Searched in the following locations: 
file:/D:/software/android/android-studio-ide-145.3276617-windows/android-studio/gradle/m2repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom 
file:/D:/software/android/android-studio-ide-145.3276617-windows/android-studio/gradle/m2repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar 
https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom 
https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar

解决方法与Maven仓库有点像:进入 
D:\software\android\android-studio-ide-145.3276617-windows\android-studio\gradle\m2repository\com\android\tools\build\gradle

【AndroidStudio】Error:Could not find com.android.tools.build:gradle:2.3.3

将项目中的build.gradle文件中

dependencies { classpath 'com.android.tools.build:gradle:2.2.1' }
  • 1
  • 2
  • 3

改为

dependencies { classpath 'com.android.tools.build:gradle:2.2.0' }
  • 1
  • 2
  • 3

即可。

注意:gradle的版本指的是仓库中的gradle编译工具版本,不是gradle版本。 
【AndroidStudio】Error:Could not find com.android.tools.build:gradle:2.3.3

再补充一点

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
    }
}

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.3'
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
dependencies {
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

中 
android { buildToolsVersion ‘23.0.3’ } 
这个是在sdk的build-tools目录下 
【AndroidStudio】Error:Could not find com.android.tools.build:gradle:2.3.3

二、从网上下载Android-nRF-Toolbox(一个智能卡表控制程序)编译报错

https://github.com/NordicSemiconductor/Android-nRF-Toolbox 
再下载其依赖库 
https://github.com/NordicSemiconductor/Android-DFU-Library 
修改settings.gradle(Project Settings),使其依赖库引用路径正确

include ':app', ':wear', ':common'

include ':dfu'
project(':dfu').projectDir = file('../Android-DFU-Library-release/dfu')
  • 1
  • 2
  • 3
  • 4

然后编译报错

ERROR: Could not find method android() for arguments [build_4fli1jm76ubcnxesnhqnhie47$_run_closure3@6e71db85] on root project ”. Information:BUILD FAILED

一开始修改了compileSdkVersion,降低了版本且让子项目的指向root项目,依旧报错。 
然后还修改了com.android.tools.build:gradle为仓库中已经有的版本,还是报错。 
再后来更新了SDK Manager,还重启了电脑,问题依旧存在。

最终解决方案是: 
从网上重新下载项目,然后在记事本中修改settings.gradle中的依赖路径。最后打开android studio x64,引入项目,刚开始它会弹窗要你从jcenter中下载个什么(忘了),这步可以取消,直接进入android studio的项目页面。然后选择更新gradle,它会自动更新,更新好后便可正常运行了。

版权声明:转载请注明出处——http://blog.csdn.net/chy555chy/article