2015-10-06 20 views
9

當我在ubuntu上的android studio 1.4中創建新項目時。未能解決:junit:junit:ubuntu上的android studio 1.4中的4.12

我收到此錯誤的gradle時的同步上

testCompile 'junit:junit:4.12' 

完成對應用程序的消息/的build.gradle

Error:(23, 17) Failed to resolve: junit:junit:4.12 
Show in File 
Show in Project Structure dialog 

//建立gradle這個(應用模塊)

apply plugin: 'com.android.application' 

android { 
compileSdkVersion 23 
buildToolsVersion "23.0.1" 

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

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

//構建gradle(項目)

//頂級構建文件,您可以在其中添加對所有子項目/模塊通用的配置選項。

buildscript { 
repositories { 
    jcenter() 
} 
dependencies { 
    classpath 'com.android.tools.build:gradle:1.3.0' 

    // NOTE: Do not place your application dependencies here; they belong 
    // in the individual module build.gradle files 
} 
} 

allprojects { 
repositories { 
    jcenter() 
} 
} 

task clean(type: Delete) { 
delete rootProject.buildDir 
} 

回答

-2

//刪除此LINE-testCompile '的JUnit:JUnit的:4.12'

,並再次同步......工作了我 -

dependencies 

{ 

compile fileTree(dir: 'libs', include: ['*.jar']) 

testCompile 'junit:junit:4.12' //remove this line from here 

compile 'com.android.support:appcompat-v7:23.0.1' 

} 
+0

亞我知道,但是我爲什麼要刪除這些添加上述兩行?那麼如果我想測試呢? – abhishek

+0

我嚴重懷疑這是一個解決方案。 一個猜測是它使用的是Junit 3方法,它應該包含在android.jar中(例如在Api 19中),而不需要Junit 4.x. 或者更新的機器人愛普斯甚至有Junit 4. – cowst

7

有些人已經通過添加下面的塊來解決存儲庫丟失URL的問題。

android { 
    ..... 
    repositories { 
     maven { url 'http://repo1.maven.org/maven2' } 
    } 
    ..... 
} 

只需提及:右鍵單擊「應用」文件夾,然後轉到「打開模塊設置」。然後移動到最後一個選項卡'Dependencies'並通過搜索重新添加junit。我試圖添加更早的版本,但沒有得到它的工作。

+0

http://stackoverflow.com/a/32566057/1179841 – Sithu

+0

http://stackoverflow.com/a/32566057/1179841 – Sithu

1

在我來說,我是在一個代理,並同時使用

jcenter { 
    url "http://jcenter.bintray.com/" 
} 

repositories { 
    maven { url 'http://repo1.maven.org/maven2' } 
} 
1

如果你使用JDK開放8這可能是因爲一個問題已經解決 與cacerts的bug。 也許你可以嘗試以下方法來修復損壞的cacerts:

$ sudo dpkg --purge --force-depends ca-certificates-java 
$ sudo apt-get install ca-certificates-java 

我試圖改變我的jcenter()到一個與URL以及試圖去改變它到Maven {網址...}無一不沒有工作。 這個爲我修好了。

參見: https://stackoverflow.com/a/33440168

+0

我可以驗證此修補程序在Ubuntu 15.10下工作與Java 8(來自webupd8team)。 –

0

如果你正面臨問題的JUnit:junit4.12。這是解決方案

repositories { 
    maven { url 'http://repo1.maven.org/maven2' } 
    jcenter { url "http://jcenter.bintray.com/" } 
} 

apply plugin: 'com.android.application' 
相關問題