未能解决:junit:junit:4.12在ubuntu上的android studio 1.4

当我在ubuntu上的android studio 1.4创build新的项目。

当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 

//构buildgradle(应用程序模块)

 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' } 

//build立gradle(项目)

//顶级构build文件,您可以在其中添加所有子项目/模块通用的configuration选项。

 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 } 
  • 我试过错误:(23,17)无法解决:junit:junit:4.12

有些人通过添加下面的块来解决缺少URL的URL的问题。

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

只要提一下:右键单击“应用程序”文件夹,然后转到“打开模块设置”。 然后移动到最后一个选项卡“依赖关系”,并通过搜索重新添加junit。 我试图添加更早的版本,但没有得到它的工作。

如果您使用的是开放的JDK 8,那可能是因为cacerts的bug。 也许你可以尝试以下来修复破碎的cacerts:

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

我尝试将我的jcenter()更改为带有url的那个,并试图将其更改为maven {url …},两者都不起作用。 这个为我修好了

请参阅: https : //stackoverflow.com/a/33440168

在我的情况下,我是在一个代理的背后,这个问题已经解决了两个

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

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

如果你遇到 junit的 问题 :junit4.12 。 这是解决方案

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

之后加上这两行

 apply plugin: 'com.android.application' 

//删除这行 – 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' }