Android Build Gradle无法完成

时间:2016-03-08 16:29:29

标签: android android-studio gradle

had a problem要运行android-studios build gradle,所以我测试了很多解决方案,但不幸的是我无法解决我的问题: 现在我卸载我的旧Android工作室和Android-sdk,然后我下载包含默认SDK的android studio 1.5.1。 我安装它们并创建一个空项目,但是构建项目需要30分钟,我将添加在这段时间内显示的对话框窗口。

最后使用此错误创建的项目:

  

错误:(23,17)无法解决:junit:junit:4.12

请问有人帮助我吗? enter image description here

build.gradle文件内容:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.armangar.app.fortest"
        minSdkVersion 23
        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')
    androidTestCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
}

top 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:1.5.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 个答案:

答案 0 :(得分:0)

testCompile是单元测试的配置(位于src / test中),androidTestCompile用于测试api(位于src / androidTest中)。

两者之间的主要区别是test在常规Java JVM中运行,androidTest测试在Android设备(或模拟器)上运行。

所以,使用

testCompile 'junit:junit:4.12'

而不是

androidTestCompile 'junit:junit:4.12'

来源:http://tools.android.com/tech-docs/unit-testing-support

答案 1 :(得分:0)

我在build.gradle中将jcenter()更改为mavenCentral()。 所以我的问题解决了

编辑: 此问题与我的代理有关。所以我无法从jcenter()下载。 如果您遇到与此问题相同的问题,请检查您的Internet代理。