error:Could not find gradle

一.更新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.jarandroid

解決方法與Maven倉庫有點像:git

下載:http://services.gradle.org/distributions/github

進入 
D:\software\android\android-studio-ide-145.3276617-windows\android-studio\gradle\m2repository\com\android\tools\build\gradlewindows

這裏寫圖片描述

將項目中的build.gradle文件中android-studio

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

改成app

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

便可。ide

注意:gradle的版本指的是倉庫中的gradle編譯工具版本,不是gradle版本。 
這裏寫圖片描述工具

再補充一點gradle

build.gradleui

// 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 {
}

中 
android { buildToolsVersion ‘23.0.3’ } 
這個是在sdk的build-tools目錄下 
這裏寫圖片描述

2、從網上下載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')

而後編譯報錯

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,它會自動更新,更新好後即可正常運行了。

相關文章
相關標籤/搜索