簡體   English   中英

Android studio - gradle無法解析依賴項

[英]Android studio - gradle failed to resolve dependencies

我在我的系統中安裝了Android Studio版本2.1.2,如果我在Gradle文件中添加任何依賴項,則I get failed to resolve error

It happen the all the libraries likes Picasso not only for Junit

所以我嘗試在gradle.properties文件中添加代理設置

systemProp.http.proxyHost=http://xxxx/xxx
systemProp.http.proxyPort=80
systemProp.https.proxyHost=http://xxxx/xxx
systemProp.https.proxyPort=80

但是我收到以下錯誤:

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not resolve junit:junit:4.12.
     Required by:
         MyApplication2:app:unspecified
      > Could not resolve junit:junit:4.12.
         > Could not get resource 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
            > Could not GET 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
               > http://xxxx/xxx

如何解決這個問題,請幫忙。

build.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "com.example.muraliathmarao.myapplication"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
}

您需要在main build.gradle的末尾添加一個部分allprojects,它定義項目模塊的存儲庫:

allprojects {
repositories {
    jcenter()
  }
}

這是build.gradle(項目)

buildscript {
 repositories {
    jcenter()
    mavenCentral()
  }

  dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
       // NOTE: Do not place your application dependencies here; they belong
       // in the individual module build.gradle files
   }
 }

allprojects {
    repositories {
       jcenter()
       mavenCentral()
 } 
}

您應該更新您的Android Repository do:
1.打開SDK Manager
2.Android支持庫
3.安裝包

我在封閉的網絡下,它不允許讓Gradle庫下載

如果您處於一個完全封閉的網絡(根本沒有互聯網訪問),那么在本地網絡中擁有一個依賴性的中央內部存儲庫是很常見的,所有內部用戶都可以從中獲取依賴關系。 此本地存儲庫需要復制您從外部站點/存儲庫下載的所有內容。 例如,您必須從某個地方獲得Android Studio安裝和Android SDK依賴項。 此外,Android SDK會定期收到更新 - 您在運行Android SDK管理器時是否看到了更新?

即使您是唯一的開發人員,也可以設置自己的本地Maven倉庫以保留所有依賴項 - 這需要從您正在構建的計算機上訪問(可能只在您的開發計算機上) 。 請參閱https://maven.apache.org/guides/introduction/introduction-to-repositories.html#Internal_Repositories 然后,您需要使用所需的依賴項添加到本地存儲庫 - 當然,這取決於您如何在封閉網絡上獲取任何類型的外部文件(例如,首先是您的Android Studio或Android SDK依賴項) )。

可能存在以下任何一個問題,

  1. 首先檢查存儲庫鏈接是否accessible or not ; 通過您的瀏覽器 (如果您無法訪問該鏈接;請聯系您的網絡基礎架構團隊)

  2. 如果鏈接可以在瀏覽器中訪問; 然后問題在於你的gradle configuration 確保您的根gradle文件中有以下條目。

 buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.1.2'> // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } 

請檢查build.gradle中的“buildToolsVersion”。請確保您的sdk文件已更新。 否則,在build.gradle文件中將buildToolVersion從當前的'24 .0.0'更改為'23 .0.1'或更少

allprojects {
    repositories {
       jcenter()
       mavenCentral()
       google() 
 } 
}

對我有幫助。 google()是那里的關鍵改進,因為所需的依賴關系是在google repo中。

它沒有用,因為我在一個封閉的網絡上,它不允許讓Gradle庫下載,我使用的是jar文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM